Conway's Game of Life

by ukslim
  scripts
  sprites
See inside
Instructions

Conway's Game of Life:
- http://en.wikipedia.org/wiki/Conway's_Game_of_Life
- http://www.math.com/students/wonders/life/life.html

Click "Go" to begin the simulation.

While stopped, you can click cells to toggle them.
The start pattern is called "Acorn" and will grow to do stuff all over the screen before eventually settling to a steady state. Because the grid is small and loops, patterns can interfere with themselves and therefore not exhibit the behaviour they would on a boundless grid.

Also while stopped, you can click the buttons for a selection of ready-made patterns.

Out of consideration for your CPU, the simulation will stop if the simulation reaches a static state - but it will keep going forever if there is an oscillating pattern alive.

Notes and Credits

Acceptably fast now, due to only updating changed cells.

We keep the whole state in one List, and use the "double buffer" pattern -- half of the list is the current state, the other half is the next state, and we flick between the two; populating one by looking at the state of the other. We use a 1D list to represent a 2D grid by doing calculations like "index=row + (column * width)"

As we calculate the next state, whenever we find a cell that changes state, we add its X and Y coordinates to the 'changes' list -- as two items. Then to do a 'fast display' we chew through that list, only stamping those cells onto the screen. This is much faster than stamping every cell: even when the grid is apparently full of action, it's unusual for more than 50 of the 900 cells to change in one generation.

Shared: 3 Apr 2014 Modified: 4 Apr 2014
Favorite this project 5
Love this project 7
Total views 217
View the remix tree  1
  
More projects by ukslim