|
|
@ -19,15 +19,6 @@ var (
|
|
|
|
"Millisecond sleep interval per generation")
|
|
|
|
"Millisecond sleep interval per generation")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func pushChecksum(checksum string, checksums []string) {
|
|
|
|
|
|
|
|
head := make([]string, 3)
|
|
|
|
|
|
|
|
copy(head, checksums[:3])
|
|
|
|
|
|
|
|
checksums[0] = checksum
|
|
|
|
|
|
|
|
checksums[1] = head[0]
|
|
|
|
|
|
|
|
checksums[2] = head[1]
|
|
|
|
|
|
|
|
checksums[3] = head[2]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
|
@ -38,52 +29,32 @@ func main() {
|
|
|
|
os.Exit(2)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checksums := make([]string, 4)
|
|
|
|
genTicks, err := game.Generations()
|
|
|
|
checksums[0], checksums[1], checksums[2], checksums[3] = "foo", "bar", "baz", "qwx"
|
|
|
|
|
|
|
|
ck, err := game.Checksum()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "NAY NAY: %v\n", err)
|
|
|
|
fmt.Fprintf(os.Stderr, "No generations?: %v\n", err)
|
|
|
|
os.Exit(3)
|
|
|
|
os.Exit(3)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pushChecksum(ck, checksums)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond)
|
|
|
|
sleepInterval := time.Duration(*sleepMs * 1000 * 1000)
|
|
|
|
generations := 0
|
|
|
|
for genTick := range genTicks {
|
|
|
|
for now := range ticks {
|
|
|
|
fmt.Printf("\nGeneration %v\n%v\n", genTick.N, time.Now())
|
|
|
|
fmt.Printf("\nGeneration %v\n%v\n", generations, now)
|
|
|
|
|
|
|
|
fmt.Println(game)
|
|
|
|
fmt.Println(game)
|
|
|
|
|
|
|
|
|
|
|
|
game.EvaluateGeneration()
|
|
|
|
game.EvaluateGeneration()
|
|
|
|
|
|
|
|
|
|
|
|
curChecksum, err := game.Checksum()
|
|
|
|
if genTick.Error != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s: %s\n", genTick.Message, genTick.Error)
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to calculate current game checksum: %v\n", err)
|
|
|
|
|
|
|
|
os.Exit(4)
|
|
|
|
os.Exit(4)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if checksums[0] == curChecksum || checksums[1] == curChecksum {
|
|
|
|
if len(genTick.Message) > 0 {
|
|
|
|
fmt.Println("Stasis!")
|
|
|
|
fmt.Println(genTick.Message)
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if checksums[2] == curChecksum {
|
|
|
|
|
|
|
|
fmt.Println("Checksum found 2 periods ago")
|
|
|
|
|
|
|
|
fmt.Println("Stasis with 2-period oscillator(s)!")
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if checksums[3] == curChecksum {
|
|
|
|
if *mutate && genTick.N%2 == 0 {
|
|
|
|
fmt.Println("Checksum found 3 periods ago")
|
|
|
|
|
|
|
|
fmt.Println("Stasis with 3-period oscillator(s)!")
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pushChecksum(curChecksum, checksums)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if *mutate && generations%2 == 0 {
|
|
|
|
|
|
|
|
game.Mutate()
|
|
|
|
game.Mutate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
generations++
|
|
|
|
time.Sleep(sleepInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|