give unique r.name for each robot

This commit is contained in:
Stephen McQuay 2013-11-10 23:37:43 -08:00
parent 5361cc276e
commit e4bbd4a0f4
2 changed files with 8 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"math/rand" "math/rand"
"sync" "sync"
@ -43,6 +44,7 @@ func main() {
*server, *server,
*port, *port,
gameName, gameName,
fmt.Sprintf("%s%d", *botname, i),
*hp, *hp,
*speed, *speed,
*acceleration, *acceleration,

View File

@ -19,12 +19,14 @@ type robot struct {
ws *websocket.Conn ws *websocket.Conn
game GameParam game GameParam
playerId string playerId string
name string
} }
func NewRobot( func NewRobot(
server string, server string,
port int, port int,
gameName string, gameName string,
botName string,
hp, hp,
speed, speed,
acceleration, acceleration,
@ -36,7 +38,8 @@ func NewRobot(
return nil, errors.New(fmt.Sprintf("connection failure: %s", err)) return nil, errors.New(fmt.Sprintf("connection failure: %s", err))
} }
r := &robot{ r := &robot{
ws: ws, ws: ws,
name: botName,
} }
// XXX: update with missing fields // XXX: update with missing fields
@ -84,7 +87,7 @@ func (r *robot) negociate(req StatsRequest, gameName string) (err error) {
Name string `json:"name"` Name string `json:"name"`
Useragent string `json:"useragent"` Useragent string `json:"useragent"`
}{ }{
Name: *botname, Name: r.name,
Useragent: "gobot", Useragent: "gobot",
Type: "robot", Type: "robot",
}) })
@ -101,7 +104,7 @@ func (r *robot) negociate(req StatsRequest, gameName string) (err error) {
conf := ClientConfig{ conf := ClientConfig{
ID: gameName, ID: gameName,
Stats: map[string]StatsRequest{ Stats: map[string]StatsRequest{
*botname: req, r.name: req,
}, },
} }