Cache after sleep near labeled chests
This commit is contained in:
@@ -46,6 +46,112 @@ class CacheItemsTests(unittest.TestCase):
|
||||
finally:
|
||||
items.WANTED_ITEMS = old_wanted
|
||||
|
||||
def test_post_sleep_halves_threshold_only_with_compatible_nearby_chest(self):
|
||||
bed = (0, 64, 0)
|
||||
chest_position = (5, 64, 0)
|
||||
item_id = items.get_id('stone')
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 14
|
||||
|
||||
class NearbyWorld:
|
||||
@staticmethod
|
||||
def find_labeled_chests(_center, _distance):
|
||||
return [{
|
||||
'position': chest_position,
|
||||
'positions': (chest_position,),
|
||||
'item_ids': {item_id},
|
||||
}]
|
||||
|
||||
g = Munch(
|
||||
game=FakeGame(), world=NearbyWorld(),
|
||||
minimum_cache_slots=27, post_sleep_cache_bed=bed,
|
||||
inv={9: Munch(present=True, item_id=item_id, item_count=64)})
|
||||
state = CacheItemsStates(g)
|
||||
|
||||
state.init()
|
||||
|
||||
self.assertIs(state.state.__func__, state.find_trapped_chests.__func__)
|
||||
self.assertNotIn('post_sleep_cache_bed', g)
|
||||
|
||||
def test_post_sleep_threshold_rounds_27_up_to_14(self):
|
||||
bed = (0, 64, 0)
|
||||
item_id = items.get_id('stone')
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 13
|
||||
|
||||
class NearbyWorld:
|
||||
@staticmethod
|
||||
def find_labeled_chests(_center, _distance):
|
||||
return [{
|
||||
'position': (5, 64, 0),
|
||||
'positions': ((5, 64, 0),),
|
||||
'item_ids': {item_id},
|
||||
}]
|
||||
|
||||
g = Munch(
|
||||
game=FakeGame(), world=NearbyWorld(), minimum_cache_slots=27,
|
||||
post_sleep_cache_bed=bed,
|
||||
inv={9: Munch(present=True, item_id=item_id, item_count=64)})
|
||||
state = CacheItemsStates(g)
|
||||
|
||||
state.init()
|
||||
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_post_sleep_does_not_lower_threshold_without_compatible_nearby_chest(self):
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 14
|
||||
|
||||
class EmptyWorld:
|
||||
@staticmethod
|
||||
def find_labeled_chests(_center, _distance):
|
||||
return []
|
||||
|
||||
g = Munch(
|
||||
game=FakeGame(), world=EmptyWorld(), minimum_cache_slots=27,
|
||||
post_sleep_cache_bed=(0, 64, 0), inv={})
|
||||
state = CacheItemsStates(g)
|
||||
|
||||
state.init()
|
||||
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
self.assertNotIn('post_sleep_cache_bed', g)
|
||||
|
||||
def test_post_sleep_ignores_compatible_chest_beyond_16_blocks(self):
|
||||
item_id = items.get_id('stone')
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 14
|
||||
|
||||
class FarWorld:
|
||||
@staticmethod
|
||||
def find_labeled_chests(_center, _distance):
|
||||
position = (17, 64, 0)
|
||||
return [{
|
||||
'position': position,
|
||||
'positions': (position,),
|
||||
'item_ids': {item_id},
|
||||
}]
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
game=FakeGame(), world=FarWorld(), minimum_cache_slots=27,
|
||||
post_sleep_cache_bed=(0, 64, 0),
|
||||
inv={9: Munch(present=True, item_id=item_id, item_count=64)}))
|
||||
|
||||
state.init()
|
||||
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_manual_cache_threshold_override_is_consumed_once(self):
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
|
||||
@@ -29,9 +29,11 @@ class SignWorkTargetTests(unittest.TestCase):
|
||||
return crop_state
|
||||
|
||||
state = GatherCropStates(Munch(world=FakeWorld(), pos=(0, 64, 0)))
|
||||
state.completed_crops = 7
|
||||
state.find_new_crop()
|
||||
|
||||
self.assertIs(state.state.__func__, state.wait_for_crops.__func__)
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
self.assertEqual(state.completed_crops, 0)
|
||||
self.assertEqual(state.bad_crops, [])
|
||||
|
||||
def test_tree_search_skips_out_of_bounds_tree_without_blacklisting_it(self):
|
||||
|
||||
@@ -52,6 +52,27 @@ class FakeGame:
|
||||
|
||||
|
||||
class TestSleepWithBed(unittest.TestCase):
|
||||
def test_confirmed_sleep_records_bed_for_following_cache_pass(self):
|
||||
bed = (1, 64, 2)
|
||||
g = Munch(world=FakeWorld(), path=[], look_at=None)
|
||||
state = SleepWithBedStates(g)
|
||||
state.area = bed
|
||||
state.sleep_confirmed = True
|
||||
|
||||
state.cleanup()
|
||||
|
||||
self.assertEqual(g.post_sleep_cache_bed, bed)
|
||||
|
||||
def test_unconfirmed_sleep_does_not_trigger_post_sleep_cache(self):
|
||||
g = Munch(world=FakeWorld(), path=[], look_at=None)
|
||||
state = SleepWithBedStates(g)
|
||||
state.area = (1, 64, 2)
|
||||
state.sleep_confirmed = False
|
||||
|
||||
state.cleanup()
|
||||
|
||||
self.assertNotIn('post_sleep_cache_bed', g)
|
||||
|
||||
def test_bed_occupancy_only_logs_first_observation_and_changes(self):
|
||||
bed_states = [
|
||||
state for state in blocks.BED_IDS
|
||||
|
||||
Reference in New Issue
Block a user