Today I implemented Conway's Game of Life on a lark. It was something to do.
Or anyway, I tried. I screwed
something up, so my sim doesn't quite obey the same rules as the traditional Game of Life, which are:
* For each step, for each cell, count how many of the 8 neighboring cells are occupied.
* If the count is 3, then the cell is occupied.
* If the count is 2 and the cell is already occupied, then the cell lives.
* Otherwise the cell dies.
Whatever I ended up with, it's not this. I can test this easily enough: in the standard sim, a string of 3 occupied cells in a row turns into a repeater, flicking back and forth between horizontal and vertical orientations. Mine doesn't.
However, my sim does have two interesting properties, which have prevented me from looking too closely into why it's "not working". First, it seems to be able to run more or less indefinitely without repeating state -- for a 40x30 grid, I ran over 100k steps without getting a repeat once -- which isn't to say that I got a repeat after that many steps; I just canceled the sim there to tweak it. Second, it likes to form what I call "corridors", two parallel lines of occupied cells with a one-cell gap between them.
I've posted the code for the sim
here. It's written in Python, using Pygame for visualization. The history checking is lines 44-54, the sim step is lines 60-82. I won't claim that this is great code, but it's a simple program so it should still be fairly easy to read.