From 24cf30ca83023a6b30f4a42fa6698b9e7d0da979 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Fri, 27 Sep 2013 00:04:25 -0700 Subject: [PATCH] added flags for server and botname --- main.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 2881bb6..da3201e 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,9 @@ var hp = flag.Int("hp", 150, "") var speed = flag.Float64("speed", 150, "") var weaponRadius = flag.Int("wrad", 100, "weapon radius") var scannerRadius = flag.Int("srad", 100, "scanner radius") +var server = 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") type infos struct { id string @@ -25,7 +28,7 @@ type infos struct { func connect() (*websocket.Conn, error) { origin := "http://localhost/" - url := "ws://localhost:8666/ws/" + url := fmt.Sprintf("ws://%s:%d/ws/", *server, *port) return websocket.Dial(url, "", origin) } @@ -62,7 +65,7 @@ func negociate(ws *websocket.Conn, gameid string) (i *infos, err error) { log.Printf("%+v", idreq) err = websocket.JSON.Send(ws, bot.ClientID{ - Name: "smcquay test robot 2", + Name: *botname, Useragent: "gobot", Type: "robot", }) @@ -79,8 +82,9 @@ func negociate(ws *websocket.Conn, gameid string) (i *infos, err error) { log.Printf("%+v", gameparam) err = websocket.JSON.Send(ws, &bot.Config{ - gameid, - bot.Stats{ + ID: gameid, + Name: *botname, + Stats: bot.Stats{ Hp: *hp, Speed: *speed, WeaponRadius: *weaponRadius, @@ -123,6 +127,7 @@ func main() { log.Fatal(err) } + // TODO: var target govector.Point2d moveto := govector.Point2d{ X: rand.Float64() * board_info.width, Y: rand.Float64() * board_info.height, @@ -131,6 +136,7 @@ func main() { var me bot.Robot + log.Printf("negociated well, starting loop") for { var boardstate bot.Boardstate err = websocket.JSON.Receive(ws, &boardstate) @@ -144,9 +150,7 @@ func main() { } } log.Printf("%+v: %+v", me.Position, moveto) - // come up with new location if I am there if govector.Distance(me.Position, moveto) < 3.0 { - log.Println("finally got there") moveto = govector.Point2d{ X: rand.Float64() * board_info.width, Y: rand.Float64() * board_info.height, @@ -154,6 +158,7 @@ func main() { } // TODO: send instructions + log.Printf("%+v: %+v", me.Position, moveto) err = websocket.JSON.Send(ws, bot.Instruction{ MoveTo: &moveto, })