From 2191f99a2947c8460358fb5aeb0a1032519286d4 Mon Sep 17 00:00:00 2001 From: Tanner Date: Sat, 14 Nov 2026 17:35:23 +0000 Subject: [PATCH] Allow sign-bounded work destinations via any route --- mosfet/world.py | 21 ++++++++++----------- tests/test_signs.py | 26 +++++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/mosfet/world.py b/mosfet/world.py index 4e0c9f7..08659dd 100644 --- a/mosfet/world.py +++ b/mosfet/world.py @@ -467,8 +467,8 @@ class World: if distances[0] <= radius: return all(distance <= radius for distance in distances) - # If the bot starts just outside a newly read boundary, let it return - # without allowing it to travel farther away from that sign. + # Cache trips that start just outside a work boundary may return + # toward it, but must not travel farther away or leave again. start_distance = distances[0] entered = False for distance in distances[1:]: @@ -602,8 +602,15 @@ class World: return result def path_to_place(self, start, place): - maze_solver = path.Pathfinder(self.g) + policies = self._active_work_policies() + for policy in policies: + if not self._inside_sign_policy(place, policy): + print('[sign policy] rejected work destination outside {}-block {} ' + 'around {}'.format(policy['distance'], policy['shape'], + policy['position']), flush=True) + return None + maze_solver = path.Pathfinder(self.g) try: solution = maze_solver.astar(start, place) if not solution: @@ -612,14 +619,6 @@ class World: except path.AStarTimeout: return None - policies = self._active_work_policies() - points = [tuple(start)] + [tuple(point) for point in navpath] - for policy in policies: - if not self._path_allowed_by_sign(points, policy): - print('[sign policy] rejected work path outside {}-block {} ' - 'around {}'.format(policy['distance'], policy['shape'], - policy['position']), flush=True) - return None return navpath def path_to_place_faked(self, start, place): diff --git a/tests/test_signs.py b/tests/test_signs.py index e5c688d..1ed5bf2 100644 --- a/tests/test_signs.py +++ b/tests/test_signs.py @@ -138,7 +138,7 @@ class SignReadingTests(unittest.TestCase): 'shape': 'square', 'side': 'front', }]) - def test_work_paths_obey_sign_boundary_but_cache_paths_do_not(self): + def test_work_paths_check_destination_only_but_cache_paths_bypass_signs(self): sign_data = {'front_text': {'messages': [ 'mosfet1', 'stay within 25 square', '', '', ]}} @@ -150,23 +150,27 @@ class SignReadingTests(unittest.TestCase): world = World(Munch(chunks=chunks, job=job, name='mosfet1', pos=(0, 64, 0))) + route = [(0, 64, 0), (50, 64, 0), (24, 64, 0)] + astar_calls = [] + class FixedPathfinder: @staticmethod - def astar(_start, _place): - return [(0, 64, 0), (20, 64, 0), (30, 64, 0)] + def astar(start, place): + astar_calls.append((start, place)) + return route with patch('mosfet.world.path.Pathfinder', return_value=FixedPathfinder()): + # The work target is inside, so even a route well outside is okay. + self.assertEqual(world.path_to_place((0, 64, 0), (24, 64, 0)), + route) + # An out-of-bounds destination is rejected before pathfinding. self.assertIsNone(world.path_to_place((0, 64, 0), (30, 64, 0))) + self.assertEqual(len(astar_calls), 1) + + # Support/cache paths do not use work-sign limits. job.active_machine = cache_machine self.assertEqual(world.path_to_place( - (0, 64, 0), (30, 64, 0)), - [(0, 64, 0), (20, 64, 0), (30, 64, 0)]) - - policy = {'position': (0, 64, 0), 'distance': 25, 'shape': 'square'} - self.assertTrue(World._path_allowed_by_sign( - [(30, 64, 0), (27, 64, 0), (24, 64, 0)], policy)) - self.assertFalse(World._path_allowed_by_sign( - [(30, 64, 0), (32, 64, 0), (24, 64, 0)], policy)) + (0, 64, 0), (30, 64, 0)), route) six_square = {'position': (-158, 71, -248), 'distance': 6, 'shape': 'square'}