added multi-bot spinup

This commit is contained in:
Stephen McQuay 2013-11-10 23:32:12 -08:00
parent 5f6ad59303
commit 5361cc276e

40
main.go
View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"log" "log"
"math/rand" "math/rand"
"sync"
"time" "time"
) )
@ -21,11 +22,12 @@ var port = flag.Int("port", 8666, "server port")
var botname = flag.String("name", "gobot", "the name that other players will see") 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 verbose = flag.Bool("verbose", false, "run verbosly")
func main() { func main() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
var err error
var gameName string var gameName string
flag.Parse() flag.Parse()
if flag.NArg() < 1 { if flag.NArg() < 1 {
@ -34,20 +36,26 @@ func main() {
gameName = flag.Arg(0) gameName = flag.Arg(0)
} }
// XXX: add TurnSpeed, WeaponDamage, WeaponSpeed // XXX: add TurnSpeed, WeaponDamage, WeaponSpeed
r, err := NewRobot( var wg sync.WaitGroup
*server,
*port, for i := 0; i < *botcount; i++ {
gameName, r, err := NewRobot(
*hp, *server,
*speed, *port,
*acceleration, gameName,
*weaponRadius, *hp,
*scannerRadius, *speed,
*fireRate, *acceleration,
) *weaponRadius,
if err != nil { *scannerRadius,
log.Fatal(err) *fireRate,
)
if err != nil {
log.Fatal(err)
}
log.Printf("my robot: %+v", r)
go r.play()
wg.Add(1)
} }
log.Printf("%+v", r) wg.Wait()
r.play()
} }