Skip to content

Fill: fix swap error found in CI #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:

location.item = None
placed_item.location = None
swap_state = sweep_from_pool(base_state, [placed_item] if unsafe else [])
swap_state = sweep_from_pool(base_state, [placed_item, *item_pool] if unsafe else item_pool)
# unsafe means swap_state assumes we can somehow collect placed_item before item_to_place
# by continuing to swap, which is not guaranteed. This is unsafe because there is no mechanic
# to clean that up later, so there is a chance generation fails.
Expand Down
38 changes: 38 additions & 0 deletions test/general/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,44 @@ def test_swap_to_earlier_location_with_item_rule(self):
self.assertTrue(sphere1_loc.item, "Did not swap required item into Sphere 1")
self.assertEqual(sphere1_loc.item, allowed_item, "Wrong item in Sphere 1")

def test_swap_to_earlier_location_with_item_rule2(self):
"""Also test that item swap happens and works as intended"""
multi_world = generate_multi_world(1)
player1 = generate_player_data(multi_world, 1, 5, 5)
locations = player1.locations[:] # copy required
items = player1.prog_items[:] # copy required
# Two items provide access to sphere 2.
# One of them is forbidden in sphere 1, the other is placed in sphere 3 because of placement order.
# There are spheres in between, so for the swap to work, it'll have to assume all other items are collected.
one_to_two1 = items[4].name
one_to_two2 = items[3].name
three_to_four = items[2].name
two_to_three1 = items[1].name
two_to_three2 = items[0].name
# Sphere 4
set_rule(locations[0], lambda state: ((state.has(one_to_two1, player1.id) or state.has(one_to_two2, player1.id))
and state.has(two_to_three1, player1.id)
and state.has(two_to_three2, player1.id)
and state.has(three_to_four, player1.id)))
# Sphere 3
set_rule(locations[1], lambda state: ((state.has(one_to_two1, player1.id) or state.has(one_to_two2, player1.id))
and state.has(two_to_three1, player1.id)
and state.has(two_to_three2, player1.id)))
# Sphere 2
set_rule(locations[2], lambda state: state.has(one_to_two1, player1.id) or state.has(one_to_two2, player1.id))

# forbid one_to_two2 in sphere 1, which will have to swap out one_to_two1
sphere1_loc1 = locations[3]
sphere1_loc2 = locations[4]
add_item_rule(sphere1_loc1, lambda item_to_place: item_to_place.name != one_to_two2)
add_item_rule(sphere1_loc2, lambda item_to_place: item_to_place.name != one_to_two2)
# fill has to place items[1] in locations[0] which will result in a swap because of placement order
fill_restrictive(multi_world, multi_world.state, player1.locations, player1.prog_items)
# assert swap happened
self.assertTrue(sphere1_loc1.item and sphere1_loc2.item, "Did not swap required item into Sphere 1")
self.assertTrue(sphere1_loc1.item.name == one_to_two1 or
sphere1_loc2.item.name == one_to_two1, "Wrong item in Sphere 1")

def test_double_sweep(self):
"""Test that sweep doesn't duplicate Event items when sweeping"""
# test for PR1114
Expand Down