I'm trying to ask white turtles to create yellow turtles to one of the 8 empty neighboring spaces. If there is no free space the turtle should produce nothing. Note: white turtles stay white and produce yellow turtles which are able to reproduce themselves as well as other yellow turtles. In summary, at the end I would like to fill up the black spaces with yellow turtles.
breed [ cells cell ]
cells-own [ n ]
to setup
clear-all
set-default-shape cells "square"
ask patches [ if pycor = min-pycor [sprout-cells 1]]
ask cells [ ifelse random 10 < 2 [set color white] [set color yellow]]
Thanks for the reply.
I'll explain what I'm trying to do:
Thanks again for your help.
reset-ticks
end
to go
ask cells
[ set n count neighbors with [pcolor = yellow] ]
ask cells
[ if n >= 1
[ set color yellow] ]
tick
;ask cells
;[if ticks = 10
;[set color yellow]]
end
What exactly you are trying to do is not entirely clear to me. I am going to go with a likely interpretation, but whether or not my interpretation is correct, you should try to clarify your question.
Trying to understand your code, it seems to me like there is a bit of confusion between patches and turtles. In your go procedure, you ask cells to turn yellow if they have a yellow neighbor. I think that what you want is for a yellow square to appear on patches that are neighbors of yellow squares. The empty patches you are trying to fill don't have any cells on them yet, so ask cells to turn yellow will not help you here.
If you really want to stick with cell agents, keeping your current setup procedure, you could do something like:
to go
ask patches with [not any? turtles-here] [
if any? neighbors with [any? turtles-here] [
sprout-cells 1 [
set color yellow
]
]
]
end
(If you want your cells to grow from the bottom up only, you should turn off wrapping in the view settings by right clicking on the view and choosing Edit...)
Now, a completely different approach, that may be simpler if all you want is some kind of cellular automaton, would be to ditch agents and work only with patches. That would give you something like:
to setup
clear-all
ask patches [
if pycor = min-pycor [
ifelse random 10 < 2
[set pcolor white]
[set pcolor yellow]
]
]
reset-ticks
end
to go
ask patches with [pcolor = black] [
if any? neighbors with [pcolor = yellow or pcolor = white] [
set pcolor yellow
]
]
tick
end
Both approaches are valid. The first one is a bit more visually pleasing. The second one is slightly simpler because you don't need turtles at all. It depends on what you ultimately want to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With