Lecture: 12-10-2012

posted Dec 10, 2012, 8:29 AM by Samuel Konstantinovich   [ updated Dec 11, 2012, 5:37 AM ]

Cellular Automata Introduction:

Problem to start with: Voting by majority

Using neighbors (all 8) to decide what color to be the next day:

Set up the model:

Make all patches either red or black randomly. The % doesn't matter as long as it isn't very extreme.

Every Round repeat:

1. Count how many of the patches adjacent to you are red / black.

2. When more than 5 are red you should turn red. When more than 5 are black you should turn black.

In order to do that we need to be able to get an agentset of just your 8 neighbors. We need to use a new command.

neighbors → gives you an agentset of the 8 adjacent patches.

neighbors4 → gives you an agentset of the 4 ajacent patches (up down left and right)

and you probably want to count them...


If you write your go command like this:

ask patches





Then each patch will run both commands before letting the next patch do the command.

BUT! If you ask the patches to do separate sets of commands, they all finish the 1st command before starting the second command.

ask patches[ countNeighbors]

ask patches[ changeColor ]

If you don't understand the difference try using setup and testing the together and separate commands :

to setup

cro 10


to together

ask turtles [ fd 10 rt 90 wait .1]

;one turtle moves, then turns, then the next turtle moves and turns until all turtles have done this. 


to separate

ask turtles [ fd 10 wait .1]

ask turtles [rt 90 wait .1]

;each turtle moves one at a time

;then each turtle turns one at a time