removed unecessary looping from probe

This commit is contained in:
Stephen McQuay 2014-01-12 01:23:20 -08:00
parent 5b8ec0b8ab
commit 4d0eac703c

View File

@ -206,8 +206,6 @@ 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 i = 0; i < maxSearchIterations; i++ {
for _, v := range r.knownObstacles { for _, v := range r.knownObstacles {
collided, _, _ := govector.RectIntersection( collided, _, _ := govector.RectIntersection(
v.Bounds, v.Bounds,
@ -218,10 +216,6 @@ func (r *robot) probe(destination govector.Point2d) bool {
return false 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
}
} }