Remove spurious logging

This commit is contained in:
Stephen McQuay 2015-08-31 21:55:18 -07:00
parent 3ef90af341
commit 623dfa4c48
4 changed files with 12 additions and 34 deletions

View File

@ -2,8 +2,9 @@ package main
import ( import (
"flag" "flag"
"log" "fmt"
"math/rand" "math/rand"
"os"
"time" "time"
"hackerbots.us/client" "hackerbots.us/client"
@ -12,11 +13,9 @@ import (
var serverHostname = flag.String("server", "localhost", "server hostname") var serverHostname = flag.String("server", "localhost", "server hostname")
var port = flag.Int("port", 8666, "server port") 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") var forceJSON = flag.Bool("json", false, "force json encoding")
func main() { func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
var gameId string var gameId string
flag.Parse() flag.Parse()
@ -31,7 +30,6 @@ func main() {
Port: *port, Port: *port,
Name: "bspect", Name: "bspect",
GameId: gameId, GameId: gameId,
Verbose: *verbose,
ForceJSON: *forceJSON, ForceJSON: *forceJSON,
StateStream: make(chan *server.Boardstate), StateStream: make(chan *server.Boardstate),
Die: make(chan struct{}), Die: make(chan struct{}),
@ -40,7 +38,8 @@ func main() {
var err error var err error
err = c.Negociate("spectator") err = c.Negociate("spectator")
if err != nil { 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() { go func() {

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log"
"golang.org/x/net/websocket" "golang.org/x/net/websocket"
@ -28,7 +27,6 @@ type Client struct {
Port int Port int
Server string Server string
StatsReq server.StatsRequest StatsReq server.StatsRequest
Verbose bool
Game server.GameParam Game server.GameParam
boardstate *server.Boardstate boardstate *server.Boardstate
@ -55,9 +53,6 @@ type decoder interface {
// Negociate runs through the hackerbots negociation protocol. // Negociate runs through the hackerbots negociation protocol.
func (c *Client) Negociate(clientType string) (err error) { 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) c.ws, err = connect(c.Server, c.Port)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("connection failure: %s", err)) 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" { if err != nil || idreq.Type == "failure" {
return errors.New(fmt.Sprintf("failure: %+v", idreq)) 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 { err = websocket.JSON.Send(c.ws, struct {
Type string `json:"type"` Type string `json:"type"`
@ -110,9 +102,6 @@ func (c *Client) Negociate(clientType string) (err error) {
if c.Game.Type != "gameparam" { if c.Game.Type != "gameparam" {
return errors.New("didn't receive a good 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" { if c.Game.Encoding == "json" {
c.enc = json.NewEncoder(c.ws) c.enc = json.NewEncoder(c.ws)
@ -130,9 +119,6 @@ func (c *Client) Negociate(clientType string) (err error) {
c.Name: c.StatsReq, c.Name: c.StatsReq,
}, },
} }
if c.Verbose {
log.Printf("%s: client config: %+v", c.Name, conf)
}
err = websocket.JSON.Send(c.ws, conf) err = websocket.JSON.Send(c.ws, conf)
@ -146,9 +132,6 @@ func (c *Client) Negociate(clientType string) (err error) {
if !handshake.Success { if !handshake.Success {
return errors.New(handshake.Reason) 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 // we don't do anything useful with dstats, but could be interesting to
// pass along to the player? // 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 // server, and passes this along to the embedded Player. Following this it
// sends the server the Player's instruction. // sends the server the Player's instruction.
func (c *Client) Play() error { func (c *Client) Play() error {
log.Printf("%s: starting loop", c.Name)
bs := &server.Boardstate{} bs := &server.Boardstate{}
var err error var err error
for { for {

View File

@ -2,8 +2,9 @@ package main
import ( import (
"flag" "flag"
"log" "fmt"
"math/rand" "math/rand"
"os"
"time" "time"
"hackerbots.us/client" "hackerbots.us/client"
@ -25,11 +26,9 @@ var weaponSpeed = flag.Int("wspeed", 50, "weapons speed")
var serverHostname = flag.String("server", "localhost", "server hostname") var serverHostname = flag.String("server", "localhost", "server hostname")
var port = flag.Int("port", 8666, "server port") var port = flag.Int("port", 8666, "server port")
var botname = flag.String("name", "gobot", "the name that other players will see") 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") var forceJSON = flag.Bool("json", false, "force json encoding")
func main() { func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
var gameId string var gameId string
flag.Parse() flag.Parse()
@ -56,7 +55,6 @@ func main() {
WeaponDamage: *weaponDamage, WeaponDamage: *weaponDamage,
WeaponSpeed: *weaponSpeed, WeaponSpeed: *weaponSpeed,
}, },
Verbose: *verbose,
ForceJSON: *forceJSON, ForceJSON: *forceJSON,
StateStream: make(chan *server.Boardstate), StateStream: make(chan *server.Boardstate),
Die: make(chan struct{}), Die: make(chan struct{}),
@ -66,7 +64,8 @@ func main() {
var err error var err error
err = c.Negociate("robot") err = c.Negociate("robot")
if err != nil { 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() { go func() {

View File

@ -1,7 +1,7 @@
package client package client
import ( import (
"log" "fmt"
"math" "math"
"github.com/nsf/termbox-go" "github.com/nsf/termbox-go"
@ -27,7 +27,7 @@ func (s *Client) Recv(bs *server.Boardstate) map[string]server.Instruction {
func (s *Client) Visualize() { func (s *Client) Visualize() {
err := termbox.Init() err := termbox.Init()
if err != nil { if err != nil {
log.Fatal(err) panic(err)
} }
s.viewX, s.viewY = termbox.Size() s.viewX, s.viewY = termbox.Size()
@ -50,7 +50,6 @@ func (s *Client) Visualize() {
case termbox.EventKey: case termbox.EventKey:
switch event.Key { switch event.Key {
case termbox.KeyCtrlZ, termbox.KeyCtrlC: case termbox.KeyCtrlZ, termbox.KeyCtrlC:
log.Printf("exiting ...")
return return
} }
@ -64,7 +63,7 @@ func (s *Client) Visualize() {
case termbox.EventResize: case termbox.EventResize:
s.viewX, s.viewY = event.Width, event.Height s.viewX, s.viewY = event.Width, event.Height
case termbox.EventError: 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: case u := <-s.StateStream:
termbox.Clear(termbox.ColorBlack, termbox.ColorBlack) termbox.Clear(termbox.ColorBlack, termbox.ColorBlack)
@ -181,7 +180,7 @@ func (s *Client) Visualize() {
err := termbox.Flush() err := termbox.Flush()
if err != nil { if err != nil {
log.Fatal(err) panic(err)
} }
case <-s.Die: case <-s.Die:
return return