client/gobot/main.go

77 lines
1.9 KiB
Go
Raw Normal View History

package main
import (
"flag"
2014-01-06 23:33:06 -08:00
"log"
2013-09-20 11:16:11 -07:00
"math/rand"
2013-09-28 13:10:25 -07:00
"time"
2014-04-23 14:54:30 -07:00
"bitbucket.org/hackerbots/client"
"bitbucket.org/hackerbots/server"
)
2013-10-19 00:30:20 -07:00
var hp = flag.Int("hp", 50, "")
2013-11-10 21:24:41 -08:00
var speed = flag.Int("speed", 50, "")
var acceleration = flag.Int("acceleration", 50, "")
2013-10-19 00:30:20 -07:00
var scannerRadius = flag.Int("srad", 50, "scanner radius")
2013-11-11 00:24:11 -08:00
var turnSpeed = flag.Int("omega", 50, "turn speed")
2013-10-19 00:30:20 -07:00
var fireRate = flag.Int("fire-rate", 50, "scanner radius")
2013-11-11 00:24:11 -08:00
var weaponRadius = flag.Int("wrad", 50, "weapon radius")
var weaponDamage = flag.Int("wdamage", 50, "weapons umph")
var weaponSpeed = flag.Int("wspeed", 50, "weapons speed")
2013-10-19 00:30:20 -07:00
2013-11-10 23:30:23 -08:00
// XXX: add TurnSpeed, WeaponDamage, WeaponSpeed
2014-04-23 14:54:30 -07:00
var serverHostname = flag.String("server", "localhost", "server hostname")
2013-09-27 00:04:25 -07:00
var port = flag.Int("port", 8666, "server port")
2013-11-10 23:30:23 -08:00
var botname = flag.String("name", "gobot", "the name that other players will see")
var verbose = flag.Bool("verbose", false, "run verbosly")
2014-03-11 07:30:05 -07:00
var forceJSON = flag.Bool("json", false, "force json encoding")
func main() {
2014-01-06 23:33:06 -08:00
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
2013-09-28 13:10:25 -07:00
rand.Seed(time.Now().UnixNano())
2014-04-09 21:35:54 -07:00
var gameId string
flag.Parse()
if flag.NArg() < 1 {
2014-04-09 21:35:54 -07:00
gameId = "debug"
} else {
2014-04-09 21:35:54 -07:00
gameId = flag.Arg(0)
2013-11-10 23:30:23 -08:00
}
2013-11-10 23:32:12 -08:00
2014-04-23 14:54:30 -07:00
c := &client.Client{
Server: *serverHostname,
2014-04-09 21:35:54 -07:00
Port: *port,
Name: *botname,
GameId: gameId,
// XXX: update with missing fields
2014-04-23 14:54:30 -07:00
StatsReq: server.StatsRequest{
2014-04-09 21:35:54 -07:00
Hp: *hp,
Speed: *speed,
Acceleration: *acceleration,
ScannerRadius: *scannerRadius,
TurnSpeed: *turnSpeed,
FireRate: *fireRate,
WeaponRadius: *weaponRadius,
WeaponDamage: *weaponDamage,
WeaponSpeed: *weaponSpeed,
},
Verbose: *verbose,
ForceJSON: *forceJSON,
}
var err error
err = c.Negociate("robot")
2014-04-09 21:35:54 -07:00
if err != nil {
2014-04-23 14:58:22 -07:00
log.Fatalf("%s: failed to negociate: %s", c.Name, err)
2014-04-09 21:35:54 -07:00
}
2014-04-23 14:54:30 -07:00
c.Player = client.NewSimplePlayer(
2014-04-09 21:35:54 -07:00
c.Game.BoardSize.Width,
c.Game.BoardSize.Height,
)
if err := c.Play(); err != nil {
log.Fatal(err)
}
}