I mentioned there were two tricks, and that's only the first. The second trick is to cache the `results' of the LIFE calculation, but in a way that looks ahead farther in time as you go higher in the tree, much like the tree nodes themselves scan larger distances in space. This trick is just a little subtle, but it is where the bulk of the power of the program comes from.
Consider once again the 8-squares. We want to cache the result of executing LIFE on that area. We could cache the result of looking ahead just one generation; that would yield a 6x6 square. (Note that we cannot calculate an 8-square, because we are using the single instance of the 8-square to represent all the different places that 8x8 arrangement occurs, and those different places might be surrounded by different border cells. But we
can say for sure that the central 6-square will evolve in a unique way in the next generation.)
We could also calculate the 4-square that is two generations hence, and the 3-square that is three generations hence, and the 2-square that is four generations hence. We choose the 4-square that is two generations hence; why will be clear in a moment.
Now let's consider the 16-square. We would like to look farther ahead for this square (if we always only looked two generations ahead, our runtime would be at "least" linear in the number of generations, and we want to beat that.) So let's look 4 generations ahead, and cache the resulting 8-square. So we do.
Partager