Extracting and testing generation emit and checksumming bits

This commit is contained in:
2012-12-11 23:35:49 -05:00
parent c0184dd9df
commit 353b59b303
4 changed files with 129 additions and 40 deletions

View File

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