Sunday, 15 July 2012

Conway's Game Of Life.

     Cellular automation devised by the British mathematician John Horton Conway, hence the name Conway's Game of Life.
The game is a zero player game, which has an initial set of cell configuration and based on a set of rules how the cells evolve.
     The game has 4 rules which each cell follows:-
Each individual cell interacts with its 8 neighboring cells.
  1. A living cell with 2 or 3 neighboring cells lives to join the next generation.
  2. A dead cell with exactly 3 cells in its neighborhood turns alive.
  3. A living cell having less than 2 cells as neighbors dies due to depression.(no company no life!)
  4. A living cell having more than 3 cells as neighbors dies due to overcrowding.(Phew! it's so stuffed out there.)
My approach to implement this game using pygame was to first get a random set of cells represented by little black rectangles indicating life on a white canvas. After which I checked for the rules according to Conway and accordingly adding and removing cells from the screen. The cells keep on evolving satisfying the conditions laid down in Game of Life.

The screenshot shows a program I implemented using pygame.

 


The code is available at my github id: anjalirmenon@github.com, search for conways game of life.

No comments:

Post a Comment