Paul
Paul

Reputation: 189

Fracctionate turtles population in Netlogo

Hello I am writing a code in which a population of turtles with 3 different colors interact and play certain strategies with a payoff from using any of the strategy. But what i want to do is create a population of turtles and fractionate it to get, let say, 1/3 with color blue, 1/3 with color red and 1/3 with color green but without using 3 buttons just defining the population like number with a slider. Any suggestions for the code?

Upvotes: 2

Views: 64

Answers (1)

JenB
JenB

Reputation: 17678

If you want exactly one third in each color, the following will work (and has the advantage of automatically dealing with the case where the slider value is not divisible by 3):

create-turtles <slider varname>
[ ...
  set color item (who mod 3) (list red blue green)
...
] 

If you want a more probabilistic approach, where each turtle has a chance of being any of the colors (and potentially different group sizes), it's almost the same code

create-turtles <slider varname>
[ ...
  set color one-of (list red blue green)
...
] 

Upvotes: 2

Related Questions