Skip to content

Building Conway's Game of Life - Part 1

Published: at 11:20 AM

Building Conway’s Game of Life - Part 1

Source: Numberphile - Youtube video

*(Image Source: Numberphile - Youtube video)*

I built an extremely simple python terminal implementation of John Conway’s Game of Life. Source code on github - plays inside a Jupyter notebook. This is what it looks like in action:

Game of life - in python

Wikipedia link

Conway’s Game of Life is a cellular automaton that is played on a 2D square grid. It was devised by the British mathematician John Horton Conway in 1970. Cellular automata is an interesting field of study that shows how complexities can emerge from very simple rules and initial conditions. The game of life is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Rules:

Each square (or “cell”) on the grid can be either alive or dead, and they evolve according to the following rules:

The initial configuration of cells can be created by a human, but all generations thereafter are completely determined by the above rules. The goal of the game is to find patterns that evolve in interesting ways – something that people have now been doing for over 50 years. (see this amazing lexicon for inspiration)

My python Implementation:

My starting point is chapter 4 of this amazing resource for learning python. Unlike the classic implementations which have an infinite 2D grid, this implementation folds over itself from right-to-left and from bottom-to-top. Which means a cell on the right most edge of the grid influences cells on the left most edge, and same for bottom and top edges. This makes likelihood of the game reach a “stable” state significantly higher. In this first version, the initial conditions are created at random, something I will change in future. Additionally, I made slight changes to original source code: (1) Added epochs counter to see how many iterations have passed, and (2) Logic to identify when a “stable” state has reached and mark the number of epochs it took to reach that stable state.

Source code on github - plays inside a Jupyter notebook

This is what it looks like in action:

Game of life - in python

Future plans as tinker around more:

Here is John Conway himself talking about inventing the Game of Life (Source: Numberphile): Game of life - in python

I keep a track of my learning journey, nerdy musings and creative projects on my blog and Twitter