4 Memoizing immutable quadtrees to make a better Life
This chapter covers
- Following the rules of Life, a two-dimensional grid automation
- Using quadtrees to represent grids of bits
- Implementing the HashLife algorithm
- Finding astonishing performance improvements
The Game of Life—Life, for short—is a cellular automaton created by mathematician John Conway. Imagine a grid of values in which each value is inside a cell. The grid evolves one step at a time, based only on the arrangement of values in the preceding step. Life isn’t really a game in the traditional sense: although it has rules, it has no players. Instead, you create a particular arrangement of values and see whether it displays interesting behaviors as it evolves.
Building your own Life implementation is a common project in many programmers’ early attempts to learn their craft, and I was certainly no different. I wrote Life implementations for my Commodore 64 and Amiga 500 as a teenager and have reimplemented it many times since just for fun.