Courses‎ > ‎Introduction to Computer Science 1‎ > ‎Konstantinovich‎ > ‎ML1 9/2012‎ > ‎labs‎ > ‎

Lab 09 : Conway

posted Dec 18, 2012, 5:30 AM by Samuel Konstantinovich   [ updated Dec 21, 2012, 5:27 AM ]

Conway's Game of Life


Overview:

Each patch does one of two things (never do both):

Living cells: check if you stay alive or die.

Dead cells: check if you stay dead or come alive.


Rules :

1. living cells stay alive when there are 2 or 3 living neighbors, (die otherwise)
2. dead cells born (come to life) when there are 3 living neighbors (stay dead otherwise)


We abbreviate this rule as follows

S: 2, 3 (stay alive)

B: 3 (born)


Now you can make a Conway simulation to follow these rules:

1. Your setup should make a % of the patches alive randomly. We will use any color to be alive, and black to represent dead. (It would be nice to make a reporter function alive? As it would make your code very readable)

2. The function you will repeat forever should do two steps just like voting. Calculate the next state( counting your neighbors) , and change states(running the livingRules or the deadRules.

*Just like before you can store the next color, or you can store the counted neighbors) Use the rules defined above to decide what to do.

Make it better!

3. Add a slider to change the starting % of living patches in your setup.

4. Make patches that stay alive longer change to brighter colors. Try to start newly born cells at any color ending in 4 and go up by 1 every time it stays alive until it ends in 9, then just stay ending in 9 until you die. (e.g. start at 24 and go up to 30) If you do this, it really helps to have a reporter function (alive?) to use on a patch.


At this point you should have had the basic algorithm. Your code should have had a structure like this:

(the livestuff/deadstuff would be different in these two versions)

to go 

  ask patches [ counting ] ;separate the counting part from the changing part

  ask patches [ changeBasedOnCount]; look at the count and change your color based on the rules

end


to changeBasedOnCount

  ifelse alive? [ liveStuff ] [ deadStuff] ;separate the living/dead code so you cant do both

end

OR YOU CAN DO IT THIS WAY: (the livestuff/deadstuff would be different in these two versions)

to go 

  ask patches [ pickNextColor] ;decide what color to be, based on the neighbors

  ask patches [ changeColor] ;set the color to that color

end


to pickNextColor

  ifelse alive? [ liveStuff ] [ deadStuff] ;separate the living/dead code so you cant do both

end

Comments