Avoid false positives in path recovery

This commit is contained in:
Tanner committed 2026-11-17 20:32:34 +00:00
1 parent ebf325f48b
commit 777018d24b
3 files changed
+9 -24

No files matched your search

+1 -5
View File
@@ -137,13 +137,9 @@ def _recover_invalid_path(g, now=None):
g.navigation_retry_at = 0.0 g.navigation_retry_at = 0.0
if now >= g.get('path_validation_at', 0.0): if now >= g.get('path_validation_at', 0.0):
g.path_validation_at = now + PATH_VALIDATION_INTERVAL 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: try:
valid, invalid_node = path.Pathfinder(g).path_prefix_is_valid( valid, invalid_node = path.Pathfinder(g).path_prefix_is_valid(
start, route, steps=2, route, steps=2)
skip_start_edge=skip_first_edge)
except path.AStarTimeout: except path.AStarTimeout:
valid, invalid_node = True, None valid, invalid_node = True, None
if not valid: if not valid:
+5 -13
View File
@@ -281,26 +281,18 @@ class Pathfinder(AStar):
if not self.bair(above) or self.bavoid(above): if not self.bair(above) or self.bavoid(above):
return False return False
below = utils.padd(node, BLOCK_BELOW) below = utils.padd(node, BLOCK_BELOW)
below_state = self.chunks.get_block_at(*below) return not self.bair(below) and not self.bavoid(below)
return (below_state is not None and not self.bair(below) and
not self.bavoid(below))
def path_prefix_is_valid(self, start, route, steps=2, def path_prefix_is_valid(self, route, steps=2):
skip_start_edge=False):
"""Check upcoming route nodes against the current loaded block state.""" """Check upcoming route nodes against the current loaded block state."""
previous = tuple(start) previous = None
first_edge = True
for point in route[:steps]: for point in route[:steps]:
node = tuple(point) node = tuple(point)
if node == previous:
continue
if not self._can_stand_at(node): if not self._can_stand_at(node):
return False, node return False, node
if not (first_edge and skip_start_edge): if previous is not None and node not in self.neighbors(previous):
if node not in self.neighbors(previous): return False, node
return False, node
previous = node previous = node
first_edge = False
return True, None return True, None
def neighbors(self, node): def neighbors(self, node):
+3 -6
View File
@@ -59,21 +59,18 @@ class DoorNavigationTests(unittest.TestCase):
g = Munch(chunks=chunks, crawling=False, unopenable_doors=set()) g = Munch(chunks=chunks, crawling=False, unopenable_doors=set())
route = [(1, 64, 0), (2, 64, 0), (3, 64, 0)] route = [(1, 64, 0), (2, 64, 0), (3, 64, 0)]
valid, invalid_node = Pathfinder(g).path_prefix_is_valid( valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
(0, 64, 0), route)
self.assertTrue(valid) self.assertTrue(valid)
self.assertIsNone(invalid_node) self.assertIsNone(invalid_node)
chunks.states[(2, 64, 0)] = blocks.STONE chunks.states[(2, 64, 0)] = blocks.STONE
valid, invalid_node = Pathfinder(g).path_prefix_is_valid( valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
(0, 64, 0), route)
self.assertFalse(valid) self.assertFalse(valid)
self.assertEqual(invalid_node, (2, 64, 0)) self.assertEqual(invalid_node, (2, 64, 0))
chunks.states.clear() chunks.states.clear()
chunks.states[(2, 63, 0)] = blocks.AIR chunks.states[(2, 63, 0)] = blocks.AIR
valid, invalid_node = Pathfinder(g).path_prefix_is_valid( valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route)
(0, 64, 0), route)
self.assertFalse(valid) self.assertFalse(valid)
self.assertEqual(invalid_node, (2, 64, 0)) self.assertEqual(invalid_node, (2, 64, 0))