removed unecessary looping from probe

This commit is contained in:
Stephen McQuay 2014-01-12 01:23:20 -08:00
parent 5b8ec0b8ab
commit 4d0eac703c
1 changed files with 19 additions and 22 deletions

View File

@ -206,22 +206,16 @@ func (r *robot) selectDirection() *govector.Point2d {
func (r *robot) probe(destination govector.Point2d) bool { func (r *robot) probe(destination govector.Point2d) bool {
// XXX: make test for this // XXX: make test for this
var i int for _, v := range r.knownObstacles {
for i = 0; i < maxSearchIterations; i++ { collided, _, _ := govector.RectIntersection(
for _, v := range r.knownObstacles { v.Bounds,
collided, _, _ := govector.RectIntersection( r.me.Position,
v.Bounds, destination.Sub(r.me.Position),
r.me.Position, )
destination.Sub(r.me.Position), if collided {
) return false
if collided {
return false
}
} }
} }
if *verbose {
log.Printf("%s: iterations to find destination: %d", r.name, i)
}
return true return true
} }
@ -239,20 +233,13 @@ func (r *robot) navigate() {
r.moveto = r.selectDirection() r.moveto = r.selectDirection()
} }
if r.me.Collision {
if *verbose {
log.Printf("%s apparent collision", r.name)
}
r.moveto = r.selectDirection()
r.speed = 0
return
}
togo := r.me.Position.Sub(*r.moveto).Mag() togo := r.me.Position.Sub(*r.moveto).Mag()
if togo < safeDistance+5 { if togo < safeDistance+5 {
if *verbose { if *verbose {
log.Printf("%s got to destination", r.name) log.Printf("%s got to destination", r.name)
} }
r.moveto = r.selectDirection() r.moveto = r.selectDirection()
return
} }
if !r.probe(r.me.Position.Add(r.me.Heading.Scale(safeDistance))) { if !r.probe(r.me.Position.Add(r.me.Heading.Scale(safeDistance))) {
if *verbose { if *verbose {
@ -264,6 +251,16 @@ func (r *robot) navigate() {
log.Printf("%s unsafe to move, choose new direction", r.name) log.Printf("%s unsafe to move, choose new direction", r.name)
} }
r.moveto = r.selectDirection() r.moveto = r.selectDirection()
return
} }
} }
if r.me.Collision {
// XXX: I am being told I am here ...
if *verbose {
log.Printf("%s apparent collision", r.name)
}
r.moveto = r.selectDirection()
r.speed = 0
return
}
} }