The GO function doesn't want to work. It's trying to spread a fire with different probailities for different colour but i cant get it to work
globals [
initial-trees
burned-trees
]
breed [fires fire]
to setup
clear-all
set-default-shape turtles "square"
ask patches with [(random-float 100) < density] [
set pcolor green
if random 100 < 50 [
set pcolor blue ]
if random 100 < 25 [
set pcolor yellow ] ]
ask patches with [pxcor = min-pxcor] [
ignite
]
set initial-trees count patches with [pcolor = green]
set burned-trees 0
reset-ticks
end
to ignite
sprout-fires 1
[ set color red ]
set pcolor black
set burned-trees burned-trees + 1
end
to go
print count patches with [ pcolor = yellow ]
print count patches with [ pcolor = blue ]
print count patches with [ pcolor = green ]
if not any? turtles
[ stop ]
ask fires
[ if neighbors4 [pcolor = green]
if random 100 < 50 [ignite] ]
[ if neighbors4 [pcolor = blue]
[ if neighbors4 [pcolor = yellow]
if random 100 < 25 [ignite] ]
tick
end
I've tried everything I can think of and nothing works.
So multiple things:
ifrequires to be followed by a logical statement.neighbors4 [pcolor = green]is not a logical statement.neighbors4creates an agentset. If you want to pick only green patches you could useneighbors4 with [pcolor = green]and to make it a logical statement useany? neighbors4 with [pcolor = green]. This would make a logical statement if TRUE/FALSE as a result and thus usable for theif.You want to
ignitethese patches and therefore have to select them. You currentlyaskthe fires to do something.sproutis a command that can only be used by patches. You therefore need to select the patch by using anotherask.You are missing brackets. The NetLogo Dictionary tells you when and how to use them. For if it says
if boolean [command]. So the consequence of your logical statement needs to be in square brackets. The logical expression itself does not.So keeping this in mind, there are multiple ways to achieve what you want. Here is one solution:
At least that is what I am guessing you would like to happen. It asks all neighbors and checks their color (using the
ifelsewith multiple choices by using the round brackets) and ignites them based on probabilities (check the numbers there, it is not quite clear based on your original code!)