added flags for server and botname

This commit is contained in:
Stephen McQuay 2013-09-27 00:04:25 -07:00
parent 476e2a3ff8
commit 24cf30ca83
1 changed files with 11 additions and 6 deletions

17
main.go
View File

@ -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,
})