File size: 2,940 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
import numpy as np

from engine.game.enums import Phase
from engine.game.game_state import GameState
from engine.models.card import LiveCard, MemberCard


def test_multiple_live_selection_and_discard():
    print("\n--- Starting Multiple Live Selection Test ---")
    gs = GameState()
    m1 = MemberCard(
        card_id=1,
        card_no="M1",
        name="Member 1",
        cost=1,
        hearts=np.array([2, 0, 0, 0, 0, 0, 0]),
        blade_hearts=np.zeros(7, dtype=np.int32),
        blades=0,
        img_path="m1.png",
    )
    gs.member_db = {1: m1}

    gs.live_db = {
        100: LiveCard(
            card_id=100,
            card_no="100",
            name="Live A",
            img_path="a.png",
            score=1,
            required_hearts=np.array([1, 0, 0, 0, 0, 0, 0]),
        ),
        101: LiveCard(
            card_id=101,
            card_no="101",
            name="Live B",
            img_path="b.png",
            score=1,
            required_hearts=np.array([1, 0, 0, 0, 0, 0, 0]),
        ),
    }

    p = gs.players[0]
    p.stage[1] = 1
    p.live_zone = [100, 101]

    print(f"Pre-performance hearts: {p.get_total_hearts(gs.member_db)}")

    gs.phase = Phase.PERFORMANCE_P1
    gs._do_performance(0)

    print(f"Passed lives: {p.passed_lives}")
    assert len(p.passed_lives) == 2

    gs.phase = Phase.LIVE_RESULT
    gs._do_live_result()

    print(f"Pending choices: {[c[0] for c in gs.pending_choices]}")
    assert len(gs.pending_choices) > 0
    assert gs.pending_choices[0][0] == "SELECT_SUCCESS_LIVE"

    # Select Live A (Index 0 in [100, 101])
    gs.take_action(600)

    print(f"DEBUG: Success lives: {p.success_lives}")
    print(f"DEBUG: Passed lives: {p.passed_lives}")
    print(f"DEBUG: Discard pile: {p.discard}")
    print(f"DEBUG: Pending choices after selection: {[c[0] for c in gs.pending_choices]}")

    assert 100 in p.success_lives
    assert 101 not in p.success_lives
    # 101 should be in discard because SELECT_SUCCESS_LIVE logic discards others
    assert 101 in p.discard

    # 101 should be in discard because SELECT_SUCCESS_LIVE logic discards others
    assert 101 in p.discard

    # With high-throughput optimization, the game auto-advances after selection.
    # It skips the "CONTINUE_LIVE_RESULT" confirmation.

    # Check that we advanced to next turn's ENERGY phase (via Active Phase)
    # The phase transition chain is: LIVE_RESULT -> _finish_live_result -> _do_active_phase (ENERGY)
    assert gs.phase == Phase.ENERGY, "Should advance to Active -> Energy Phase"

    # Verify no pending choices
    assert len(gs.pending_choices) == 0

    print("Test passed!")


if __name__ == "__main__":
    try:
        test_multiple_live_selection_and_discard()
    except Exception:
        import traceback

        traceback.print_exc()
        exit(1)