client/cmd/gobot/main.go

86 lines
2.0 KiB
Go
Raw Normal View History

package main
import (
"flag"
2015-08-31 21:55:18 -07:00
"fmt"
2013-09-20 11:16:11 -07:00
"math/rand"
2015-08-31 21:55:18 -07:00
"os"
2013-09-28 13:10:25 -07:00
"time"
"hackerbots.us/client"
"hackerbots.us/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
var addr = flag.String("addr", "ws://localhost:8666", "server hostname")
2013-11-10 23:30:23 -08:00
var botname = flag.String("name", "gobot", "the name that other players will see")
2014-03-11 07:30:05 -07:00
var forceJSON = flag.Bool("json", false, "force json encoding")
var botType = flag.String("bot", "simple", "which Bot")
func main() {
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: *addr,
2014-04-09 21:35:54 -07:00
Name: *botname,
GameId: gameId,
// XXX: update with missing fields
2015-08-31 21:48:25 -07:00
ForceJSON: *forceJSON,
StateStream: make(chan *server.Boardstate),
Die: make(chan struct{}),
}
2016-07-13 19:12:46 -07:00
sr := server.StatsRequest{
Hp: *hp,
Speed: *speed,
Acceleration: *acceleration,
ScannerRadius: *scannerRadius,
TurnSpeed: *turnSpeed,
FireRate: *fireRate,
WeaponRadius: *weaponRadius,
WeaponDamage: *weaponDamage,
WeaponSpeed: *weaponSpeed,
}
2015-08-31 21:48:25 -07:00
switch *botType {
case "simple":
2016-07-13 19:12:46 -07:00
c.Player = client.NewSimplePlayer(800, 600, sr)
case "fraserbot":
c.Player = client.NewFraserbot("Fraserbot")
2016-07-13 20:23:41 -07:00
default:
fmt.Fprintf(os.Stderr, "must specify a known bot \n")
os.Exit(1)
2014-04-09 21:35:54 -07:00
}
2014-04-09 21:35:54 -07:00
var err error
err = c.Negotiate("robot", c.Player)
2014-04-09 21:35:54 -07:00
if err != nil {
2015-08-31 21:55:18 -07:00
fmt.Fprintf(os.Stderr, "%s: failed to negociate: %s\n", c.Name, err)
os.Exit(1)
2014-04-09 21:35:54 -07:00
}
2015-08-31 21:48:25 -07:00
go func() {
if err := c.Play(); err != nil {
close(c.Die)
}
}()
c.Visualize()
}