让乌龟评估不同品种乌龟的颜色

Asking Turtle to evaluate color of different breed of Turtle

我正在为捕食者模型构建交互。

我有一个猎物会根据其当前所处的状态改变颜色。我正在处理的状态是 "hiding",其中猎物是黄色的。我有一个捕食者正在评估它是否可以追逐猎物,我试图通过评估猎物的颜色来做到这一点,但它似乎没有用。

to chase
  let target min-one-of prey [distance myself]
  output-print target
  ifelse target != yellow 
  [

     output-print "chase"
  ]
  [
    output-print "ignore"
  ]
end

当我 运行 模型时,捕食者不断打印 "chase" - 无论猎物是否 "hiding"。

这里是隐藏函数

to hiding
  set color yellow
  set energy (energy - 1)
  if (count predators = 0)
[
  output-print "safe"
]
end

如有任何帮助,我们将不胜感激。

要访问颜色(或代理的任何其他变量),您将变量名称括在括号中并使用 "of" 因此

[color] of target

在您的代码上下文中,它看起来像这样

 to chase
 let target nearest-of prey
 output-print target
 ifelse [color] of target != yellow 
 [

  output-print "chase"
 ]
 [
 output-print "ignore"
 ]

结束

它需要一些时间来适应,因为它与 "C" 风格语言使用的 object.variable 形式完全不同。