removed unecessary looping from probe
This commit is contained in:
parent
5b8ec0b8ab
commit
4d0eac703c
25
robot.go
25
robot.go
@ -206,8 +206,6 @@ 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,
|
||||
@ -218,10 +216,6 @@ func (r *robot) probe(destination govector.Point2d) bool {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user