4 Memoizing immutable quadtrees to make a better Life
This chapter covers
- The rules of Life, a two-dimensional grid automation
- Using quadtrees to represent grids of bits
- The HashLife algorithm
- Finding astonishing performance improvements
“The Game of Life” -- or just “Life” for short -- is a cellular automaton created by the mathematician John Conway. Imagine a grid of values, where each value is in a “cell”. 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 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.