Conway’s Game of Life

A Cellular Automation Method created with Biology in mind by Jon Conway.

enter image description here

By far the hardest game I had to implement using OOP and Pygame. The visualizations weren’t as nice because I couldn’t use any local images, but it was the most educational game I’ve created so far. I gave up a few times trying to figure out this code on my own and now that its done, I’m pretty impressed at the results.

GAME RULES:

For the life, the universe is an infinite 2D orthogonal grid of square cells. Each of which has either two states, alive or dead. Every cell interacts with eight neighbours which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  1. Any live cell with fewer than two live neighbours dies, as if caused by under population.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overcrowding.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed, and births and deaths occur at the same time. Each following generation is a result of applying the function or rules to the preceding one. The rules continue to be applied repeatedly to create further generations.

Simpler explanation:

  1. If a cell is ON and has fewer than two neighbors that are ON, it turns OFF
  2. If a cell is ON and has either two or three neighbors that are ON, it remains ON.
  3. If a cell is ON and has more than three neighbors that are ON, it turns OFF.
  4. If a cell is OFF and has exactly three neighbors that are ON, it turns ON.

GAMEPLAY

  • SPACEBAR: This will activate a selected cell to either be ALIVE or DEAD.
  • “S”: Press the “S” key to start or stop the game.
  • “C”: Press the “C” key to clear your screen.
  • “N”: Press the “N” key to show automatically jump to the next generation.
  • “R”: Press the “R” key to randomize your cells.
  • “P”: Press the “P” key to change the patterns of your cells.
  • “M”: Press the “M” key to show the four different views of cells: -> Normal -> Marked ->New Alive -> Died Out
  • “G”: Press the “G” key to toggle the grid view on the screen.
  • “Q”: Press the “Q” key to exit out of the game.