下面的代码查找所有至少有一只雄性和一只雌性存在的补丁,然后在每个这样的补丁上,有一只雌性孵化随机性别的后代海龟。
turtles-own [ gender]
to setup
ask patches [
sprout 1
[set size 0.2
set color pink
set gender "female"
]]
ask patches [
sprout 1
[set size 0.2
set color blue
set gender "male"
]]
reset-ticks
end
to-report parents-here? ;; patch procedure
report any? turtles-here with [gender = "male"]
and
any? turtles-here with [gender = "female"]
end
to go
ask patches with [parents-here?] [
ask one-of turtles-here with [gender = "female"] [
hatch 1 [
set gender one-of ["male" "female"]
]
]
]
tick
end我想问的不是让一只雌性孵化,而是一只雌性要求孵化“或”如果有两只雌性要求孵化(最少一只,最多两只)。我试着写出来
ask n-of 2 turtles-here ............但是我有一个错误,说这个补丁只有一个来自乌龟
我试着使用(但也是错误的),我也试着写
ask n-of (1 + random 2 )作为最小值和最大值,这也是错误的。
提前谢谢你
发布于 2014-04-22 09:48:21
这是我能想到的最简单的解决方案:
let females turtles-here with [gender = "female"]
ask n-of (min list 2 count females) females [
hatch 1 [
...
]
]为什么是min list 2 count females?当您想要最大值为2时,需要使用名为min的原语,这有点违反直觉,但min list 2 ...的结果始终是2或更小。或者,如果你按案例进行分析:
count females为0,则min list 2 count females也为0。count females为1,则min list 2 count females也为1。H113如果D14为2或更多,则D15为2。H216F217
如果我没理解错的话,这就是你想要的。
https://stackoverflow.com/questions/23204387
复制相似问题