Conway’s Game of Life

I realized one day that I had never implemented Conway’s Game of Life, which is something of a rite of passage for young computer-science students. As I opted for a more non-traditional path to the software profession, I somehow missed that fun, even though I’ve made a point of implementing other computer-sciency things like it.

While the game itself is actually quite simple (look at the generation method in the source code to see just how simple), the notion of implementing it on a self-contained web page and making it as fast as possible seemed intriguing, so I dived in. About six hours later I had it pretty much finished. Optimizing it took one more day several more days as new optimizations occurred to me.

The “Step” button will let you move forward one generation at a time to watch how the cells interact with each other. The link labeled “Link to current board state” will let you save a link to the cellular configuration that you see at any given time.

Live cells:
Generation time (ms):

Settings (Click “Stop” to Edit, “Start” to Activate)

More Patterns

Here are a few links to some interesting boards:

A Gosper glider gun

A Gosper glider gun running at top speed, probably faster than your screen’s refresh rate.

A set of cells that devolves into a single spinner.

A pair of gliders which follow each other endlessly.

A large board with a long-running pattern

Stand-alone Page

If you’d like to play with the game without all the WordPress clutter, you can take a look at the stand-alone page.

The JavaScript Code

I’m working on another article that goes through the code and explains how it works, but for now, here is the JavaScript code listing. You may download the CSS and JavaScript as well.


Leave a Reply

Your email address will not be published.