Return to work boundary after long cache trips
This commit is contained in:
1 parent
315bc212dc
commit
e019752ffd
2 files changed
+285
-4
No files matched your search
@@ -7,6 +7,7 @@ from minecraft.networking.types import BlockFace
|
||||
|
||||
from mosfet.info import items
|
||||
from mosfet.jobs.cache_items import CacheItemsStates
|
||||
from mosfet.world import World
|
||||
|
||||
|
||||
class CacheItemsTests(unittest.TestCase):
|
||||
@@ -164,6 +165,124 @@ class CacheItemsTests(unittest.TestCase):
|
||||
state.select_chest()
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_long_cache_trip_requires_a_valid_return_inside_work_boundary(self):
|
||||
start = (0, 64, 0)
|
||||
opening = (51, 64, 0)
|
||||
policy = {'position': start, 'distance': 10, 'shape': 'square'}
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def _sign_policy_distance(position, boundary):
|
||||
return World._sign_policy_distance(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _inside_sign_policy(position, boundary):
|
||||
return World._inside_sign_policy(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _path_allowed_by_sign(points, boundary):
|
||||
return World._path_allowed_by_sign(points, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _cache_opening_standable(_position):
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def sign_policies(_bot_name):
|
||||
return [policy]
|
||||
|
||||
@staticmethod
|
||||
def path_to_place(origin, target):
|
||||
return [tuple(origin), tuple(target)]
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
world=FakeWorld(), name='mosfet2', pos=start))
|
||||
state._capture_work_policies()
|
||||
|
||||
self.assertTrue(state._accept_cache_trip(
|
||||
start, opening, [start, opening]))
|
||||
self.assertTrue(state.cache_return_required)
|
||||
self.assertTrue(state._inside_work_policies(
|
||||
state.cache_return_point))
|
||||
self.assertEqual(state.cache_trip_max_outside, 41)
|
||||
|
||||
def test_cache_trip_exactly_40_beyond_boundary_does_not_trigger_return(self):
|
||||
start = (0, 64, 0)
|
||||
opening = (50, 64, 0)
|
||||
policy = {'position': start, 'distance': 10, 'shape': 'square'}
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def _sign_policy_distance(position, boundary):
|
||||
return World._sign_policy_distance(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _inside_sign_policy(position, boundary):
|
||||
return World._inside_sign_policy(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def sign_policies(_bot_name):
|
||||
return [policy]
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
world=FakeWorld(), name='mosfet2', pos=start))
|
||||
state._capture_work_policies()
|
||||
|
||||
self.assertTrue(state._accept_cache_trip(
|
||||
start, opening, [start, opening]))
|
||||
self.assertFalse(state.cache_return_required)
|
||||
self.assertEqual(state.cache_trip_max_outside, 40)
|
||||
|
||||
def test_cache_replans_return_path_after_finishing_chests(self):
|
||||
start = (0, 64, 0)
|
||||
opening = (51, 64, 0)
|
||||
return_point = (9, 64, 0)
|
||||
policy = {'position': start, 'distance': 10, 'shape': 'square'}
|
||||
path_calls = []
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def _sign_policy_distance(position, boundary):
|
||||
return World._sign_policy_distance(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _inside_sign_policy(position, boundary):
|
||||
return World._inside_sign_policy(position, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _path_allowed_by_sign(points, boundary):
|
||||
return World._path_allowed_by_sign(points, boundary)
|
||||
|
||||
@staticmethod
|
||||
def _cache_opening_standable(_position):
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def path_to_place(origin, target):
|
||||
path_calls.append((tuple(origin), tuple(target)))
|
||||
return [tuple(origin), tuple(target)]
|
||||
|
||||
g = Munch(world=FakeWorld(), name='mosfet2', pos=opening,
|
||||
path=[], look_at=None)
|
||||
state = CacheItemsStates(g)
|
||||
state.work_policies = [policy]
|
||||
state.cache_return_point = return_point
|
||||
state.cache_return_required = True
|
||||
state.cleanup()
|
||||
self.assertIs(state.state.__func__, state.return_to_work_area.__func__)
|
||||
|
||||
state.return_to_work_area()
|
||||
|
||||
self.assertIn((opening, state.cache_return_point), path_calls)
|
||||
self.assertTrue(state._inside_work_policies(state.cache_return_point))
|
||||
self.assertIs(state.state.__func__, state.going_to_return_point.__func__)
|
||||
self.assertEqual(g.path[-1], state.cache_return_point)
|
||||
|
||||
g.pos = state.cache_return_point
|
||||
state.going_to_return_point()
|
||||
self.assertFalse(state.cache_return_required)
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_wanted_single_stack_is_not_considered_transferable(self):
|
||||
wanted_id = items.WHEAT_SEEDS_ID
|
||||
old_wanted = items.WANTED_ITEMS
|
||||
|
||||
Reference in new issue
Block a user