Table of Contents
1. Advanced Variables |
2. Grass Grows... |
3. Giving Birth. |
4. Creating a graph. |
Like the last section, this part is quite short. All that you need to do is add a few lines so that if the turtles have enough energy then they can give birth.
go
procedure, after the turtle
has decided whether or not a patch of grass is good to eat:
if energy > 50 [
set energy 10
hatch 1
]
That's it! The code above checks to see if the turtle has more than 50 units of
energy stored up. If it does, then we reduce the amount of energy to 10 (to simulate
the stress of giving birth) and then use the hatch
command to create
a copy of the turtle.
grass-regrow-time
slider. If you change the amount of time it takes for
grass to re-grow, does this have an impact on the number of turtles in the model?
You'll probably notice that it is quite hard to work out how many turtles are actually in the model at any given time. It would be better if there was a way to see exactly how many turtles are alive at any given time. This is something that will be addressed next.