don't rename package without need.

This commit is contained in:
Stephen McQuay 2014-04-23 14:54:30 -07:00
parent b63780c2bc
commit bbfb2af4a9
3 changed files with 32 additions and 32 deletions

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"log" "log"
hbserver "bitbucket.org/hackerbots/server" "bitbucket.org/hackerbots/server"
"code.google.com/p/go.net/websocket" "code.google.com/p/go.net/websocket"
) )
@ -26,12 +26,12 @@ type Client struct {
Name string Name string
Port int Port int
Server string Server string
StatsReq hbserver.StatsRequest StatsReq server.StatsRequest
Verbose bool Verbose bool
Player Player Player Player
Game hbserver.GameParam Game server.GameParam
boardstate hbserver.Boardstate boardstate server.Boardstate
enc encoder enc encoder
dec decoder dec decoder
ws *websocket.Conn ws *websocket.Conn
@ -114,9 +114,9 @@ func (c *Client) Negociate() (err error) {
c.dec = gob.NewDecoder(c.ws) c.dec = gob.NewDecoder(c.ws)
} }
conf := hbserver.ClientConfig{ conf := server.ClientConfig{
ID: c.GameId, ID: c.GameId,
Stats: map[string]hbserver.StatsRequest{ Stats: map[string]server.StatsRequest{
c.Name: c.StatsReq, c.Name: c.StatsReq,
}, },
} }
@ -127,7 +127,7 @@ func (c *Client) Negociate() (err error) {
Id string `json:"id"` Id string `json:"id"`
Success bool `json:"success"` Success bool `json:"success"`
Type string `json:"type"` Type string `json:"type"`
hbserver.Failure server.Failure
} }
websocket.JSON.Receive(c.ws, &handshake) websocket.JSON.Receive(c.ws, &handshake)
if !handshake.Success { if !handshake.Success {
@ -140,7 +140,7 @@ func (c *Client) Negociate() (err error) {
// we don't do anything useful with dstats, but could be interesting to // we don't do anything useful with dstats, but could be interesting to
// pass along to the player? // pass along to the player?
dstats := struct { dstats := struct {
Stats map[string]hbserver.Stats `json:"stats"` Stats map[string]server.Stats `json:"stats"`
Type string `json:"type"` Type string `json:"type"`
}{} }{}
err = websocket.JSON.Receive(c.ws, &dstats) err = websocket.JSON.Receive(c.ws, &dstats)
@ -151,7 +151,7 @@ func (c *Client) Negociate() (err error) {
return nil return nil
} }
// Play contains the main game run loop. It gets a hbserver.Boardstate from the // Play contains the main game run loop. It gets a server.Boardstate from the
// server, and passes this along to the embedded Player. Following this it // server, and passes this along to the embedded Player. Following this it
// sends the server the Player's instruction. // sends the server the Player's instruction.
func (c *Client) Play() error { func (c *Client) Play() error {

View File

@ -6,8 +6,8 @@ import (
"math/rand" "math/rand"
"time" "time"
hbclient "bitbucket.org/hackerbots/client" "bitbucket.org/hackerbots/client"
hbserver "bitbucket.org/hackerbots/server" "bitbucket.org/hackerbots/server"
) )
var hp = flag.Int("hp", 50, "") var hp = flag.Int("hp", 50, "")
@ -22,7 +22,7 @@ var weaponSpeed = flag.Int("wspeed", 50, "weapons speed")
// XXX: add TurnSpeed, WeaponDamage, WeaponSpeed // XXX: add TurnSpeed, WeaponDamage, WeaponSpeed
var server = flag.String("server", "localhost", "server hostname") var serverHostname = flag.String("server", "localhost", "server hostname")
var port = flag.Int("port", 8666, "server port") 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 verbose = flag.Bool("verbose", false, "run verbosly") var verbose = flag.Bool("verbose", false, "run verbosly")
@ -39,13 +39,13 @@ func main() {
gameId = flag.Arg(0) gameId = flag.Arg(0)
} }
c := &hbclient.Client{ c := &client.Client{
Server: *server, Server: *serverHostname,
Port: *port, Port: *port,
Name: *botname, Name: *botname,
GameId: gameId, GameId: gameId,
// XXX: update with missing fields // XXX: update with missing fields
StatsReq: hbserver.StatsRequest{ StatsReq: server.StatsRequest{
Hp: *hp, Hp: *hp,
Speed: *speed, Speed: *speed,
Acceleration: *acceleration, Acceleration: *acceleration,
@ -65,7 +65,7 @@ func main() {
log.Fatal("%s: failed to negociate: %s", c.Name, err) log.Fatal("%s: failed to negociate: %s", c.Name, err)
} }
c.Player = hbclient.NewSimplePlayer( c.Player = client.NewSimplePlayer(
c.Game.BoardSize.Width, c.Game.BoardSize.Width,
c.Game.BoardSize.Height, c.Game.BoardSize.Height,
) )

View File

@ -5,7 +5,7 @@ import (
"math" "math"
"math/rand" "math/rand"
hbserver "bitbucket.org/hackerbots/server" "bitbucket.org/hackerbots/server"
"bitbucket.org/hackerbots/vector" "bitbucket.org/hackerbots/vector"
) )
@ -15,17 +15,17 @@ import (
// The general case will be to implement a Player type that contains the magic // 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. // required to slay other robots quickly while staying alive for a long time.
type Player interface { type Player interface {
Recv(bs *hbserver.Boardstate) Recv(bs *server.Boardstate)
Instruction() map[string]hbserver.Instruction Instruction() map[string]server.Instruction
} }
// SimplePlayer is our default player and stands as a starting point for your // SimplePlayer is our default player and stands as a starting point for your
// own Player implementations. // own Player implementations.
type SimplePlayer struct { type SimplePlayer struct {
me hbserver.Robot me server.Robot
width, height float32 width, height float32
knownObstacles map[string]hbserver.Obstacle knownObstacles map[string]server.Obstacle
nearestEnemy *hbserver.OtherRobot nearestEnemy *server.OtherRobot
fireat *vector.Point2d fireat *vector.Point2d
moveto *vector.Point2d moveto *vector.Point2d
speed float32 speed float32
@ -36,7 +36,7 @@ type SimplePlayer struct {
// NewSimplePlayer simply returns a populated, usable *SimplePlayer // NewSimplePlayer simply returns a populated, usable *SimplePlayer
func NewSimplePlayer(width, height float32) *SimplePlayer { func NewSimplePlayer(width, height float32) *SimplePlayer {
return &SimplePlayer{ return &SimplePlayer{
knownObstacles: make(map[string]hbserver.Obstacle), knownObstacles: make(map[string]server.Obstacle),
width: width, width: width,
height: height, height: height,
maxSpeed: 100, maxSpeed: 100,
@ -44,8 +44,8 @@ func NewSimplePlayer(width, height float32) *SimplePlayer {
} }
} }
// Recv is our implementation of receiving a hbserver.Boardstate from the server // Recv is our implementation of receiving a server.Boardstate from the server
func (p *SimplePlayer) Recv(bs *hbserver.Boardstate) { func (p *SimplePlayer) Recv(bs *server.Boardstate) {
p.speed = p.maxSpeed p.speed = p.maxSpeed
if len(bs.MyRobots) > 0 { if len(bs.MyRobots) > 0 {
p.me = bs.MyRobots[0] p.me = bs.MyRobots[0]
@ -81,7 +81,7 @@ func (p *SimplePlayer) navigate() {
} }
} }
func (p *SimplePlayer) recon(bs *hbserver.Boardstate) { func (p *SimplePlayer) recon(bs *server.Boardstate) {
for _, o := range bs.Objects { for _, o := range bs.Objects {
obj := MiniObstacle(o) obj := MiniObstacle(o)
if _, ok := p.knownObstacles[obj.Id()]; !ok { if _, ok := p.knownObstacles[obj.Id()]; !ok {
@ -109,8 +109,8 @@ func (p *SimplePlayer) recon(bs *hbserver.Boardstate) {
// Instruction is our default implementation of preparing a map of information // Instruction is our default implementation of preparing a map of information
// to be sent to server. // to be sent to server.
func (p *SimplePlayer) Instruction() map[string]hbserver.Instruction { func (p *SimplePlayer) Instruction() map[string]server.Instruction {
return map[string]hbserver.Instruction{ return map[string]server.Instruction{
p.me.Id: { p.me.Id: {
MoveTo: p.moveto, MoveTo: p.moveto,
TargetSpeed: &p.speed, TargetSpeed: &p.speed,
@ -142,7 +142,7 @@ func (p *SimplePlayer) probe(destination vector.Point2d) bool {
return true return true
} }
// MiniObstacle is a convenient way to encode/decode between the [4]int -> hbserver.Obstacle // MiniObstacle is a convenient way to encode/decode between the [4]int -> server.Obstacle
type MiniObstacle [4]int type MiniObstacle [4]int
// id is used to calculate a key for use in maps // id is used to calculate a key for use in maps
@ -161,8 +161,8 @@ func (mo MiniObstacle) String() string {
} }
// ToObstacle is where the conversion magic happens // ToObstacle is where the conversion magic happens
func (mo *MiniObstacle) ToObstacle() hbserver.Obstacle { func (mo *MiniObstacle) ToObstacle() server.Obstacle {
return hbserver.Obstacle{ return server.Obstacle{
Bounds: vector.AABB2d{ Bounds: vector.AABB2d{
A: vector.Point2d{float32(mo[0]), float32(mo[1])}, A: vector.Point2d{float32(mo[0]), float32(mo[1])},
B: vector.Point2d{float32(mo[2]), float32(mo[3])}, B: vector.Point2d{float32(mo[2]), float32(mo[3])},