package main import ( "flag" "fmt" "os" "time" ) import ( . "github.com/meatballhat/box-o-sand/conway/go" ) 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, "Millisecond sleep interval per generation") ) func main() { flag.Parse() game := NewGameOfLife(*height, *width) err := game.ImportRandomState() if err != nil { fmt.Fprintf(os.Stderr, "WHAT IN FAIL?: %v\n", err) os.Exit(2) } cksum := game.Checksum() ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond) generations := 0 for now := range ticks { fmt.Printf("\nGeneration %v\n%v\n", generations, now) fmt.Println(game) game.EvaluateGeneration() if cksum == game.Checksum() { fmt.Println("Stasis!") os.Exit(0) } cksum = game.Checksum() if *mutate && generations%2 == 0 { game.Mutate() } generations++ } }