fixed stalling robots

This commit is contained in:
Stephen McQuay 2014-01-11 23:14:44 -08:00
parent b16886cbac
commit a122577019
1 changed files with 6 additions and 6 deletions

View File

@ -12,7 +12,8 @@ import (
)
const maxSpeed = 100
const safeDistance = 20
const safeDistance = 40
const maxSearchIterations = 20
func connect(server string, port int) (*websocket.Conn, error) {
origin := "http://localhost/"
@ -136,7 +137,6 @@ func (r *robot) play() {
if len(r.boardstate.MyRobots) > 0 {
r.me = r.boardstate.MyRobots[0]
} else {
// XXX
log.Println("continue")
continue
}
@ -178,7 +178,7 @@ func (r *robot) recon() {
}
}
if r.nearestEnemy != nil {
point := r.nearestEnemy.Position.Add(r.nearestEnemy.Heading.Scale(20))
point := r.nearestEnemy.Position.Add(r.nearestEnemy.Heading.Scale(safeDistance))
r.fireat = &point
}
}
@ -193,7 +193,7 @@ func (r *robot) selectDirection() *govector.Point2d {
func (r *robot) probe(destination govector.Point2d) bool {
// XXX: make test for this
for i := 0; i < 20; i++ {
for i := 0; i < maxSearchIterations; i++ {
for _, v := range r.knownObstacles {
collided, _, _ := govector.RectIntersection(
v.Bounds,
@ -225,10 +225,10 @@ func (r *robot) navigate() {
return
}
togo := r.me.Position.Sub(*r.moveto).Mag()
if togo < 20.0 {
if togo < safeDistance {
r.moveto = r.selectDirection()
}
if !r.probe(r.me.Position.Add(r.me.Heading.Scale(80))) {
if !r.probe(r.me.Position.Add(r.me.Heading.Scale(safeDistance))) {
r.speed = 0
if !r.probe(*r.moveto) {
r.moveto = r.selectDirection()