Conway’s Game of Life, In Go

About a week ago, I decided to implement Conway’s Game of Life in Go. There was no particular reason, other than that I was bored, I wanted to do something else with Go, and I had never tried to implement Life before.

For those who don’t know, Life is a zero-player “game” in which an ecosystem is seeded, and then plays out all by itself. Once begun, each generation follows these basic rules:

  1. Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by overcrowding.
  4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

That’s it. You start it up, and then sit back and watch for patterns to emerge. So far, I have a version that uses a portable curses-like library for console graphics. It runs on OSX, and should definitely run on Linux. The page for termbox-go says that it will run on Windows, but I haven’t tried it. I plan to build a “prettier” version using Gtk+, but that will take a little while, since I don’t know Gtk+ (yet!).

Here’s a screenshot of the current version running:

Screen Shot 2013-08-17 at 9.01.52 AM

If you want to see the code, it’s on github.