diff --git a/conway/go/conways-game-of-life/main.go b/conway/go/conways-game-of-life/main.go index 870eae9..9ba03a0 100644 --- a/conway/go/conways-game-of-life/main.go +++ b/conway/go/conways-game-of-life/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "os" "time" @@ -10,18 +11,29 @@ import ( . "github.com/meatballhat/box-o-sand/conway/go" ) +var ( + height = flag.Int("height", 40, "Game height") + width = flag.Int("width", 80, "Game width") + sleepMs = flag.Int("sleep.millis", 200, + "Millisecond sleep interval per generation") +) + func main() { - game := NewGameOfLife(40, 40) + 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) } - ticks := time.Tick(1 * time.Second) + ticks := time.Tick(time.Duration(*sleepMs) * time.Millisecond) + generations := 0 for now := range ticks { - fmt.Printf("\n\n%v\n", now) + fmt.Printf("\nGeneration %v\n%v\n", generations, now) fmt.Println(game) game.EvaluateGeneration() + generations++ } } diff --git a/conway/go/game_of_life.go b/conway/go/game_of_life.go index d8aa865..1fc36a3 100644 --- a/conway/go/game_of_life.go +++ b/conway/go/game_of_life.go @@ -210,7 +210,7 @@ func (state *GameState) String() string { for y := 0; y < height; y++ { var cells []string for x := 0; x < width; x++ { - stringVal := "X" + stringVal := "Φ" value, err := state.Get(x, y) if err != nil { @@ -218,7 +218,7 @@ func (state *GameState) String() string { } if value == 0 { - stringVal = "_" + stringVal = "·" } cells = append(cells, stringVal) }