Remove spurious logging
This commit is contained in:
parent
3ef90af341
commit
623dfa4c48
@ -2,8 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"hackerbots.us/client"
|
||||
@ -12,11 +13,9 @@ import (
|
||||
|
||||
var serverHostname = flag.String("server", "localhost", "server hostname")
|
||||
var port = flag.Int("port", 8666, "server port")
|
||||
var verbose = flag.Bool("verbose", false, "run verbosly")
|
||||
var forceJSON = flag.Bool("json", false, "force json encoding")
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var gameId string
|
||||
flag.Parse()
|
||||
@ -31,7 +30,6 @@ func main() {
|
||||
Port: *port,
|
||||
Name: "bspect",
|
||||
GameId: gameId,
|
||||
Verbose: *verbose,
|
||||
ForceJSON: *forceJSON,
|
||||
StateStream: make(chan *server.Boardstate),
|
||||
Die: make(chan struct{}),
|
||||
@ -40,7 +38,8 @@ func main() {
|
||||
var err error
|
||||
err = c.Negociate("spectator")
|
||||
if err != nil {
|
||||
log.Fatalf("%s: failed to negociate: %s", c.Name, err)
|
||||
fmt.Fprintf(os.Stderr, "%s: failed to negociate: %s\n", c.Name, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
19
client.go
19
client.go
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
|
||||
@ -28,7 +27,6 @@ type Client struct {
|
||||
Port int
|
||||
Server string
|
||||
StatsReq server.StatsRequest
|
||||
Verbose bool
|
||||
Game server.GameParam
|
||||
|
||||
boardstate *server.Boardstate
|
||||
@ -55,9 +53,6 @@ type decoder interface {
|
||||
|
||||
// Negociate runs through the hackerbots negociation protocol.
|
||||
func (c *Client) Negociate(clientType string) (err error) {
|
||||
if c.Verbose {
|
||||
log.Printf("%s: trying to connect to game '%s'", c.Name, c.GameId)
|
||||
}
|
||||
c.ws, err = connect(c.Server, c.Port)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("connection failure: %s", err))
|
||||
@ -80,9 +75,6 @@ func (c *Client) Negociate(clientType string) (err error) {
|
||||
if err != nil || idreq.Type == "failure" {
|
||||
return errors.New(fmt.Sprintf("failure: %+v", idreq))
|
||||
}
|
||||
if c.Verbose {
|
||||
log.Printf("%s: idreq: %+v", c.Name, idreq)
|
||||
}
|
||||
|
||||
err = websocket.JSON.Send(c.ws, struct {
|
||||
Type string `json:"type"`
|
||||
@ -110,9 +102,6 @@ func (c *Client) Negociate(clientType string) (err error) {
|
||||
if c.Game.Type != "gameparam" {
|
||||
return errors.New("didn't receive a good gameparam")
|
||||
}
|
||||
if c.Verbose {
|
||||
log.Printf("%s: game parameters: %+v", c.Name, c.Game)
|
||||
}
|
||||
|
||||
if c.Game.Encoding == "json" {
|
||||
c.enc = json.NewEncoder(c.ws)
|
||||
@ -130,9 +119,6 @@ func (c *Client) Negociate(clientType string) (err error) {
|
||||
c.Name: c.StatsReq,
|
||||
},
|
||||
}
|
||||
if c.Verbose {
|
||||
log.Printf("%s: client config: %+v", c.Name, conf)
|
||||
}
|
||||
|
||||
err = websocket.JSON.Send(c.ws, conf)
|
||||
|
||||
@ -146,9 +132,6 @@ func (c *Client) Negociate(clientType string) (err error) {
|
||||
if !handshake.Success {
|
||||
return errors.New(handshake.Reason)
|
||||
}
|
||||
if c.Verbose {
|
||||
log.Printf("%s: handshake: %+v", c.Name, handshake)
|
||||
}
|
||||
|
||||
// we don't do anything useful with dstats, but could be interesting to
|
||||
// pass along to the player?
|
||||
@ -173,8 +156,6 @@ func (c *Client) Negociate(clientType string) (err error) {
|
||||
// server, and passes this along to the embedded Player. Following this it
|
||||
// sends the server the Player's instruction.
|
||||
func (c *Client) Play() error {
|
||||
log.Printf("%s: starting loop", c.Name)
|
||||
|
||||
bs := &server.Boardstate{}
|
||||
var err error
|
||||
for {
|
||||
|
@ -2,8 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"hackerbots.us/client"
|
||||
@ -25,11 +26,9 @@ var weaponSpeed = flag.Int("wspeed", 50, "weapons speed")
|
||||
var serverHostname = flag.String("server", "localhost", "server hostname")
|
||||
var port = flag.Int("port", 8666, "server port")
|
||||
var botname = flag.String("name", "gobot", "the name that other players will see")
|
||||
var verbose = flag.Bool("verbose", false, "run verbosly")
|
||||
var forceJSON = flag.Bool("json", false, "force json encoding")
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var gameId string
|
||||
flag.Parse()
|
||||
@ -56,7 +55,6 @@ func main() {
|
||||
WeaponDamage: *weaponDamage,
|
||||
WeaponSpeed: *weaponSpeed,
|
||||
},
|
||||
Verbose: *verbose,
|
||||
ForceJSON: *forceJSON,
|
||||
StateStream: make(chan *server.Boardstate),
|
||||
Die: make(chan struct{}),
|
||||
@ -66,7 +64,8 @@ func main() {
|
||||
var err error
|
||||
err = c.Negociate("robot")
|
||||
if err != nil {
|
||||
log.Fatalf("%s: failed to negociate: %s", c.Name, err)
|
||||
fmt.Fprintf(os.Stderr, "%s: failed to negociate: %s\n", c.Name, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
@ -27,7 +27,7 @@ func (s *Client) Recv(bs *server.Boardstate) map[string]server.Instruction {
|
||||
func (s *Client) Visualize() {
|
||||
err := termbox.Init()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s.viewX, s.viewY = termbox.Size()
|
||||
@ -50,7 +50,6 @@ func (s *Client) Visualize() {
|
||||
case termbox.EventKey:
|
||||
switch event.Key {
|
||||
case termbox.KeyCtrlZ, termbox.KeyCtrlC:
|
||||
log.Printf("exiting ...")
|
||||
return
|
||||
}
|
||||
|
||||
@ -64,7 +63,7 @@ func (s *Client) Visualize() {
|
||||
case termbox.EventResize:
|
||||
s.viewX, s.viewY = event.Width, event.Height
|
||||
case termbox.EventError:
|
||||
log.Fatalf("Quitting because of termbox error: \n%s\n", event.Err)
|
||||
panic(fmt.Sprintf("Quitting because of termbox error:\n%v\n", event.Err))
|
||||
}
|
||||
case u := <-s.StateStream:
|
||||
termbox.Clear(termbox.ColorBlack, termbox.ColorBlack)
|
||||
@ -181,7 +180,7 @@ func (s *Client) Visualize() {
|
||||
|
||||
err := termbox.Flush()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
case <-s.Die:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user