我试图阻止在patch-ahead 1 condition
上移动乌龟,如果它发现另一只具有特定属性的海龟,例如在其下一个相邻的补丁上静止,那么它应该停止,
实际上,我想要在到达静止的海龟时阻止彼此相邻的海龟。
ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [
fd 0.1
rt random 360
] [
set stationary? true
stop
]
实际上,我正在使用补丁提前1条件来停止使用" import-pcolors
"导入的绘图中的海龟。命令。
绘图或形状(如星鱼)在世界中心对齐,4只龟(种子)放置在原点中心附近,形状图保持静止直至结束,所有其他海龟随机放置,并随着stationary? = false
随机移动。
目标是完全填充形状(绘图),不会在图纸中留下任何补丁,通过随机移动海龟并在接近下一个固定海龟时停止并成为stationary? = true
,并参考其他所有剩余非固定龟。
这是我到目前为止所尝试的,
to setup
import-pcolors "starnew.png" ; image imported in the world on patches for turtles to interact
create-robots num-of-robots
[
set seed? false
set stationary? false
set shape "circle 2"
setxy random-pxcor random-pycor
]
ask turtles
[
if who = 0 ; similarly for who = 1 (setxy = 0 1 ), who = 2 (setxy = 1 0 ), who = 3 (setxy = 0 -1 ), having loaction near centre origin
[
setxy 0 0
set seed? true
set stationary? true
set localized? true
]
]
end
to go
ask robots with [stationary? != true]
[
ifelse pcolor = white ;; out-shape
[
wall
fd 0.1
rt random 30
lt random 30
]
[ ;; In-shape
set pos-inside? true
ifelse ( not any? (robots-on patch-ahead 1 ) with [stationary? = true or seed? = true] )
[
fd 0.1
rt random 30
lt random 30
]
[
set pos-inside? true
set stationary? true
set localized? true
stop
]
]
]
end
答案 0 :(得分:2)
很难说没有查看您的设置代码(请参阅MCVE guidelines),但我怀疑您的海龟都是stationary?
等于false
并且没有从stationary
开始的海龟设置为真(对于流浪的海龟来说作出反应。当我用一些固定的乌龟运行你的代码时,它确实可以正常工作。尝试这个稍微修改过的版本,看看是否接近你之后的事情:
turtles-own [ stationary? ]
to setup
ca
crt 50 [
setxy random-pxcor random-pycor
set stationary? false
]
ask n-of 15 turtles [
set stationary? true
]
reset-ticks
end
to go
ask turtles with [ stationary? = false ] [
ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [
fd 0.1
rt random 360
] [
print "Found a stationary turtle. I'll be stationary too."
set stationary? true
]
]
tick
end