询问Netlogo中所有海龟变量的值

时间:2015-02-11 01:33:17

标签: variables colors netlogo primitive agents

您好我有下一个代码为3种不同颜色的海龟种群的变量“支付”赋值

turtles-own
  [
   payoff
   ]

to pay
let nearby other turtles in-radius 1
 ask turtles with [color = blue] 
  [
  if any? nearby with [color = red]
  [
 set payoff -1 
  ]
  ]
end   

所以我想做的是用蓝色检查海龟的收益,如果收益小于0(即-1),他们将颜色改为红色,但我需要为每只蓝龟做这个那么我可以使用什么代码?我尝试使用“one-of”和“any?”但我认为这个代码不是出于我想要的目的。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

ask turtles with [ color = blue ] [
  if payoff < 0 [
    set color red
  ]
]

可替换地:

ask turtles with [ color = blue and payoff < 0 ] [ set color red ]