Tag Archives: conway

Update: Conway’s game of life

As part of my website’s facelift I decided to update the Conway’s game of life (Live page) project. The content was rearranged to make more sense to the first time user, a the controls organised in a way that made them larger and easier to navigate. I also changed the links to different shapes to be gallery objects (similar to what I had for the Mandelbrot project.) This is also the first page to get the “You might also like…” feature at the bottom, which will soon appear on most other pages when I get time to add them.

Before and after

Conway before the update
Conway before the update
Conway after the update
Conway after the update
Conway after the update
Conway after the update

Conway’s game of life

Conway’s game of life is a very famous mathematical model with a rich variety of “creatures” that can interact with one another. This script is a simple interactive sandbox where the user can “paint” cells to create different shapes. There are a number of predefined boards that the user can choose to investigate some small and interesting patterns as they evolve.

Links

Live page
GitHub repository

Overview

The underlying mathematics is very simple. Conway’s game of life follows three simple rules:

  1. A dead cell comes to life if there are three adjacent cells which are alive.
  2. A living cell dies if there are fewer than two adjacent cells which are alive.
  3. A living cell dies if there are more than three adjacent cells which are alive.

This is achieved by simply iterating over the board where each cell has two possible states (dead/alive) as well as the state from the previous turn. This procedure is then wrapped up in a series of window.setTimeout calls to allow the board to evolve.

Challenges

Challenge: The user must be able to paint cells to make shapes. The interaction must match the underlying grid.
Solution: Overcoming this challenge was largely a matter of seamless performance as well as correct handling of events. This was surprisingly straightforward given the lack of cross browser support for finding the cursor position. (Resolved)
Challenge: Ideally this should be an infinite sandbox.
Solution: After toying with the idea of an unlimited size of board the stretches to match the user’s patterns it was decided that this would be unfeasible. As the size of the board increases (for example, due to gospel gliders moving off to infinity) the amount of memory required to contain the game would increase to dangerous levels. In addition the splicing of additional columns (and to a lesser extent, rows) of the board would incur a significant CPU cost. The board is sufficiently large for most interesting patterns. (Resolved)
Challenge: Saving patterns with markup.
Solution: One of the most useful features was for users to be able to share their patterns with other people. To do this there is a link which automatically updates, storing the current board as a string as a url argument. This is then parsed, which turned out to be quite simple, and centred on the board. (Resolved)

Sample output

The gospel glider gun:

The gospel glider gun
The gospel glider gun