Skip to content

Commit

Permalink
fix piece limit tests (regression after Camel feature)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesslogic committed Jun 19, 2024
1 parent 244a618 commit f27e1bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
5 changes: 2 additions & 3 deletions worlds/checksmate/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def determine_relaxation(opts: CMOptions):

def meets_material_expectations(state: CollectionState,
material: int, player: int, difficulty: float, absolute_relaxation: int) -> bool:
return state.prog_items[player]["Material"] >= (
(material * difficulty) + (absolute_relaxation if material > 90 else 0))
target = (material * difficulty) + (absolute_relaxation if material > 90 else 0)
return state.prog_items[player]["Material"] >= target


def meets_chessmen_expectations(state: CollectionState,
Expand All @@ -103,7 +103,6 @@ def meets_chessmen_expectations(state: CollectionState,
return chessmen_count + pocket_count >= count



def set_rules(multiworld: MultiWorld, player: int, opts: CMOptions):
difficulty = determine_difficulty(opts)
absolute_relaxation = determine_relaxation(opts)
Expand Down
10 changes: 4 additions & 6 deletions worlds/checksmate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CMWorld(World):
items_used: Dict[int, Dict[str, int]] = {}
items_remaining: Dict[int, Dict[str, int]] = {}
armies: Dict[int, List[int]] = {}
army_piece_types_by_player: Dict[int, Dict[str, int]] = {}

item_pool: List[CMItem] = []
prefill_items: List[CMItem] = []
Expand Down Expand Up @@ -471,11 +470,10 @@ def find_piece_limit(self, chosen_item: str, with_children: PieceLimitCascade) -
return 0

piece_limit: int = self.piece_limit_of(chosen_item)
if self.player not in self.army_piece_types_by_player:
self.army_piece_types_by_player[self.player] = \
{piece: sum([self.piece_types_by_army[army][piece] for army in self.armies[self.player]])
for piece in set().union(*self.piece_types_by_army.values())}
limit_multiplier = get_limit_multiplier_for_item(self.army_piece_types_by_player[self.player])
army_piece_types = {
piece: sum([self.piece_types_by_army[army][piece] for army in self.armies[self.player]])
for piece in set().union(*self.piece_types_by_army.values())}
limit_multiplier = get_limit_multiplier_for_item(army_piece_types)
piece_limit = piece_limit * limit_multiplier(chosen_item)
if piece_limit > 0 and with_children != self.PieceLimitCascade.NO_CHILDREN:
children = get_children(chosen_item)
Expand Down
39 changes: 16 additions & 23 deletions worlds/checksmate/test/TestPieceLimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class TestChaosPieceLimitsOfOne(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "chaos",
"fairy_chess_piece_collection": 2,
"fairy_chess_piece_collection": "configure",
"minor_piece_limit_by_type": 1,
"major_piece_limit_by_type": 1,
"queen_piece_limit_by_type": 1,
}

def test_limit(self):
expected_minors = 9
expected_majors = 5
expected_minors = 11
expected_majors = 7
expected_queens = 4
self.assert_matches(expected_minors, expected_majors, expected_queens)
self.assert_actuals(expected_majors, expected_queens)
Expand All @@ -81,16 +81,16 @@ class TestChaosPieceLimitsOfTwo(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "chaos",
"fairy_chess_piece_collection": 2,
"fairy_chess_piece_collection": "configure",
"minor_piece_limit_by_type": 2,
"major_piece_limit_by_type": 2,
"queen_piece_limit_by_type": 2,
}

def test_limit(self):
expected_minors = 18
expected_majors = 10
expected_queens = 8
expected_minors = 22
expected_majors = 14
expected_queens = 10
self.assert_matches(expected_minors, expected_majors, expected_queens)
self.assert_actuals(expected_majors, expected_queens)

Expand All @@ -99,25 +99,24 @@ class TestChaosPieceLimitsByVariety(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "chaos",
"fairy_chess_piece_collection": 2,
"fairy_chess_piece_collection": "configure",
"minor_piece_limit_by_type": 5,
"major_piece_limit_by_type": 1,
"queen_piece_limit_by_type": 3,
}

def test_limit(self):
expected_minors = 45
expected_majors = 5
expected_queens = 12
expected_minors = 55
expected_majors = 7
expected_queens = 18
self.assert_matches(expected_minors, expected_majors, expected_queens)
self.assert_actuals(expected_majors, expected_queens)


class TestLimitedPieceLimits(PieceLimitTestBase):
class TestStablePieceLimits(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "limited",
"fairy_chess_piece_collection": 2,
"fairy_chess_piece_collection": "configure",
}

def test_no_options(self):
Expand All @@ -127,11 +126,9 @@ def test_no_options(self):
self.assert_matches(expected_minors, expected_majors, expected_queens)


class TestLimitedPieceLimitsOfVanilla(PieceLimitTestBase):
class TestStablePieceLimitsOfVanilla(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "limited",
"fairy_chess_piece_collection": 2,
"minor_piece_limit_by_type": 2,
"major_piece_limit_by_type": 2,
"queen_piece_limit_by_type": 1,
Expand All @@ -145,11 +142,9 @@ def test_limit(self):
self.assert_actuals(expected_majors, expected_queens)


class TestLimitedPieceLimitsOfThree(PieceLimitTestBase):
class TestStablePieceLimitsOfThree(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "limited",
"fairy_chess_piece_collection": 0,
"minor_piece_limit_by_type": 3,
"major_piece_limit_by_type": 3,
"queen_piece_limit_by_type": 3,
Expand All @@ -163,11 +158,9 @@ def test_limit(self):
self.assert_actuals(expected_majors, expected_queens)


class TestLimitedPieceLimitsByVariety(PieceLimitTestBase):
class TestStablePieceLimitsByVariety(PieceLimitTestBase):
options = {
"accessibility": "minimal",
"fairy_chess_army": "limited",
"fairy_chess_piece_collection": 0,
"minor_piece_limit_by_type": 4,
"major_piece_limit_by_type": 1,
"queen_piece_limit_by_type": 3,
Expand Down

0 comments on commit f27e1bf

Please sign in to comment.