diff --git a/conway/go/conways-game-of-life/main.go b/conway/go/conways-game-of-life/main.go index d9c92e5..4da2e76 100644 --- a/conway/go/conways-game-of-life/main.go +++ b/conway/go/conways-game-of-life/main.go @@ -15,10 +15,18 @@ var ( height = flag.Int("height", 40, "Game height") width = flag.Int("width", 80, "Game width") mutate = flag.Bool("mutate", false, "Mutate every other generation") - sleepMs = flag.Int("sleep.millis", 200, + sleepMs = flag.Int("sleep.ms", 200, "Millisecond sleep interval per generation") ) +func pushChecksum(checksum string, checksums []string) { + first2 := make([]string, 2) + copy(first2, checksums[:2]) + checksums[0] = checksum + checksums[1] = first2[0] + checksums[2] = first2[1] +} + func main() { flag.Parse() @@ -29,7 +37,9 @@ func main() { os.Exit(2) } - cksum := game.Checksum() + checksums := make([]string, 3) + checksums[0], checksums[1], checksums[2] = "foo", "bar", "baz" + pushChecksum(game.Checksum(), checksums) ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond) generations := 0 @@ -39,12 +49,20 @@ func main() { game.EvaluateGeneration() - if cksum == game.Checksum() { + curChecksum := game.Checksum() + + if checksums[0] == curChecksum { fmt.Println("Stasis!") os.Exit(0) } - cksum = game.Checksum() + if checksums[1] == curChecksum || checksums[2] == curChecksum { + fmt.Println("Checksum found in last 2") + fmt.Println("Stasis with blinkers or beacons or some such!") + os.Exit(0) + } + + pushChecksum(curChecksum, checksums) if *mutate && generations%2 == 0 { game.Mutate()