From 5361cc276e98431db6945e4bc056785bbcd93e20 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sun, 10 Nov 2013 23:32:12 -0800 Subject: [PATCH] added multi-bot spinup --- main.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 6e050cd..1346637 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "log" "math/rand" + "sync" "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 botcount = flag.Int("bots", 1, "number of bots to spin up") + var verbose = flag.Bool("verbose", false, "run verbosly") func main() { rand.Seed(time.Now().UnixNano()) - var err error var gameName string flag.Parse() if flag.NArg() < 1 { @@ -34,20 +36,26 @@ func main() { gameName = flag.Arg(0) } // XXX: add TurnSpeed, WeaponDamage, WeaponSpeed - r, err := NewRobot( - *server, - *port, - gameName, - *hp, - *speed, - *acceleration, - *weaponRadius, - *scannerRadius, - *fireRate, - ) - if err != nil { - log.Fatal(err) + var wg sync.WaitGroup + + for i := 0; i < *botcount; i++ { + r, err := NewRobot( + *server, + *port, + gameName, + *hp, + *speed, + *acceleration, + *weaponRadius, + *scannerRadius, + *fireRate, + ) + if err != nil { + log.Fatal(err) + } + log.Printf("my robot: %+v", r) + go r.play() + wg.Add(1) } - log.Printf("%+v", r) - r.play() + wg.Wait() }