Ok, the reproduction procedure
is going to ask the turtles
to create copies of themselves
going to use the hatch procedure
ask each turtle to hatch 2 turtles
by default those turtles will have
all the attributes of their parents
and to keep track of generations
that involves giving the turtles variables
I am going to call one of those variables
a generation.
So, now when we create a turtle, it will
automatically have a variable
called generation.
These little hatchlings,
that arrive on the scene,
they are going to automatically have that
variable too.
They are the next generation, so we want
them to set their generation to
Here we have to use a generation
myself plus one.
I think this might have to be
in square brackets.
Basically, we're setting
the commands apply to the newly arrived
hatchlings. Setting myself plus one.
Basically, just incrementing that.
I don't know if these square brackets
need to be there.
I could look at quick help for myself.
Yeah, sure enough.
It does have to be in square brackets.
This explains the difference
between self and myself.
We're going to hatch two and set them.
Just so we can see them.
Set their color to red.
Let's try going back here.
I am going to comment this out for now.
So we can test the code we've got so far.
Now we set up, and we step.
It looks to me like, every turtle has
Let's do a smaller population, just so
we can see. Let's start with 5 turtles.
We don't, ..., oh, I see, yeah,
I am guessing that these inherited
the heading of the parent too.
Sometimes it is confusing
when you are doing these kinds of models
because you don't know how many turtles
you have. You could do a simple thing,
show count of turtles.
It looks to me like there is just
10 turtles or so, but when we look, indeed
there are 15, there is overlap.
Another way you can do this is,
click on that,
turtles 11 and 12 are coincident.
The heading from their parent is causing
overlap. We don't need to worry about
that for now. So, reproduction works.
We might want to see if the generation
business works. Take a look back here at
the interface. This, if we inspect
this turtle, we should see that it has a
generation variable.
I don't see it.
Let's see if this one does.
Well, well, it's not there.
Something has gone awry.
Let's comment this out again.
Run setup.
Inspect this turtle.
Sure enough, we have the generation.
This is generation 0.
Turtle 3 is of generation 0.
When we step, with any luck,
it will be of generation 1.
So we are incrementing generation.
Our generation feature is working.
Ok, we're going to ask the parents to die.
It occurs to me we are going to have to
keep track of what generation we're on.
That is a global variable.
Every time we step we are going to
increment the current generation.
This will allow us to keep track of who
should die when.
Start out at zero, add one to it.
Make the parents die.
Ask turtles with generation less than
or equal to current generation
Create to partial agent sets.
Want to talk only with the turtles whose
generation is less than, maybe I just
mean less than, to die.
Let's go back here.
Setup, step, looks like, let's instead of
setting to red, set to a random number,
up to 100. That will mean they are
different colors. Just temporarily, so
we can see them.
We're seeing the different generations.
You can see the colors are changing.
The different generations are coming,
we can inspect these turtles,
we're only at generation 12,
but we've hatched over 20,000 turtles,
that's how exponential population growth
works, right?
We've got the parents dying.
We need some kind of constraint.
Something that makes it difficult,
so we don't have unlimited growth.
One easy way to do that
is to create a situation where
individuals die depending on how crowded
This is an idea from evolutionary biology,
individuals compete with each other,
and also compete with the environment
in some way.
This is a case where they are kind of
competing with each other for space, and
kind of the environment too.