Detecting statis with blinkers or beacons or some other 2-period oscillator
This commit is contained in:
parent
8ff1125452
commit
78625088e8
@ -15,10 +15,18 @@ var (
|
|||||||
height = flag.Int("height", 40, "Game height")
|
height = flag.Int("height", 40, "Game height")
|
||||||
width = flag.Int("width", 80, "Game width")
|
width = flag.Int("width", 80, "Game width")
|
||||||
mutate = flag.Bool("mutate", false, "Mutate every other generation")
|
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")
|
"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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -29,7 +37,9 @@ func main() {
|
|||||||
os.Exit(2)
|
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)
|
ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond)
|
||||||
generations := 0
|
generations := 0
|
||||||
@ -39,12 +49,20 @@ func main() {
|
|||||||
|
|
||||||
game.EvaluateGeneration()
|
game.EvaluateGeneration()
|
||||||
|
|
||||||
if cksum == game.Checksum() {
|
curChecksum := game.Checksum()
|
||||||
|
|
||||||
|
if checksums[0] == curChecksum {
|
||||||
fmt.Println("Stasis!")
|
fmt.Println("Stasis!")
|
||||||
os.Exit(0)
|
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 {
|
if *mutate && generations%2 == 0 {
|
||||||
game.Mutate()
|
game.Mutate()
|
||||||
|
Loading…
Reference in New Issue
Block a user