The Task

In Netlogo, upgrade the simple blocks program we did in class. For the program you write be sure to use dashes and not underscores if you want to put a visual separator in a variable name. This is a programming convention of NetLogo. It is not required by the language but is tradition.

The Blocks Program

The program will:

  1. Unlike in class, use a slider to determine the number of yellow blocks (patches) that will be created as indicated below. This can be from 0 to 100 blocks. Blocks are "created" by simply by coloring patches, yellow in this case. To do this use the n-of command in NetLogo to do this. See the NetLogo manual.
  2. use a slider to determine the number of turtles as indicated below. This can be from 0 to 10 turtles.
  3. create a separate button labeled Turtles that when pressed will create the indicated number of extra turtles. That is it will add to the current number of turtles, the number of turtles indicated by the slider in the point just above. Hint: this is easier than it sounds.
  4. create a separate button labeled reset that when pressed will return all colored blocks to yellow. Hint: one way to do this is to ask the patches that are not black to set their color to yellow.
  5. create a button called Setup that will clear the screen and create the indicated number of yellow blocks and turtles. Essentially this button clears the screen and then does what the Turtles and Blocks buttons do.
  6. The turtles must be white, placed at a random location, and pointed in randomly in one of the four directions (N, S, E, W) and have a pen-size of 2. They start with their pen down. Do not do anything extra. Hint: in order to set to one of the four directions you need to set the heading to one of 0, 90, 180, 270. You can use random to generate the number betwen 0 and 3 and then multiply that by 90 or you could use a list of the four angles and use the one-of command. A list is simply a bracketed list of things see the user manual.
  7. create a button named Step that moves the turtles forward 1 step and then reacts to whatever color patch (block) the turtle is on.
  8. create a forever button named Go that will do whatever the Step button does, but does it forever.
  9. Turtles react to 3 colors of blocks. If the turtle is on a yellow block, the turtle will turn right 90 degrees and turn the block blue. If the turtle is on a blue block, it will turn left 90 degrees and turn the block red. If the turtle is on a red block it will turn 180 degrees and turn the color back to yellow. So the blocks will cycle through the colors yellow, blue, red, yellow, blue, red, ...
  10. Every time through the go routine (one step processed for all turtles) there is a 0.1% (1 in a 1000 chance) that the go command will execute the clear-drawing command! This will clear all the pen drawings but leave the patches and turtles untouched. HINT: clear-drawing is an observer context command and not allowed in the turtle context. So be sure you don't put it inside the part of the part of the go routine that asks the turtles to do anything!
  11. You must use the cascading ifelse for testing the block colors. It is good practice.


    Save your results as a .nlogo file and submit the file to the the BBLearn assignment. See BBLearn.