1

您好,我有下一个代码可以为具有 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?” 但我认为这段代码不是为了我想要的目的。有什么建议么?

4

1 回答 1

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

或者:

ask turtles with [ color = blue and payoff < 0 ] [ set color red ]
于 2015-02-11T01:44:55.283 回答