From 51d05228336db399ccce3d39b58e58d081c8b5aa Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Wed, 23 Apr 2014 14:28:06 -0700 Subject: [PATCH] renamed package/directory --- client.go | 22 +++++++++++----------- doc.go | 4 ++-- gobot/main.go | 10 +++++----- player.go | 50 +++++++++++++++++++++++++------------------------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/client.go b/client.go index ca5d329..641b0ca 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -package botclient +package client import ( "encoding/gob" @@ -7,7 +7,7 @@ import ( "fmt" "log" - "bitbucket.org/hackerbots/botserv" + hbserver "bitbucket.org/hackerbots/server" "code.google.com/p/go.net/websocket" ) @@ -26,12 +26,12 @@ type Client struct { Name string Port int Server string - StatsReq botserv.StatsRequest + StatsReq hbserver.StatsRequest Verbose bool Player Player - Game botserv.GameParam + Game hbserver.GameParam - boardstate botserv.Boardstate + boardstate hbserver.Boardstate enc encoder dec decoder ws *websocket.Conn @@ -114,9 +114,9 @@ func (c *Client) Negociate() (err error) { c.dec = gob.NewDecoder(c.ws) } - conf := botserv.ClientConfig{ + conf := hbserver.ClientConfig{ ID: c.GameId, - Stats: map[string]botserv.StatsRequest{ + Stats: map[string]hbserver.StatsRequest{ c.Name: c.StatsReq, }, } @@ -127,7 +127,7 @@ func (c *Client) Negociate() (err error) { Id string `json:"id"` Success bool `json:"success"` Type string `json:"type"` - botserv.Failure + hbserver.Failure } websocket.JSON.Receive(c.ws, &handshake) if !handshake.Success { @@ -140,8 +140,8 @@ func (c *Client) Negociate() (err error) { // we don't do anything useful with dstats, but could be interesting to // pass along to the player? dstats := struct { - Stats map[string]botserv.Stats `json:"stats"` - Type string `json:"type"` + Stats map[string]hbserver.Stats `json:"stats"` + Type string `json:"type"` }{} err = websocket.JSON.Receive(c.ws, &dstats) if err != nil { @@ -151,7 +151,7 @@ func (c *Client) Negociate() (err error) { return nil } -// Play contains the main game run loop. It gets a botserv.Boardstate from the +// Play contains the main game run loop. It gets a hbserver.Boardstate from the // server, and passes this along to the embedded Player. Following this it // sends the server the Player's instruction. func (c *Client) Play() error { diff --git a/doc.go b/doc.go index 2c890e4..599b5b9 100644 --- a/doc.go +++ b/doc.go @@ -1,2 +1,2 @@ -// botclient is a package used to connect to and interact with a hackebots game. -package botclient +// client is a package used to connect to and interact with a hackebots game. +package client diff --git a/gobot/main.go b/gobot/main.go index 8f1fcdc..2c157d3 100644 --- a/gobot/main.go +++ b/gobot/main.go @@ -6,8 +6,8 @@ import ( "math/rand" "time" - "bitbucket.org/hackerbots/botclient" - "bitbucket.org/hackerbots/botserv" + hbclient "bitbucket.org/hackerbots/client" + hbserver "bitbucket.org/hackerbots/server" ) var hp = flag.Int("hp", 50, "") @@ -39,13 +39,13 @@ func main() { gameId = flag.Arg(0) } - c := &botclient.Client{ + c := &hbclient.Client{ Server: *server, Port: *port, Name: *botname, GameId: gameId, // XXX: update with missing fields - StatsReq: botserv.StatsRequest{ + StatsReq: hbserver.StatsRequest{ Hp: *hp, Speed: *speed, Acceleration: *acceleration, @@ -65,7 +65,7 @@ func main() { log.Printf("%s: failed to negociate: %s", c.Name, err) } - c.Player = botclient.NewSimplePlayer( + c.Player = hbclient.NewSimplePlayer( c.Game.BoardSize.Width, c.Game.BoardSize.Height, ) diff --git a/player.go b/player.go index 247c3d1..9206bf1 100644 --- a/player.go +++ b/player.go @@ -1,11 +1,11 @@ -package botclient +package client import ( "fmt" "math" "math/rand" - "bitbucket.org/hackerbots/botserv" + hbserver "bitbucket.org/hackerbots/server" "bitbucket.org/hackerbots/vector" ) @@ -15,19 +15,19 @@ import ( // The general case will be to implement a Player type that contains the magic // required to slay other robots quickly while staying alive for a long time. type Player interface { - Recv(bs *botserv.Boardstate) - Instruction() map[string]botserv.Instruction + Recv(bs *hbserver.Boardstate) + Instruction() map[string]hbserver.Instruction } // SimplePlayer is our default player and stands as a starting point for your // own Player implementations. type SimplePlayer struct { - me botserv.Robot + me hbserver.Robot width, height float32 - knownObstacles map[string]botserv.Obstacle - nearestEnemy *botserv.OtherRobot - fireat *govector.Point2d - moveto *govector.Point2d + knownObstacles map[string]hbserver.Obstacle + nearestEnemy *hbserver.OtherRobot + fireat *vector.Point2d + moveto *vector.Point2d speed float32 maxSpeed float32 safeDistance float32 @@ -36,7 +36,7 @@ type SimplePlayer struct { // NewSimplePlayer simply returns a populated, usable *SimplePlayer func NewSimplePlayer(width, height float32) *SimplePlayer { return &SimplePlayer{ - knownObstacles: make(map[string]botserv.Obstacle), + knownObstacles: make(map[string]hbserver.Obstacle), width: width, height: height, maxSpeed: 100, @@ -44,8 +44,8 @@ func NewSimplePlayer(width, height float32) *SimplePlayer { } } -// Recv is our implementation of receiving a botserv.Boardstate from the server -func (p *SimplePlayer) Recv(bs *botserv.Boardstate) { +// Recv is our implementation of receiving a hbserver.Boardstate from the server +func (p *SimplePlayer) Recv(bs *hbserver.Boardstate) { p.speed = p.maxSpeed if len(bs.MyRobots) > 0 { p.me = bs.MyRobots[0] @@ -81,7 +81,7 @@ func (p *SimplePlayer) navigate() { } } -func (p *SimplePlayer) recon(bs *botserv.Boardstate) { +func (p *SimplePlayer) recon(bs *hbserver.Boardstate) { for _, o := range bs.Objects { obj := MiniObstacle(o) if _, ok := p.knownObstacles[obj.Id()]; !ok { @@ -109,8 +109,8 @@ func (p *SimplePlayer) recon(bs *botserv.Boardstate) { // Instruction is our default implementation of preparing a map of information // to be sent to server. -func (p *SimplePlayer) Instruction() map[string]botserv.Instruction { - return map[string]botserv.Instruction{ +func (p *SimplePlayer) Instruction() map[string]hbserver.Instruction { + return map[string]hbserver.Instruction{ p.me.Id: { MoveTo: p.moveto, TargetSpeed: &p.speed, @@ -119,18 +119,18 @@ func (p *SimplePlayer) Instruction() map[string]botserv.Instruction { } } -func (p *SimplePlayer) randomDirection() *govector.Point2d { - pt := govector.Vector2d{ +func (p *SimplePlayer) randomDirection() *vector.Point2d { + pt := vector.Vector2d{ X: rand.Float32() * p.width, Y: rand.Float32() * p.height, }.ToPoint() return &pt } -func (p *SimplePlayer) probe(destination govector.Point2d) bool { +func (p *SimplePlayer) probe(destination vector.Point2d) bool { // XXX: make test for this for _, v := range p.knownObstacles { - collided, _, _ := govector.RectIntersection( + collided, _, _ := vector.RectIntersection( v.Bounds, p.me.Position, destination.Sub(p.me.Position), @@ -142,7 +142,7 @@ func (p *SimplePlayer) probe(destination govector.Point2d) bool { return true } -// MiniObstacle is a convenient way to encode/decode between the [4]int -> botserv.Obstacle +// MiniObstacle is a convenient way to encode/decode between the [4]int -> hbserver.Obstacle type MiniObstacle [4]int // id is used to calculate a key for use in maps @@ -161,11 +161,11 @@ func (mo MiniObstacle) String() string { } // ToObstacle is where the conversion magic happens -func (mo *MiniObstacle) ToObstacle() botserv.Obstacle { - return botserv.Obstacle{ - Bounds: govector.AABB2d{ - A: govector.Point2d{float32(mo[0]), float32(mo[1])}, - B: govector.Point2d{float32(mo[2]), float32(mo[3])}, +func (mo *MiniObstacle) ToObstacle() hbserver.Obstacle { + return hbserver.Obstacle{ + Bounds: vector.AABB2d{ + A: vector.Point2d{float32(mo[0]), float32(mo[1])}, + B: vector.Point2d{float32(mo[2]), float32(mo[3])}, }, } }