Validate diagonal edges during airborne path recovery

This commit is contained in:
Tanner committed 2026-11-18 20:02:09 +00:00
1 parent 0ea7b855be
commit 838bac6680
3 files changed
+42 -29

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_start_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(
route, steps=2, start=start, route, steps=2)
skip_start_edge=skip_start_edge)
except path.AStarTimeout: except path.AStarTimeout:
valid, invalid_node = True, None valid, invalid_node = True, None
if not valid: if not valid:
+9 -12
View File
@@ -302,25 +302,22 @@ class Pathfinder(AStar):
return self.check_parkour(start, offset) return self.check_parkour(start, offset)
return False return False
def path_prefix_is_valid(self, route, steps=2, start=None, def path_prefix_is_valid(self, route, steps=2):
skip_start_edge=False): """Check upcoming route edges without treating its start as blocked."""
"""Check upcoming route nodes without treating midair start as blocked.""" previous = None
previous = tuple(start) if start is not None else None
first_edge = True
for point in route[:steps]: for point in route[:steps]:
node = tuple(point) node = tuple(point)
if previous is not None and node == previous: if previous is None:
# A* includes its start in the reconstructed route. The bot # A* includes its start in the route. The bot may be airborne
# may currently be jumping/falling through that cell. # or have moved into this cell since planning; still validate
# its outgoing edge so new diagonal obstacles are detected.
previous = node
continue continue
if not self._can_stand_at(node): if not self._can_stand_at(node):
return False, node return False, node
if (previous is not None and if not self._path_edge_is_valid(previous, node):
not (first_edge and skip_start_edge) and
not self._path_edge_is_valid(previous, node)):
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):
+32 -12
View File
@@ -128,7 +128,7 @@ class DoorNavigationTests(unittest.TestCase):
chunks=chunks, crawling=False, unopenable_doors=set())) chunks=chunks, crawling=False, unopenable_doors=set()))
valid, invalid_node = finder.path_prefix_is_valid( valid, invalid_node = finder.path_prefix_is_valid(
route, steps=2, start=start, skip_start_edge=True) route, steps=2)
self.assertTrue(valid) self.assertTrue(valid)
self.assertIsNone(invalid_node) self.assertIsNone(invalid_node)
@@ -140,35 +140,55 @@ class DoorNavigationTests(unittest.TestCase):
valid, invalid_node = Pathfinder(Munch( valid, invalid_node = Pathfinder(Munch(
chunks=chunks, crawling=False, chunks=chunks, crawling=False,
unopenable_doors=set())).path_prefix_is_valid( unopenable_doors=set())).path_prefix_is_valid(
route, steps=3, start=start, skip_start_edge=True) route, steps=3)
self.assertFalse(valid) self.assertFalse(valid)
self.assertEqual(invalid_node, (2, 64, 0)) self.assertEqual(invalid_node, (2, 64, 0))
def test_path_recovery_ignores_unsupported_airborne_start_cell(self): def test_path_recovery_skips_midair_start_but_reroutes_diagonal_tree(self):
class MidairStartChunks: class TerrainChunks:
def __init__(self):
self.tree = None
def get_block_at(self, x, y, z): def get_block_at(self, x, y, z):
if (x, y, z) == (0, 63, 0): position = (x, y, z)
if position == self.tree:
return blocks.MCD_BLOCKS['oak_log']['minStateId']
if position == (0, 63, 0):
return blocks.AIR return blocks.AIR
return blocks.STONE if y == 63 else blocks.AIR return blocks.STONE if y == 63 else blocks.AIR
class FakeWorld: class FakeWorld:
def path_to_place(self, *_args): def __init__(self):
raise AssertionError('unchanged path should not be replanned') self.calls = []
route = [(0, 64, 0), (1, 64, 0), (2, 64, 0)] def path_to_place(self, start, goal):
self.calls.append((start, goal))
return [start, (0, 64, -1), (1, 64, 0), goal]
start = (0, 64, 0)
route = [start, (1, 64, 1), (2, 64, 2)]
chunks = TerrainChunks()
world = FakeWorld()
g = Munch( g = Munch(
chunks=MidairStartChunks(), crawling=False, chunks=chunks, crawling=False, unopenable_doors=set(),
unopenable_doors=set(), world=FakeWorld(), world=world, path=list(route), pos=(0.5, 64.2, 0.5),
path=list(route), pos=(0.5, 64.2, 0.5),
on_ground=False, y_v=1.0, path_validation_at=0.0, on_ground=False, y_v=1.0, path_validation_at=0.0,
navigation_recovery_target=None, navigation_retry_at=0.0) navigation_recovery_target=None, navigation_retry_at=0.0)
# Being airborne over an unsupported start cell alone is not a block.
_recover_invalid_path(g, now=1.0) _recover_invalid_path(g, now=1.0)
self.assertEqual(g.path, route) self.assertEqual(g.path, route)
self.assertIsNone(g.navigation_recovery_target) self.assertIsNone(g.navigation_recovery_target)
# A newly grown trunk blocks the first diagonal edge's corner space.
chunks.tree = (0, 64, 1)
_recover_invalid_path(g, now=1.3)
self.assertEqual(world.calls, [(start, route[-1])])
self.assertEqual(g.path, [start, (0, 64, -1), (1, 64, 0), route[-1]])
self.assertIsNone(g.navigation_recovery_target)
def test_invalid_path_is_replanned_to_its_original_destination(self): def test_invalid_path_is_replanned_to_its_original_destination(self):
class FakePathfinder: class FakePathfinder:
@staticmethod @staticmethod