From e4bbd4a0f491fd2b0e51d8c595c9cbca4788efd0 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sun, 10 Nov 2013 23:37:43 -0800 Subject: [PATCH] give unique r.name for each robot --- main.go | 2 ++ robot.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1346637..8370130 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "log" "math/rand" "sync" @@ -43,6 +44,7 @@ func main() { *server, *port, gameName, + fmt.Sprintf("%s%d", *botname, i), *hp, *speed, *acceleration, diff --git a/robot.go b/robot.go index 9746bbf..9e12dae 100644 --- a/robot.go +++ b/robot.go @@ -19,12 +19,14 @@ type robot struct { ws *websocket.Conn game GameParam playerId string + name string } func NewRobot( server string, port int, gameName string, + botName string, hp, speed, acceleration, @@ -36,7 +38,8 @@ func NewRobot( return nil, errors.New(fmt.Sprintf("connection failure: %s", err)) } r := &robot{ - ws: ws, + ws: ws, + name: botName, } // XXX: update with missing fields @@ -84,7 +87,7 @@ func (r *robot) negociate(req StatsRequest, gameName string) (err error) { Name string `json:"name"` Useragent string `json:"useragent"` }{ - Name: *botname, + Name: r.name, Useragent: "gobot", Type: "robot", }) @@ -101,7 +104,7 @@ func (r *robot) negociate(req StatsRequest, gameName string) (err error) { conf := ClientConfig{ ID: gameName, Stats: map[string]StatsRequest{ - *botname: req, + r.name: req, }, }