Reputation: 189
Hello i have the following code:
to go
move
play-papelvstije
play-papelvsrock
play-tijevsrock
play-tijevspapel
play-rockvspapel
play-rockvstije
end
to play-rockvspapel
ask turtles with [color = red]
[
let nearby other turtles in-radius 1
if any? nearby with [color = green]
[
set color green
]
]
end
to play-papelvstije
ask turtles with [color = green]
[
let nearby other turtles in-radius 1
if any? nearby with [color = blue]
[
set color blue
]
]
end
to play-tijevsrock
ask turtles with [color = blue]
[
let nearby other turtles in-radius 1
if any? nearby with [color = red]
[
set color red
]
]
end
to play-rockvstije
ask turtles with [color = red]
[
let nearby other turtles in-radius 1
if any? nearby with [color = blue]
[
set color red
]
]
end
to play-papelvsrock
ask turtles with [color = green]
[
let nearby other turtles in-radius 1
if any? nearby with [color = red]
[
set color green
]
]
end
to play-tijevspapel
ask turtles with [color = blue]
[
let nearby other turtles in-radius 1
if any? nearby with [color = green]
[
set color blue
]
]
end
So as you can see, i run this procedures play-papelvstije play-papelvsrock play-tijevsrock, play-tijevspapel, play-rockvspapel, play-rockvstije in this exactly order, so when run the simulation i get an slant in my results, because the first command to run is the one that have an increase population in the end, so what i want to do is finding a way to run this procedures but with one just command. I have tried with "foreach" and "map" commands, however i have not gotten results. Anny suggestions?
Upvotes: 0
Views: 244
Reputation: 1399
one solution can be to not directly ask blue turtles but for all turtles ... something like
to setup
clear-all
create-turtles 100 [
set color red
setxy random-pxcor random-pycor
]
ask n-of 10 turtles [
set color green
]
ask n-of 10 turtles with [color = red][
set color blue
]
reset-ticks
end
to go
move
changeColor
tick
end
to move
ask turtles [
rt random-float 90
lt random-float 90
fd 1
]
end
to changeColor
ask turtles [
let mycolor color
let nearby other turtles in-radius 1
if mycolor = blue [
if any? nearby with [color = green]
[
set color blue
]
if any? nearby with [color = red]
[
set color red
]
]
if mycolor = green [
if any? nearby with [color = red]
[
set color green
]
if any? nearby with [color = blue]
[
set color blue
]
]
if mycolor = red [
if any? nearby with [color = red][
if any? nearby with [color = blue]
[
set color red
]
if any? nearby with [color = green]
[
set color green
]
]
]
]
end
Upvotes: 1