package main import ( "flag" "fmt" "math/rand" "os" "time" "hackerbots.us/client" "hackerbots.us/server" ) var addr = flag.String("addr", "ws://localhost:8666", "server hostname") var forceJSON = flag.Bool("json", false, "force json encoding") func main() { rand.Seed(time.Now().UnixNano()) var gameId string flag.Parse() if flag.NArg() < 1 { gameId = "debug" } else { gameId = flag.Arg(0) } c := &client.Client{ Server: *addr, Name: "bspect", GameId: gameId, ForceJSON: *forceJSON, StateStream: make(chan *server.Boardstate), Die: make(chan struct{}), Player: client.Spectator{}, } var err error err = c.Negotiate("spectator", c.Player) if err != nil { fmt.Fprintf(os.Stderr, "%s: failed to negotiate: %s\n", c.Name, err) os.Exit(1) } go func() { if err := c.Play(); err != nil { close(c.Die) } }() c.Visualize() }