Skip to main content

Conway's Game of Life

– projects

Screenshots of the game.

Last night I made a simple implementation of Conway’s Game of Life in Python 3 with PyGame and NumPy. It’s available for download here.

The Game of Life basically consists of two-dimensional grid of square cells, each of which is either alive or dead and interacts with its eight adjacent cells (neighbors). At every clock tick, the state of each cell changes if one of the following conditions or rules are met:

  1. Any dead cell with exactly three neighbors becomes a live cell (reproduction).
  2. Any live cell with fewer than two live neighbors or more than three dies (underpopulation and overpopulation, respectively).

If a cell doesn’t match either condition, it stays in its current state. The simplest version of the game consists of setting the inital state and watching it evolve.

A friend from the university sent me this video of YouTuber Dot CSV explaining how to make the game in Python in 10 minutes, and he challenged me to do it. It took me 50 minutes, because I can’t type as fast as a sped-up recording and also because I had to look up how to stop PyGame from crashing.

My implementation of the game, like the one in the video, allows the user to pause and unpause the game by pressing any key, and to make cells alive or dead with left and right mouse clicks, respectively.

I enjoyed this little challenge, and I hope you enjoy downloading and running the game from here.