Netlogo 让海龟们改变颜色,当他们遇到其他海龟时停下来
我有两只乌龟,颜色是“绿色”和“蓝色”。我想当绿海龟遇到蓝海龟时,蓝海龟会变白并停止移动,而绿海龟会继续随机移动。这是我的代码,我做了,但它给出了一个错误期望一个文本值,并且没有返回期望的结果。非常感谢您的帮助Netlogo 让海龟们改变颜色,当他们遇到其他海龟时停下来,netlogo,Netlogo,我有两只乌龟,颜色是“绿色”和“蓝色”。我想当绿海龟遇到蓝海龟时,蓝海龟会变白并停止移动,而绿海龟会继续随机移动。这是我的代码,我做了,但它给出了一个错误期望一个文本值,并且没有返回期望的结果。非常感谢您的帮助 ask turtles with [color = green] [if any? other turtles-here with [color = blue] [set turtles with [color = blue] [color = white] ] ] 你
ask turtles with [color = green]
[if any? other turtles-here with [color = blue]
[set turtles with [color = blue] [color = white]
]
]
你忘了问海龟了。关键字
with
将正确的turtles子集化,但您需要设置一个变量,而不是设置一个Turtletset。此外,“=”用于评估(比较),而不是赋值。我想你想要这个:
ask turtles with [color = green]
[ if any? other turtles-here with [color = blue]
[ ask turtles-here with [color = blue]
[ set color white
]
]
]
请注意,我必须再次在这里写海龟
,否则所有的蓝海龟都会变成白色。减少错误的一种更可读的方法是为相关的海龟设置一个临时变量(使用let
)
ask turtles with [color = green]
[ let changers other turtles-here with [color = blue]
if any? changers
[ ask changers
[ set color white
]
]
]
问一个新问题。至少,你必须向我们展示你用来移动海龟的代码,以及你试图让它们停止移动所做的一切。