File size: 4,522 Bytes
bb3fbf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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]