netlogo: 检查某只乌龟是否领先于当前移动的乌龟

netlogo: Check whether a certain turtle is ahead of current moving turtle

一个。在 NetLogo 中,我想检查哪种类型的海龟领先于当前移动的海龟。我试着通过观察前方乌龟的形状或颜色来做到这一点。上下文:我想让移动的乌龟检查它是否遇到移动的敌人,如果是,移动的乌龟应该避开移动的敌人

我试过这一行作为条件:

if [color] of turtles-on patch-ahead 0 = yellow [do this]

乙。我想用这段代码作为条件检查某个乌龟是否与当前移动的乌龟重叠。

if [color] of turtles-here = yellow [do this]

它没有报错,但没有按预期运行。

[color] of turtles-here

returns 颜色列表。黄色 returns 一个数字。所以你是在比较一个列表和一个数字,而不是一个数字和一个数字。

我想你会喜欢:

if any? turtles-here with [color = yellow] [do something]