Spaces:
Running
Running
| from engine.game.game_state import initialize_game | |
| def setup_test_state(): | |
| state = initialize_game(use_real_data=True) | |
| return state | |
| def test_pr_033_ability_reorder_and_discard(): | |
| state = setup_test_state() | |
| p0 = state.players[0] | |
| # Setup deck: [100, 101, 102, 103, ...] (100 is top) | |
| p0.main_deck = [100, 101, 102, 103, 104] | |
| p0.discard = [] | |
| # Card 473: PL!S-PR-033-PR | |
| card_id = 473 | |
| member = state.member_db[card_id] | |
| ability = member.abilities[0] | |
| # Trigger On Play | |
| state.triggered_abilities.append((0, ability, {"card_id": card_id})) | |
| state._process_rule_checks() | |
| # 1. Triggered effect: LOOK_DECK 3 (Already resolved by _process_rule_checks) | |
| # 2. Triggered effect: LOOK_AND_CHOOSE (Already resolved by _process_rule_checks) | |
| # Step 1 check: LOOK_DECK outcome | |
| assert state.looked_cards == [100, 101, 102] | |
| assert p0.main_deck == [103, 104] | |
| # Step 2 check: LOOK_AND_CHOOSE outcome (Choice pushed) | |
| # Should have a pending choice: SELECT_FROM_LIST (reason: look_and_reorder) | |
| assert len(state.pending_choices) > 0 | |
| choice_type, params = state.pending_choices[0] | |
| assert choice_type == "SELECT_FROM_LIST" | |
| assert params["reason"] == "look_and_reorder" | |
| assert params["cards"] == [100, 101, 102] | |
| # Action 600: Select 100 | |
| state._handle_choice(600) | |
| # Since any_number is True, it should stay in SELECT_FROM_LIST for more choices | |
| assert len(state.pending_choices) > 0 | |
| choice_type, params = state.pending_choices[0] | |
| assert choice_type == "SELECT_FROM_LIST" | |
| assert params["cards"] == [101, 102] | |
| assert state._reorder_staged_cards == [100] | |
| # Action 601: Select 102 (skipping 101) | |
| state._handle_choice(601) | |
| assert len(state.pending_choices) > 0 | |
| choice_type, params = state.pending_choices[0] | |
| assert params["cards"] == [101] # Only 101 remains | |
| assert state._reorder_staged_cards == [100, 102] | |
| # Action 0: Pass (Finish selecting) | |
| state._handle_choice(0) | |
| # Now it should have transitioned to SELECT_ORDER for [100, 102] | |
| # AND 101 should be in discard | |
| assert 101 in p0.discard | |
| assert state.looked_cards == [] # Cleaned up | |
| assert len(state.pending_choices) > 0 | |
| choice_type, params = state.pending_choices[0] | |
| assert choice_type == "SELECT_ORDER" | |
| assert params["cards"] == [100, 102] | |
| # Select order: 102, then 100 (Top to Bottom) | |
| # Action 700: Pick 102 first (idx 1 in cards) | |
| state._handle_choice(701) | |
| # Action 700: Pick 100 second (idx 0 in cards) | |
| state._handle_choice(700) | |
| # Final check: Deck top should be [102, 100, 103, 104] | |
| assert p0.main_deck == [102, 100, 103, 104] | |
| def test_pr_033_ability_discard_all(): | |
| state = setup_test_state() | |
| p0 = state.players[0] | |
| p0.main_deck = [100, 101, 102, 103, 104] | |
| p0.discard = [] | |
| card_id = 473 | |
| ability = state.member_db[card_id].abilities[0] | |
| state.triggered_abilities.append((0, ability, {"card_id": card_id})) | |
| state._process_rule_checks() | |
| # Action 0: Pass immediately (Discard all 3) | |
| state._handle_choice(0) | |
| assert len(p0.main_deck) == 2 | |
| assert p0.main_deck == [103, 104] | |
| assert set(p0.discard) == {100, 101, 102} | |
| assert len(state.pending_choices) == 0 | |
| def test_pr_033_ability_choose_all_no_reorder_needed(): | |
| state = setup_test_state() | |
| p0 = state.players[0] | |
| p0.main_deck = [100, 101, 102, 103] | |
| ability = state.member_db[473].abilities[0] | |
| state.triggered_abilities.append((0, ability, {"card_id": 473})) | |
| state._process_rule_checks() | |
| # Select all 3 in original order | |
| state._handle_choice(600) # 100 | |
| state._handle_choice(600) # 101 (idx 0 after shift) | |
| state._handle_choice(600) # 102 (idx 0 after shift) | |
| # Pass choice (though cards empty, code handles it) | |
| # state._handle_choice(0) # Code should auto-trigger reorder if empty. | |
| # Actually, in my implementation: | |
| # if any_number and cards: self.pending_choices.insert(0, ...) | |
| # If cards is empty, it continues below. | |
| # It should be in SELECT_ORDER now | |
| assert state.pending_choices[0][0] == "SELECT_ORDER" | |
| assert state.pending_choices[0][1]["cards"] == [100, 101, 102] | |
| # Confirm order: 100, 101, 102 | |
| state._handle_choice(700) | |
| state._handle_choice(700) | |
| state._handle_choice(700) | |
| assert p0.main_deck == [100, 101, 102, 103] | |