client/cmd/botspectate/main.go

50 lines
905 B
Go
Raw Normal View History

package main
import (
"flag"
2015-08-31 21:55:18 -07:00
"fmt"
"math/rand"
2015-08-31 21:55:18 -07:00
"os"
"time"
"hackerbots.us/client"
2015-08-31 21:48:25 -07:00
"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,
2015-08-31 21:48:25 -07:00
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 {
2016-07-13 11:31:28 -07:00
fmt.Fprintf(os.Stderr, "%s: failed to negotiate: %s\n", c.Name, err)
2015-08-31 21:55:18 -07:00
os.Exit(1)
}
2014-05-04 00:33:46 -07:00
go func() {
if err := c.Play(); err != nil {
2015-08-31 21:48:25 -07:00
close(c.Die)
2014-05-04 00:33:46 -07:00
}
}()
2015-08-31 21:48:25 -07:00
c.Visualize()
}