Personal Projects

Game of Life

John Conway's Game of Life

Work
Processing, Cellular Automata, and Mathematical Patterns
A recreation of John Conway's Game of Life, along with a recreation of certain specific patterns that appear throughout it.

John Conway's Game of Life

I found John Conway's Game of Life while researching interesting mathematical concepts I might be able to code and was enticed by its beauty. The Game of Life is a representation of cellular automaton devised by the British mathematician John Horton Conway in 1970. My version of it is comprised of a black board with green dots, representing a cell being alive. The game follows four simple rules:

1) A live cell dies (becomes black, in this case) if it has fewer than two live direct neighbors (including the corner neighbors, not just the orthogonal ones)

2) A live cell with two or three neighbors lives on to the next generation

3) A live cell with four or more neighbors dies

4) A dead cell will be brought to life in the next generation if it has exactly three live neighbors

That's it. Every tick of the board represents the next generation, and some amazing patterns can be seen, including spaceships!

The Process

I initially wanted to code this with Unity, so C#, because I wanted to learn the language and make use of Unity's ability to change variables mid-scene to slow down or speed up the simulation. However, I quickly realized that I'd be able to create it in Processing much faster, and likely my code would be significantly more optimized. While the code for detecting the rules was actually quite simple, the code for detecting how many neighbors a cell has proved to be incredibly tedious. I had to check 9 unique cases: if the cell was in any of the corners, if it was on a side row or column, but not in a corner, or if it was somewhere in the center of the board separately. This is because my version of the Game of Life loops around the sides, similar to how Pac-Man can exit the left side of the screen and enter from the right. This resulted in 258 lines of repetitive code just to determine how many neighbors a cell has.

The Results

I actually originally made an incorrect version of the Game of Life, but thought it was correct. At this point, I tried testing my faulty code by testing some specific patterns that I found on this website, and found that they didn't behave as expected. After finally identifying and resolving the issue, I ran the test again and it passed. I then implemented some much more complex patterns, such as a spaceship, and was glad to see everything worked as it should. In my final version, I've retained the code for a random simulation, another random simulation that is incorrect (but still is interesting), a couple spaceships, some basic patterns, and a few others that I really don't know how to describe.

I'll post some videos of the simulation in action here soon.

Other Projects