Allow sign-bounded work destinations via any route

This commit is contained in:
Tanner committed 2026-11-14 17:35:23 +00:00
1 parent cdb90730bd
commit 2191f99a29
2 files changed
+25 -22

No files matched your search

+10 -11
View File
@@ -467,8 +467,8 @@ class World:
if distances[0] <= radius: if distances[0] <= radius:
return all(distance <= radius for distance in distances) return all(distance <= radius for distance in distances)
# If the bot starts just outside a newly read boundary, let it return # Cache trips that start just outside a work boundary may return
# without allowing it to travel farther away from that sign. # toward it, but must not travel farther away or leave again.
start_distance = distances[0] start_distance = distances[0]
entered = False entered = False
for distance in distances[1:]: for distance in distances[1:]:
@@ -602,8 +602,15 @@ class World:
return result return result
def path_to_place(self, start, place): 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: try:
solution = maze_solver.astar(start, place) solution = maze_solver.astar(start, place)
if not solution: if not solution:
@@ -612,14 +619,6 @@ class World:
except path.AStarTimeout: except path.AStarTimeout:
return None 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 return navpath
def path_to_place_faked(self, start, place): def path_to_place_faked(self, start, place):
+15 -11
View File
@@ -138,7 +138,7 @@ class SignReadingTests(unittest.TestCase):
'shape': 'square', 'side': 'front', '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': [ sign_data = {'front_text': {'messages': [
'mosfet1', 'stay within 25 square', '', '', 'mosfet1', 'stay within 25 square', '', '',
]}} ]}}
@@ -150,23 +150,27 @@ class SignReadingTests(unittest.TestCase):
world = World(Munch(chunks=chunks, job=job, name='mosfet1', world = World(Munch(chunks=chunks, job=job, name='mosfet1',
pos=(0, 64, 0))) pos=(0, 64, 0)))
route = [(0, 64, 0), (50, 64, 0), (24, 64, 0)]
astar_calls = []
class FixedPathfinder: class FixedPathfinder:
@staticmethod @staticmethod
def astar(_start, _place): def astar(start, place):
return [(0, 64, 0), (20, 64, 0), (30, 64, 0)] astar_calls.append((start, place))
return route
with patch('mosfet.world.path.Pathfinder', return_value=FixedPathfinder()): 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.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 job.active_machine = cache_machine
self.assertEqual(world.path_to_place( self.assertEqual(world.path_to_place(
(0, 64, 0), (30, 64, 0)), (0, 64, 0), (30, 64, 0)), route)
[(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))
six_square = {'position': (-158, 71, -248), six_square = {'position': (-158, 71, -248),
'distance': 6, 'shape': 'square'} 'distance': 6, 'shape': 'square'}