refactor for bot

This commit is contained in:
sm
2013-09-03 23:26:40 -07:00
parent 835303c53d
commit b495b16065
7 changed files with 121 additions and 249 deletions
+12 -12
View File
@@ -1,6 +1,7 @@
package main
import (
"bitbucket.org/hackerbots/bot"
v "bitbucket.org/hackerbots/vector"
"code.google.com/p/go.net/websocket"
"log"
@@ -9,15 +10,16 @@ import (
type player struct {
ws *websocket.Conn
Robot robot
send chan *boardstate
game *game
Robot bot.Robot
send chan *bot.Boardstate
Instruction instruction
}
type instruction struct {
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Stats stats `json:"stats"`
Stats bot.Stats `json:"stats"`
}
func (p *player) sender() {
@@ -60,14 +62,14 @@ func (p *player) nudge() {
}
func (p *player) scan() {
p.Robot.Scanners = make([]scanner, 0)
for player := range g.players {
p.Robot.Scanners = make([]bot.Scanner, 0)
for player := range p.game.players {
if player.Robot.Id == p.Robot.Id || player.Robot.Health <= 0 {
continue
}
dist := distance(player.Robot.Position, p.Robot.Position)
if dist < float64(p.Robot.Stats.ScannerRadius) {
s := scanner{
s := bot.Scanner{
Position: v.Point2d{
X: player.Robot.Position.X,
Y: player.Robot.Position.Y,
@@ -78,15 +80,14 @@ func (p *player) scan() {
}
}
func (p *player) fire() {
for proj := range g.projectiles {
func (p *player) fire() *bot.Projectile {
for proj := range p.game.projectiles {
if proj.Id == p.Robot.Id {
return
return nil
}
}
proj := &projectile{
return &bot.Projectile{
Id: p.Robot.Id,
Position: p.Robot.Position,
MoveTo: p.Robot.FireAt,
@@ -94,7 +95,6 @@ func (p *player) fire() {
Radius: p.Robot.Stats.WeaponRadius,
Speed: float64(p.Robot.Stats.Speed * 2),
}
g.projectiles[proj] = true
}
func (p *player) reset() {