prep code for reuse
This commit is contained in:
+36
-34
@@ -2,10 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/hackerbots/botclient"
|
||||
@@ -26,49 +24,53 @@ var weaponSpeed = flag.Int("wspeed", 50, "weapons speed")
|
||||
|
||||
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")
|
||||
|
||||
var botcount = flag.Int("bots", 1, "number of bots to spin up")
|
||||
|
||||
var verbose = flag.Bool("verbose", false, "run verbosly")
|
||||
var forceJSON = flag.Bool("json", false, "force json encoding")
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var gameName string
|
||||
var gameId string
|
||||
flag.Parse()
|
||||
if flag.NArg() < 1 {
|
||||
gameName = "debug"
|
||||
gameId = "debug"
|
||||
} else {
|
||||
gameName = flag.Arg(0)
|
||||
gameId = flag.Arg(0)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < *botcount; i++ {
|
||||
r := &botclient.Robot{
|
||||
Server: *server,
|
||||
Port: *port,
|
||||
Name: fmt.Sprintf("%s%d", *botname, i),
|
||||
GameName: gameName,
|
||||
// XXX: update with missing fields
|
||||
StatsReq: botserv.StatsRequest{
|
||||
Hp: *hp,
|
||||
Speed: *speed,
|
||||
Acceleration: *acceleration,
|
||||
ScannerRadius: *scannerRadius,
|
||||
TurnSpeed: *turnSpeed,
|
||||
FireRate: *fireRate,
|
||||
WeaponRadius: *weaponRadius,
|
||||
WeaponDamage: *weaponDamage,
|
||||
WeaponSpeed: *weaponSpeed,
|
||||
},
|
||||
Wg: &wg,
|
||||
KnownObstacles: make(map[string]botserv.Obstacle),
|
||||
}
|
||||
wg.Add(1)
|
||||
go r.Play()
|
||||
c := &botclient.Client{
|
||||
Server: *server,
|
||||
Port: *port,
|
||||
Name: *botname,
|
||||
GameId: gameId,
|
||||
// XXX: update with missing fields
|
||||
StatsReq: botserv.StatsRequest{
|
||||
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()
|
||||
if err != nil {
|
||||
log.Printf("%s: failed to negociate: %s", c.Name, err)
|
||||
}
|
||||
|
||||
c.Player = botclient.NewSimplePlayer(
|
||||
c.Game.BoardSize.Width,
|
||||
c.Game.BoardSize.Height,
|
||||
)
|
||||
|
||||
if err := c.Play(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user