patch-ahead 乌龟停止的条件无效
patch-ahead condition not working for turtle to stop
我正在尝试停止在 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
]
实际上,我正在使用 patch-ahead 1 条件来停止使用“import-pcolors
”命令导入的绘图中的海龟。
绘图或形状(例如star-fish)与世界补丁的中心对齐,并且 4 只海龟(种子)放置在形状绘图内的原点中心附近保持静止直到结束,所有其他海龟随机放置并在世界中随机移动 stationary? = false
.
目标是完全填充形状(绘图)而不在绘图中留下任何空白,通过随机移动海龟并在接近下一个静止的海龟时停止并成为stationary? = true
,并供所有参考其余 non-stationary 只海龟。
这是我到目前为止尝试过的方法,
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
我想要实现的期望行为如下图所示。
如果不查看您的设置代码(请参阅 MCVE guidelines)很难确定,但我怀疑您的海龟都是从 stationary?
等于 false
开始的没有开始时 stationary
设置为 true 的海龟(让流浪的海龟做出反应。当我 运行 你的代码有一些静止的海龟时,据我所知它确实有效。试试这个稍微修改一下版本,看看它是否更接近你所追求的:
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
我正在尝试停止在 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
]
实际上,我正在使用 patch-ahead 1 条件来停止使用“import-pcolors
”命令导入的绘图中的海龟。
绘图或形状(例如star-fish)与世界补丁的中心对齐,并且 4 只海龟(种子)放置在形状绘图内的原点中心附近保持静止直到结束,所有其他海龟随机放置并在世界中随机移动 stationary? = false
.
目标是完全填充形状(绘图)而不在绘图中留下任何空白,通过随机移动海龟并在接近下一个静止的海龟时停止并成为stationary? = true
,并供所有参考其余 non-stationary 只海龟。
这是我到目前为止尝试过的方法,
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
我想要实现的期望行为如下图所示。
如果不查看您的设置代码(请参阅 MCVE guidelines)很难确定,但我怀疑您的海龟都是从 stationary?
等于 false
开始的没有开始时 stationary
设置为 true 的海龟(让流浪的海龟做出反应。当我 运行 你的代码有一些静止的海龟时,据我所知它确实有效。试试这个稍微修改一下版本,看看它是否更接近你所追求的:
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