Flagging up the command-line interface

and using unicode chars instead of X and _, dangit!
This commit is contained in:
Dan Buch 2012-12-09 23:38:38 -05:00
parent 00b750e2b0
commit ea5bb19b0b
2 changed files with 17 additions and 5 deletions

View File

@ -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++
}
}

View File

@ -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)
}