From 928ce064eb8cd713136ccdd29dc8f40a4dd61b50 Mon Sep 17 00:00:00 2001 From: Tanner Date: Tue, 17 Nov 2026 21:32:33 +0000 Subject: [PATCH] Validate routes across crawl-mode changes --- mosfet/path.py | 28 +++++++++++++++++++++++----- tests/test_door_navigation.py | 8 ++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mosfet/path.py b/mosfet/path.py index 3f3b76d..c30b705 100644 --- a/mosfet/path.py +++ b/mosfet/path.py @@ -276,13 +276,30 @@ class Pathfinder(AStar): node = tuple(node) if not self.bair(node) or self.bavoid(node): return False - if not self.g.get('crawling'): - above = utils.padd(node, BLOCK_ABOVE) - if not self.bair(above) or self.bavoid(above): - return False below = utils.padd(node, BLOCK_BELOW) return not self.bair(below) and not self.bavoid(below) + def _path_edge_is_valid(self, start, end): + offset = utils.psub(end, start) + if offset in TRAVERSE: + # A changed ceiling can put the bot into crawl mode without + # invalidating an otherwise traversable horizontal step. + return (self.check_traverse(start, offset) or + self.check_traverse_crawling(start, offset)) + if offset in DIAGONAL: + return self.check_diagonal(start, offset) + if offset in ASCEND: + return self.check_ascend(start, offset) + if offset in DESCEND: + return self.check_descend(start, offset) + if offset in DESCEND2: + return self.check_descend2(start, offset) + if offset in DESCEND3: + return self.check_descend3(start, offset) + if offset in PARKOUR: + return self.check_parkour(start, offset) + return False + def path_prefix_is_valid(self, route, steps=2): """Check upcoming route nodes against the current loaded block state.""" previous = None @@ -290,7 +307,8 @@ class Pathfinder(AStar): node = tuple(point) if not self._can_stand_at(node): return False, node - if previous is not None and node not in self.neighbors(previous): + if (previous is not None and + not self._path_edge_is_valid(previous, node)): return False, node previous = node return True, None diff --git a/tests/test_door_navigation.py b/tests/test_door_navigation.py index f1dc709..d44f2ce 100644 --- a/tests/test_door_navigation.py +++ b/tests/test_door_navigation.py @@ -63,6 +63,14 @@ class DoorNavigationTests(unittest.TestCase): self.assertTrue(valid) self.assertIsNone(invalid_node) + # A low ceiling can switch traversal to crawling without making the + # horizontal path edge invalid. + chunks.states[(1, 65, 0)] = blocks.STONE + valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route) + self.assertTrue(valid) + self.assertIsNone(invalid_node) + + chunks.states.clear() chunks.states[(2, 64, 0)] = blocks.STONE valid, invalid_node = Pathfinder(g).path_prefix_is_valid(route) self.assertFalse(valid)