Netlogo 提前补强条件不适用于海龟停止
我试图在Netlogo 提前补强条件不适用于海龟停止,netlogo,Netlogo,我试图在提前补丁1条件下停止移动乌龟,即如果乌龟发现另一只乌龟具有特定属性,例如在其下一个相邻补丁上静止不动,则应停止移动, 事实上,我想阻止海龟在接触静止的海龟时彼此相邻 ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [ fd 0.1 rt random 360 ] [ set stationary? true stop ] 实际上,我在使用“import pcolors”命令导入
提前补丁1条件下停止移动乌龟,即如果乌龟发现另一只乌龟具有特定属性,例如在其下一个相邻补丁上静止不动,则应停止移动,
事实上,我想阻止海龟在接触静止的海龟时彼此相邻
ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [
fd 0.1
rt random 360
] [
set stationary? true
stop
]
实际上,我在使用“import pcolors
”命令导入的图形中使用提前补丁1条件来停止我的海龟
绘图或形状(如星鱼)在世界斑块的中心对齐,4只海龟(种子)被放置在形状图中原点的中心附近保持静止,直到结束,所有其他海龟被随机放置,并且在世界上以静止?=错误
目标是通过随机移动海龟,并在接近下一只静止海龟时停止,并成为静止?=正确
,以及所有其他非静止海龟的参考
ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [
fd 0.1
rt random 360
] [
set stationary? true
stop
]
这是我到目前为止试过的
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
我想要达到的预期行为如下图所示。
如果不查看设置代码(请参阅),很难确定,但我怀疑您的海龟都是以静止状态开始的?
等于false
并且没有海龟是以静止状态开始的
设置为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
卢克C,谢谢你的帮助。你说得对。但让我澄清一下我的想法。