2014-04-26 14:50:58 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-08-31 21:55:18 -07:00
|
|
|
"fmt"
|
2014-04-26 14:50:58 -07:00
|
|
|
"math/rand"
|
2015-08-31 21:55:18 -07:00
|
|
|
"os"
|
2014-04-26 14:50:58 -07:00
|
|
|
"time"
|
|
|
|
|
2015-04-30 23:14:17 -07:00
|
|
|
"hackerbots.us/client"
|
2015-08-31 21:48:25 -07:00
|
|
|
"hackerbots.us/server"
|
2014-04-26 14:50:58 -07:00
|
|
|
)
|
|
|
|
|
2016-07-13 18:40:41 -07:00
|
|
|
var addr = flag.String("addr", "ws://localhost:8666", "server hostname")
|
2014-04-26 14:50:58 -07:00
|
|
|
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{
|
2016-07-13 18:40:41 -07:00
|
|
|
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{},
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|
|
|
|
var err error
|
2016-07-13 15:04:48 -07:00
|
|
|
err = c.Negotiate("spectator", c.Player)
|
2014-04-26 14:50:58 -07:00
|
|
|
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-04-26 14:50:58 -07:00
|
|
|
}
|
|
|
|
|
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()
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|