4 Memoizing immutable quadtrees to make a better Life
This chapter covers
- The Game of Life is a famously simple two-dimensional grid automaton
- Quadtrees can represent cellular grids
- The HashLife algorithm powerfully combines immutability, recursion and memoization
- Astonishing performance improvements can come from leveraging specific quirks
“The Game of Life” -- or just “Life” for short -- is a cellular automaton created by the mathematician John Conway. What is a cellular automaton? Imagine a grid of “cells”, each of which has some discrete value. The grid “evolves” one step at a time, based only on the arrangement of values in the previous step. It’s not really a “game” in the traditional sense: though it has rules, there are no “players”. Rather, you can create a particular arrangement of cell values, and then see if they have interesting behaviors as they evolve.
Building your own Life implementation is a common project in many programmers’ early attempts at learning their craft, and I was certainly no different. I wrote Life implementations for my Commodore 64 and Amiga 500 as a teenager and have re-implemented it many times since just for fun.