Avoid false positives in path recovery
This commit is contained in:
1 parent
ebf325f48b
commit
777018d24b
3 files changed
+8
-23
No files matched your search
+1
-5
@@ -137,13 +137,9 @@ def _recover_invalid_path(g, now=None):
|
||||
g.navigation_retry_at = 0.0
|
||||
if now >= g.get('path_validation_at', 0.0):
|
||||
g.path_validation_at = now + PATH_VALIDATION_INTERVAL
|
||||
start = utils.pint(g.pos)
|
||||
skip_first_edge = (not g.get('on_ground', True) or
|
||||
bool(g.get('y_v')))
|
||||
try:
|
||||
valid, invalid_node = path.Pathfinder(g).path_prefix_is_valid(
|
||||
start, route, steps=2,
|
||||
skip_start_edge=skip_first_edge)
|
||||
route, steps=2)
|
||||
except path.AStarTimeout:
|
||||
valid, invalid_node = True, None
|
||||
if not valid:
|
||||
|
||||
+4
-12
@@ -281,26 +281,18 @@ class Pathfinder(AStar):
|
||||
if not self.bair(above) or self.bavoid(above):
|
||||
return False
|
||||
below = utils.padd(node, BLOCK_BELOW)
|
||||
below_state = self.chunks.get_block_at(*below)
|
||||
return (below_state is not None and not self.bair(below) and
|
||||
not self.bavoid(below))
|
||||
return not self.bair(below) and not self.bavoid(below)
|
||||
|
||||
def path_prefix_is_valid(self, start, route, steps=2,
|
||||
skip_start_edge=False):
|
||||
def path_prefix_is_valid(self, route, steps=2):
|
||||
"""Check upcoming route nodes against the current loaded block state."""
|
||||
previous = tuple(start)
|
||||
first_edge = True
|
||||
previous = None
|
||||
for point in route[:steps]:
|
||||
node = tuple(point)
|
||||
if node == previous:
|
||||
continue
|
||||
if not self._can_stand_at(node):
|
||||
return False, node
|
||||
if not (first_edge and skip_start_edge):
|
||||
if node not in self.neighbors(previous):
|
||||
if previous is not None and node not in self.neighbors(previous):
|
||||
return False, node
|
||||
previous = node
|
||||
first_edge = False
|
||||
return True, None
|
||||
|
||||
def neighbors(self, node):
|
||||
|
||||
@@ -59,21 +59,18 @@ class DoorNavigationTests(unittest.TestCase):
|
||||
g = Munch(chunks=chunks, crawling=False, unopenable_doors=set())
|
||||
route = [(1, 64, 0), (2, 64, 0), (3, 64, 0)]
|
||||
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
||||
self.assertTrue(valid)
|
||||
self.assertIsNone(invalid_node)
|
||||
|
||||
chunks.states[(2, 64, 0)] = blocks.STONE
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
||||
self.assertFalse(valid)
|
||||
self.assertEqual(invalid_node, (2, 64, 0))
|
||||
|
||||
chunks.states.clear()
|
||||
chunks.states[(2, 63, 0)] = blocks.AIR
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(
|
||||
(0, 64, 0), route)
|
||||
valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
|
||||
self.assertFalse(valid)
|
||||
self.assertEqual(invalid_node, (2, 64, 0))
|
||||
|
||||
|
||||
Reference in new issue
Block a user