Update to new protocol (Update)
This commit is contained in:
@@ -14,8 +14,7 @@ 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 *server.Boardstate)
|
||||
Instruction() map[string]server.Instruction
|
||||
Update(bs *server.Boardstate) map[string]server.Instruction
|
||||
}
|
||||
|
||||
// SimplePlayer is our default player and stands as a starting point for your
|
||||
@@ -43,17 +42,32 @@ func NewSimplePlayer(width, height float64) *SimplePlayer {
|
||||
}
|
||||
}
|
||||
|
||||
// Recv is our implementation of receiving a server.Boardstate from the server
|
||||
func (p *SimplePlayer) Recv(bs *server.Boardstate) {
|
||||
p.speed = p.maxSpeed
|
||||
if len(bs.MyRobots) > 0 {
|
||||
p.me = bs.MyRobots[0]
|
||||
} else {
|
||||
return
|
||||
// Update is our implementation of recieving and processing a server.Boardstate
|
||||
// from the server
|
||||
func (p *SimplePlayer) Update(bs *server.Boardstate) map[string]server.Instruction {
|
||||
instructions := make(map[string]server.Instruction)
|
||||
|
||||
for _, bot := range bs.MyRobots {
|
||||
p.me = bot
|
||||
p.speed = 1000
|
||||
if p.me.Health <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
p.recon(bs)
|
||||
p.navigate()
|
||||
|
||||
probe_point := p.me.Position.Add(p.me.Heading.Scale(p.safeDistance))
|
||||
|
||||
instructions[bot.Id] = server.Instruction{
|
||||
MoveTo: p.moveto,
|
||||
TargetSpeed: &p.speed,
|
||||
FireAt: p.fireat,
|
||||
Probe: &probe_point,
|
||||
}
|
||||
}
|
||||
|
||||
p.recon(bs)
|
||||
p.navigate()
|
||||
return instructions
|
||||
}
|
||||
|
||||
func (p *SimplePlayer) navigate() {
|
||||
@@ -81,12 +95,7 @@ func (p *SimplePlayer) navigate() {
|
||||
}
|
||||
|
||||
func (p *SimplePlayer) recon(bs *server.Boardstate) {
|
||||
for _, o := range bs.Objects {
|
||||
obj := MiniObstacle(o)
|
||||
if _, ok := p.knownObstacles[obj.Id()]; !ok {
|
||||
p.knownObstacles[obj.Id()] = obj.ToObstacle()
|
||||
}
|
||||
}
|
||||
// XXX: need to keep track of seen objects ..
|
||||
|
||||
// simplest shooting strategy ... need to do the following:
|
||||
// not shoot through buildings
|
||||
|
||||
Reference in New Issue
Block a user