Vincent Costel

Evening Project: Conway's Game of Life

What can you code in an evening? I had never implemented John Conway's Game of Life before, so one evening I decided to give it a go.

I simply used an HTML Canvas and some javascript. The code isn't pretty but it was quick to write and I had plenty of time left to play with different patterns and starting configurations.

I showed it to my kids the next day. They were really excited and we spent a long time fiddling with it. The loved the glider gun!

Gosper glider gun shooting gliders (Wikipedia)

The world is supposed to be an inifinite plane and the cells should be able to exist outside the visible world (the canvas), but I used a fixed size 2-dimensional array to represent the state of each cell. The problem with this approach is that the game breaks at the edges because a cell must have 8 neighbors, but this condition is not true on the edges.

A simple way to fix this problem is to just stitch the edges together. The left border is connected to the right border, and the top to the bottom. This way the world becomes finite as if it was shaped like a torus. It's cheating but it was good enough.

Start the Demo