From 4d0eac703cc353626f4fbba37d326f939b16f055 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sun, 12 Jan 2014 01:23:20 -0800 Subject: [PATCH] removed unecessary looping from probe --- robot.go | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/robot.go b/robot.go index bd80980..4b3f69d 100644 --- a/robot.go +++ b/robot.go @@ -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 + } }