From ea5bb19b0b18eb9682f2905fb436851ece8adb19 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 9 Dec 2012 23:38:38 -0500 Subject: [PATCH] Flagging up the command-line interface and using unicode chars instead of X and _, dangit! --- conway/go/conways-game-of-life/main.go | 18 +++++++++++++++--- conway/go/game_of_life.go | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) 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) }