You are on page 1of 3


Building a model

Where to find it?

NetLogo -> File -> New


Part I:
1. In the “Interface” tab create a new button and name it setup.

2. In the “Code” section write the following code:

to setup
create-turtles 150
ask turtles
setxy random-xcor random-ycor
Go back in the “Interface” tab and press the setup button you have just created. What is

3. Run the model a couple times and observe whether the turtles are overlapping. If yes,
write a procedure in order to avoid this. Run the model. Are the turtles still overlapping? If
yes, please modify the parameters of the setxy command. Does it works?
The following view over the world should be obtained:
4. In the “Interface” create a new button, with the following characteristics:
a. Name: go;
b. It runs over and over again, not just once;
c. It does not start until pressing the setup button.
Assign to this button the needed code in order to permit the movement of turtles randomly with
one patch at each iteration.
Add also the tick command which will enable the usage of the “on ticks” view in the “Interface”
instead of “continuous” mode. Return to “Interface” and run the model. Observe what happens
when you are in the “on ticks” mode and in the “continuous” mode. Monitor the number of ticks
in the interface.

5. Change the default form of the “turtles” into real turtles.

6. List the code written so far.

Part II:
1. Restructure the setup procedure by writing a separate procedure for the creation of the
turtles. Change the background by choosing color no. 62.

2. Create a new turtle variable and call it “energy”. Write a procedure (call it “eat-grass”)
which will enable the turtles to eat grass (change the color of the patch in black) and increase
their energy with 15 units. Create two monitors: one for the number of turtles (name it “no.
of turtles”) and another one for the number of patches colored with color no. 62 (name it
“no. of grass patches”). More, as the turtles are moving from one patch to another, make
them lose 2 units.

3. Show the energy on each turtle and control it using a switcher in the Interface (call it “show-

4. As the turtles are eating and are having energy, let’s make them reproduce and die.

The “reproduce-turtles” procedure should create one or two new turtles when the energy of
any turtle exceed 60 units. More, the following changes should be implemented in the Code
and Interface:
a. The energy of the “mother-turtle” is decreasing by 50 units when having “baby-
b. The new turtle/turtles are receiving 25 units of energy;
c. The label (for the energy) of the new turtles is red;
d. In Interface two new monitors will be added in order to show at any time the number
of the “old” / “initial” turtles and the number of the turtles “born” after running the
model (the name of the monitors should be: “no. of turtles – white label” and “no.
of turtles – red label”).
The “die-turtles” procedure eliminates all the turtles with negative energy. Write the
procedure and then run the model. What happens? Why is this happening?

5. Create a plot to show the evolution of the turtles with white and with red labels.

6. What happened with the grass in the previous simulations? Let’s now make the grass grow
back. Create a procedure (“regrow-grass”) and impose a random condition for the grass
grow with a probability of 5%. Keep in mind that the color of the grass in this case is color
no. 62. Plot the number of the patches with grass and without grass.

7. List the code written so far.

Part III:
1. Make your model more user-friendly by allowing your variables to be easily modified. For
this, create a slider for the selection of the initial number of turtles. What changes should be
made to the code? Compare the case in which you select a small number of initial turtle with
the case in which you have a greater number of initial turtles. Is there a difference after
running the model?

2. Adjust the energy the turtles are receiving after eating the grass (put a slider and make the
necessarily changes in the code). Set the energy received from eating the grass between 5
and 30. What happens with the turtles? For a better comparison, impose the model to stop
after 300 iterations.

3. Make the birth energy adjustable with a slider. Set the minimum energy at 10 and the
maximum at 30. Make the changes in the code. Run the model, while changing the energy
from the slider. What can be observed?

4. Put a slider for the grass growing probability (as any probability, it can take values from 0
to 100). Make the needed changes in the code. Play different scenarios and make some

5. Set the energy needed for reproduction to be easily selectable within a slider taking values
between 50 and 150. Change the code accordingly and run the model while setting the
reproduction-energy-condition as close as possible to the maximum value. What happens in
this case?

6. Set a slider to select the number of iterations at which the model should stop. Put the
minimum number 1 and the maximum number 1000. Modify the code accordingly. Run the
model and make some conclusions.

7. List the code for the Part III.