You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB

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.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()
game := NewGameOfLife(*height, *width)
err := game.ImportRandomState()
if err != nil {
fmt.Fprintf(os.Stderr, "WHAT IN FAIL?: %v\n", err)
os.Exit(2)
}
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
for now := range ticks {
fmt.Printf("\nGeneration %v\n%v\n", generations, now)
fmt.Println(game)
game.EvaluateGeneration()
curChecksum := game.Checksum()
if checksums[0] == curChecksum {
fmt.Println("Stasis!")
os.Exit(0)
}
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()
}
generations++
}
}