如何使海龟产卵一定数量的斑块彼此远离
How to spawn turtles a certain amount of patches away from each other
我正在尝试将海龟产卵到彼此相距 5 个地块,但我不确定如何,现在它们都在绿色地块上产卵(我不希望它们在棕色地块上产卵)而且我不知道你是如何精确控制海龟产卵之间的距离的,谢谢。
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
你读过这个问题吗:NetLogo Create turtle at regular distance from each other?
无论如何,我认为向您展示一些工作功能会有所帮助,这里我做了两个选择,sprout-distanced1
和 sprout-distanced2
,您可以通过交替注释哪一行来测试它们;我还添加了一个名为 Min-Distance
的滑块来控制海龟间距。
sprout-distanced1
使用关键字 carefully
基本上是一个 try-else 块,以防乌龟找不到足够距离的补丁来移动到,在这种情况下,乌龟不会发送警告,而是会停留在原处并打印它与最近的乌龟的距离。
sprout-distanced2
使用 while 循环,以防乌龟找不到移动到的地方,至少 Min-Distance
来自另一只乌龟,它将减少最小半径小一点,直到它可以与其他海龟保持距离,如果它必须移动到与其他海龟的距离小于 Min-Distance
的补丁,它将在 Command Center
处记录距离。
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
选择更适合您的模型。
我正在尝试将海龟产卵到彼此相距 5 个地块,但我不确定如何,现在它们都在绿色地块上产卵(我不希望它们在棕色地块上产卵)而且我不知道你是如何精确控制海龟产卵之间的距离的,谢谢。
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
你读过这个问题吗:NetLogo Create turtle at regular distance from each other?
无论如何,我认为向您展示一些工作功能会有所帮助,这里我做了两个选择,sprout-distanced1
和 sprout-distanced2
,您可以通过交替注释哪一行来测试它们;我还添加了一个名为 Min-Distance
的滑块来控制海龟间距。
sprout-distanced1
使用关键字carefully
基本上是一个 try-else 块,以防乌龟找不到足够距离的补丁来移动到,在这种情况下,乌龟不会发送警告,而是会停留在原处并打印它与最近的乌龟的距离。sprout-distanced2
使用 while 循环,以防乌龟找不到移动到的地方,至少Min-Distance
来自另一只乌龟,它将减少最小半径小一点,直到它可以与其他海龟保持距离,如果它必须移动到与其他海龟的距离小于Min-Distance
的补丁,它将在Command Center
处记录距离。
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
选择更适合您的模型。