Reuse unreachable cache opening regions
This commit is contained in:
@@ -56,6 +56,61 @@ class CacheItemsTests(unittest.TestCase):
|
||||
state.choose_trapped_chest()
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_mutually_reachable_opening_is_skipped_after_path_failure(self):
|
||||
start = (0, 64, 0)
|
||||
first = (4, 64, 0)
|
||||
nearby = (4, 64, 1)
|
||||
item_id = items.get_id('stone')
|
||||
calls = []
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_cache_openings(area, _center):
|
||||
position = first if area == (10, 64, 0) else nearby
|
||||
return [{'position': position}]
|
||||
|
||||
def path_to_place(self, origin, target):
|
||||
origin, target = tuple(origin), tuple(target)
|
||||
calls.append((origin, target))
|
||||
if origin == start and target == first:
|
||||
return None
|
||||
if (origin, target) in ((nearby, first), (first, nearby)):
|
||||
return [origin, target]
|
||||
return None
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
world=FakeWorld(), pos=start,
|
||||
inv={9: Munch(present=True, item_id=item_id)}))
|
||||
state.labeled_chests = [
|
||||
{'position': (10, 64, 0), 'positions': ((10, 64, 0),),
|
||||
'item_ids': {item_id}, 'labels': {'Stone'}},
|
||||
{'position': (11, 64, 0), 'positions': ((11, 64, 0),),
|
||||
'item_ids': {item_id}, 'labels': {'Stone'}},
|
||||
]
|
||||
state.trapped_chests = []
|
||||
state.choose_trapped_chest()
|
||||
|
||||
self.assertEqual(calls, [
|
||||
(start, first), (nearby, first), (first, nearby),
|
||||
])
|
||||
self.assertIn(first, state.bad_openings)
|
||||
self.assertIn(nearby, state.bad_openings)
|
||||
|
||||
def test_one_way_reachability_does_not_blacklist_opening(self):
|
||||
bad = (1, 64, 0)
|
||||
candidate = (2, 64, 0)
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def path_to_place(start, target):
|
||||
return [start, target] if tuple(start) == candidate else None
|
||||
|
||||
state = CacheItemsStates(Munch())
|
||||
state.bad_openings = {bad}
|
||||
|
||||
self.assertFalse(state._opening_in_bad_region(FakeWorld(), candidate))
|
||||
self.assertNotIn(candidate, state.bad_openings)
|
||||
|
||||
def test_cache_chest_placement_sneaks_to_avoid_opening_support_container(self):
|
||||
calls = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user