Netlogo 如何产卵海龟一定数量的补丁远离彼此
我正试图让海龟产卵时彼此相隔5个补丁,但我不确定如何产卵,现在它们都在绿色的补丁上产卵(我不想让它们在棕色的补丁上产卵),我也不确定如何精确控制海龟产卵之间的距离,谢谢Netlogo 如何产卵海龟一定数量的补丁远离彼此,netlogo,Netlogo,我正试图让海龟产卵时彼此相隔5个补丁,但我不确定如何产卵,现在它们都在绿色的补丁上产卵(我不想让它们在棕色的补丁上产卵),我也不确定如何精确控制海龟产卵之间的距离,谢谢 breed [ humans person ] breed [ zombies zombie ] to setup_world clear-all reset-ticks ask patches [ set pcolor green ] ask n-of 100 patches [
breed [ humans person ]
breed [ zombies zombie ]
to setup_world
clear-all
reset-ticks
ask patches [
set pcolor green
]
ask n-of 100 patches [
set pcolor brown
]
ask n-of 15 patches with [pcolor != brown][sprout-humans 1 [set size 5
set color blue
set shape "person"]]
ask n-of 5 patches with [pcolor != brown][sprout-zombies 1 [set size 4
set color red
set shape "person"]]
end
你读过这个问题吗 无论如何,我认为向您展示一些工作函数会很有帮助,在这里我做了两个选择,
sprout-distanced1
和sprout-distanced2
,您可以通过交替注释哪一行来测试它们;我还添加了一个名为mindistance
的滑块来控制海龟的间距
小心地使用关键字sprout-distanced1
基本上是一个try-else块,它在那里以防海龟找不到足够远的补丁移动到,在这种情况下,海龟不会发送警告,而是留在原地,打印它与最近海龟的距离
使用while循环,如果海龟找不到距离另一只海龟至少sprout-distanced2
的地方移动,它会将最小半径减小一小部分,直到它能够与其他海龟保持距离,如果它必须移动到距离其他海龟小于Min Distance
最小距离的地方,它将在
指挥中心记录距离
繁殖[人类]
繁殖[僵尸僵尸]
建立一个新的世界
清除所有
重置滴答声
询问补丁
[
将颜色设置为绿色
]
询问n-100个补丁
[
设置颜色为棕色
]
使用[pcolor!=棕色]
[
萌芽人类1
[
5号套餐
设置颜色为蓝色
设置形状“人”
;发芽距离1
发芽距离2
]
]
使用[pcolor!=棕色]
[
萌芽僵尸1
[
套装尺寸4
设置颜色为红色
设置形状“人”
;发芽距离1
发芽距离2
]
]
结束
远距离发芽1
小心
[
;尽量离其他海龟至少一分钟的距离
移动到[没有其他海龟在半径最小距离内]的一个补丁
]
[
;如果无法移动到距离其他海龟最小的距离
;待在原地,记录与其他海龟的最小距离,仅供参考
向另一只海龟展示距离[距离我自己]
setxy随机xcor随机ycor
发芽距离1
]
结束
在远处发芽2
设最小距离最小距离
让我走?错误的
而[未移动?且最小距离>0]
[
我能把它自己隔到某个地方吗?
如果其他海龟在半径最小距离内,有[没有其他海龟]的补丁
[
;如果是,就去那里
移动到[没有其他海龟在半径最小距离内]的一个补丁
移动了吗?是的
;如果必须减少无线电记录的距离
如果移动?和最小距离<最小距离
[
向另一只海龟展示距离[距离我自己]
]
]
[
;无处可去,减少无线电的距离
设置最小距离最小距离-0.1
]
]
结束
选择哪个更适合你的模型
breed [ humans person ]
breed [ zombies zombie ]
to setup_world
clear-all
reset-ticks
ask patches
[
set pcolor green
]
ask n-of 100 patches
[
set pcolor brown
]
ask n-of 15 patches with [pcolor != brown]
[
sprout-humans 1
[
set size 5
set color blue
set shape "person"
;sprout-distanced1
sprout-distanced2
]
]
ask n-of 5 patches with [pcolor != brown]
[
sprout-zombies 1
[
set size 4
set color red
set shape "person"
;sprout-distanced1
sprout-distanced2
]
]
end
to sprout-distanced1
carefully
[
; try to move at least Min-Distance away from other turtles
move-to one-of patches with [not any? other turtles in-radius Min-Distance]
]
[
; if can't move Min-Distance away from other turtles
; stay put and log the min distance to other turtle, just for reference
show distance min-one-of other turtles [distance myself]
setxy random-xcor random-ycor
sprout-distanced1
]
end
to sprout-distanced2
let min-dist Min-Distance
let moved? FALSE
while [not moved? and min-dist > 0]
[
; can distance it self somewhere?
ifelse any? patches with [not any? other turtles in-radius min-dist]
[
; if yes, go there
move-to one-of patches with [not any? other turtles in-radius min-dist]
set moved? TRUE
; if had to reduce the distancing radious log it
if moved? and min-dist < Min-Distance
[
show distance min-one-of other turtles [distance myself]
]
]
[
; no where to go, reduce the distancing radious
set min-dist min-dist - 0.1
]
]
end