Adding variables to a basic NetLogo model

Objective: Students will learn how to improve the basic turtle NetLogo model to make it more realistic.

Materials: Each student will need

Directions

This lessonplan assumes that students have already completed the NetLogo model and discussions in the basic NetLogo lesson plan.

Add and Energy Variable

  1. Add a turtles-own declaration at the top of the Procedures tab:
    turtles-own [ energy ]

Questions to ask:

Make the Turtles Eat Grass

  1. Add a procedure called "to eat-grass" to the Procedures:
    to eat-grass
      ask turtles [       if pcolor = green [
          set pcolor brown
          set energy (energy + 10)
        ]
      ]
    end
  2. To make this happen when you click the go button, add this function to the "to go" procedure:
    to go
      move-turtles
      eat-grass
    end
  3. Run your model.

Questions to ask:

Make the Turtles Lose Energy and Die

  1. Rewrite move-turtles so the turtles lose energy as they walk:
    to move-turtles
      ask turtles [
        right random 360
        forward 1
        set energy energy -1
      ]
    end
  2. Add a procedure called check-death:
    to check-death
      ask turtles [
        if energy < = 0 [ die ]
     ]
    end

    And as always, for this procedure to happen, you must add it to the "go" procedure:
    to go
      move-turtles
      eat-grass
      check-death
    end
  3. Run your model. Your turtles should eat the grass and eventually they should all disappear.

Questions to ask:

Make the Grass Grow

  1. Add a procedure for regrow-grass:
    to regrow-grass
      ask patches [
        if random 100 < 3 [ set pcolor green ]
      ]
    end
  2. Add this to the go procedure:
    to go
      move-turtles
      eat-grass
      check-death
      regrow-grass
    end

Questions to ask:

Make the Turtles Reproduce

  1. Make the turtles reproduce:
    to reproduce
      ask turtles [
        if energy > 50 [
          set energy (energy - 50)
          hatch 1 [ set energy 50 ]
        ]
      ]
    end
  2. And add this to the go menu:
    to go
      move-turtles
      eat-grass
      reproduce
      check-death
      regrow-grass
    end

Questions to ask: