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