added per-bot info to the logs

This commit is contained in:
Stephen McQuay 2013-11-11 00:25:02 -08:00
parent 46947bb4b3
commit 2fb7ff7b20

View File

@ -26,7 +26,7 @@ type robot struct {
}
func (r *robot) negociate() (err error) {
log.Printf("trying to connect to game '%s'", r.game.name)
log.Printf("%s: trying to connect to game '%s'", r.name, r.game.name)
r.ws, err = connect(r.server, r.port)
if err != nil {
return errors.New(fmt.Sprintf("connection failure: %s", err))
@ -49,7 +49,7 @@ func (r *robot) negociate() (err error) {
if err != nil || idreq.Type == "failure" {
return errors.New(fmt.Sprintf("failure: %+v", idreq))
}
log.Printf("idreq: %+v", idreq)
log.Printf("%s: idreq: %+v", r.name, idreq)
err = websocket.JSON.Send(r.ws, struct {
Type string `json:"type"`
@ -67,7 +67,7 @@ func (r *robot) negociate() (err error) {
if r.game.Type != "gameparam" {
return errors.New("didn't receive a good gameparam")
}
log.Printf("game parameters: %+v", r.game)
log.Printf("%s: game parameters: %+v", r.name, r.game)
conf := ClientConfig{
ID: r.game.name,
@ -88,7 +88,7 @@ func (r *robot) negociate() (err error) {
return errors.New("failed to validate correct stats request")
}
r.playerId = handshake.Id
log.Printf("handshake: %+v", handshake)
log.Printf("%s: handshake: %+v", r.name, handshake)
return nil
}
@ -96,20 +96,18 @@ func (r *robot) play() {
var err error
err = r.negociate()
if err != nil {
log.Fatal("failed to negociate:", err)
log.Printf("%s: failed to negociate: %s", r.name, err)
return
}
log.Printf("me: %+v", r)
log.Printf("%s: %+v", r.name, r)
// TODO: var target govector.Point2d
moveto := govector.Point2d{
X: rand.Float32() * r.game.BoardSize.Width,
Y: rand.Float32() * r.game.BoardSize.Height,
}
log.Printf("moveto: %+v", moveto)
var me Robot
log.Printf("%s: starting loop", r.playerId)
log.Printf("%s: moveto: %+v", r.name, moveto)
log.Printf("%s: starting loop", r.name)
for {
var boardstate Boardstate
err = websocket.JSON.Receive(r.ws, &boardstate)
@ -117,7 +115,8 @@ func (r *robot) play() {
log.Printf("%+v", boardstate)
}
if err != nil {
log.Fatal("Connection lost")
log.Printf("%s: Connection lost", r.name)
return
}
me = boardstate.MyRobots[0]
if govector.Distance(me.Position, moveto) < 3.0 {