/ Golang

Hackathon: Conway's Game of Life

Recently, I had the pleasure of participating in an internal hackathon at work. They gave us two days to create whatever we wanted with whatever group of coworkers. There were no specific guidelines on what the project had to be or what technologies it needed to use, so I decided to go solo and recreate Conway's Game of Life in Go. I've been fascinated with the Game of Life ever since I first heard of it several years back. It's an exercise in cellular automation that works by simultaneously updating a grid of cells that are either alive or dead according to four rules:

  • If there are less than 2 living cells surrounding a living cell, it will die, as if by underpopulation.
  • If there are 2 or 3 living cells surrounding a living cell, it will continue to live.
  • If there are more than 3 living cells surrounding a living cell, it will die, as if by overpopulation.
  • If there are exactly 3 living cells surrounding a dead cell, it will become alive, as if by reproduction.

By applying these four rules simultaneously to the entire grid, interesting patterns emerge. Some shapes freeze and become a still life, while others oscillate between different patterns. Patterns that travel across the grid are known as spaceships or gliders. The Game of Life has been proven to be Turing complete, meaning it can be used to represent a computer, assuming unlimited memory and no time constraints. There's even an example of someone emulating Conway's Game of Life using Conway's Game of Life!

Go has a bit of an up and coming game development community, due to its growing popularity as a language. I found a somewhat popular 2D game library for Go called Pixel. Under the covers, Pixel uses OpenGL and is dead simple to get up and running. It provides some basic constructs and methods for 2D game development, which is exactly what I needed to recreate the Game of Life.

Armed with my knowledge of Go and newfound knowledge of Pixel, I embarked on my journey to recreate the Game of Life during the two days of the hackathon. Despite getting pulled off to work on production issues, I was able to have a working prototype after the first day. The second day was spent primarily on adding features, like saving the current grid state and different cell colors. I'm pretty proud of the end result.

game-of-life-screenshot

Since the hackathon, I've been cleaning up the code a bit, as time permits. I plan to also switch to an infinite grid, as opposed to the current grid that is limited to what you can see on the screen. Just a few minor improvements over the original design. The code can be found here:

https://github.com/eleniums/game-of-life-go

Go proved to be plenty fast enough to handle the demands of the Game of Life and was actually a pleasure to develop a game in. I didn't really run into any snags and the whole process was quite painless. I look forward to seeing how game development with Go continues to grow. I would call this hackathon a success and I look forward to the next one!

Stan Nelson

Stan Nelson

I love programming. I'll create stuff for fun outside of work just because I like figuring out problems and the act of creating. I also enjoy cars, games, hiking, and going on adventures.

Read More