The Task

In Netlogo, upgrade the simple blocks program we did in class.

The Blocks Program

Your program will:

  1. Make a useful comment at the beginning of every procedure and at least one comment in each procedure.
  2. Your code should be correctly indented using the tab key.
  3. Use a slider to determine the number of yellow blocks (patches). This can be from 0 to 100 blocks.
  4. Use a slider to determine the number of red blocks (patches). This can be from 0 to 100 blocks.
  5. Use a slider to determine the number of turtles. This can be from 0 to 10 turtles.
  6. Create a button labeled Turtles that when pressed will create the indicated number of turtles. The turtles must be white, placed at a random location, and pointed in randomly in one of the 4 directions (N, S, E, W) and have a pen-size of 2. They start with their pen down.
  7. Create a button labeled Yellow that when pressed will create the number of yellow blocks in random places indicated by the slider. It is allowed to create 100 blocks and some blocks may accidentally overwrite other blocks.
  8. Create a button labeled Red that when pressed will create the number of red blocks in random places indicated by the slider. It is allowed to create 100 blocks but some blocks may accidentally overwrite other blocks.
  9. There needs to be a button labeled Step that first moves the turtle one step forward and then:
    • If the turtle is on a yellow block, the turtle will turn right and turn the block green.
    • Otherwise, if the turtle is on a green block, it will turn left and turn the block yellow.
    • If the turtle is on a red block it will turn the turtle white. And turn the block to blue.
    • Otherwise, if the turtle is on a blue block it will turn the turtle green. And turn the block back to red.
  10. There needs to be a button labeled Go that does Step forever.
  11. There needs to be a button labeled Setup that clears the screen of all blocks and turtles.
It is important that on a single step only one of the block interactions occurs on a given step. For instance, if the turtle lands on a yellow block it does NOT turn right, turn the block green and then turn left and turn the block back to yellow. That is, actions should not effect each other in the same step. We discussed this in class. (Hint: use nested ifelse statements)

Submission

Save your results as a .nlogo file and submit the file to the submission page found in the Services section of the class web page.