1

Hello i have the next code to give a value to the variable "payoff" of the population of turtles with 3 different colors

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   

So what i want to do is check the payoff of the turtles with color blue and if the payoff is less than 0 (i.e -1) they change their color to red, but i need to do this for each individual blue turtle so what code can i use? I try using "one-of" and "any?" but i think that this code its not for the purpose that i want. Any suggestions?

Paul
  • 189
  • 6

1 Answers1

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

Alternatively:

ask turtles with [ color = blue and payoff < 0 ] [ set color red ]
Bryan Head
  • 12,360
  • 5
  • 32
  • 50