如何在NetLogo中为海龟品种随机分配性别



对于我的一个班的作业,我们需要模拟疾病传播,并让海龟,无论生病还是健康,在雄性和雌性最终在同一块地上繁殖,这也是基于繁殖概率的滑块。我们应该在出生时随机分配性别,这样繁殖才能正常进行。知道怎么做吗?这是我迄今为止的代码:

to setup
clear-all
ifelse netlogo-web? [set max-turtles 300] [set max-turtles 300]
create-healthy-cows Population-Size [ set shape "cow"
set color lime
set infected? false
set disease? false
ask n-of (random Population-Size) turtles [set gender-male? true]
set size 3
setxy random-xcor random-ycor
set age random 200
set label-color black ]
end

以及:

to check-reproduction
ask turtles [if gender-male? = false [
ask turtles [if any? turtles-here with [gender-male? = true]
[reproduce-cows] ]]]
end

to reproduce-cows
ask turtles [ if max-turtles < 300 [
ask turtles [if age >= 50 [if (random-float 100 < Reproduction-Rate)
[hatch 1
[set color blue] ]]]]]
end

此外,我将gender-male?设置为turtles-own

看看one-of,看看是否能找到解决方案。重要的是要了解你在做什么以及为什么要做,而不仅仅是问答案,尤其是在课堂作业中。

我从未见过或听说过NetLogo,我花了不到5分钟的时间想出了一个解决方案,然后找到了第二个更好的解决方案。。尤其是如果这是一项任务,你应该在谷歌上搜索和研究,而不是要求被人用勺子舀

最新更新