File size: 2,335 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
import json

import engine_rust as lovecasim_engine
import pytest


@pytest.fixture
def env():
    # Load the real compiled data to ensure we are testing the actual fix
    with open("data/cards_compiled.json", "r", encoding="utf-8") as f:
        data = json.load(f)

    p0_card = data["member_db"]["565"].copy()
    p0_card["cost"] = 0  # Skip energy check

    # Minimal card DB for testing
    test_db_json = {"member_db": {"565": p0_card, "1": data["member_db"]["1"]}, "live_db": {}}
    db = lovecasim_engine.PyCardDatabase(json.dumps(test_db_json))
    state = lovecasim_engine.PyGameState(db)

    # P0 has cards in deck. initialize_game will draw 6.
    state.initialize_game([565, 1, 1, 1, 1, 1, 1, 1], [1] * 8, [1, 1], [1, 1], [10001], [10001])
    return db, state


def test_card_565_discard_interactivity(env):
    db, state = env

    # Force hand to have 565 at index 0
    state.set_hand_cards(0, [565, 1, 1, 1, 1, 1])

    # Play card 565 to slot 0
    # Phase is Main (4)
    state.phase = 4

    p0 = state.get_player(0)
    print(f"\nBefore play: Phase={state.phase}, Hand={p0.hand}")

    # Action for play from hand: 1000 + hand_idx*100 + slot*10 + choice
    # hand_idx 0 (card 565), slot 0, choice 0
    state.step(1000)

    p0 = state.get_player(0)
    print(f"After play: Phase={state.phase}, Hand={p0.hand}")
    print(f"Stage: {p0.stage}")

    # Check if we are in Response phase (10)
    # If this fails, it means trigger_abilities didn't pause
    assert state.phase == 10
    assert state.pending_card_id == 565

    # Legal actions should include choices for the discard
    actions = state.get_legal_action_ids()  # PyGameState.get_legal_action_ids doesn't take db anymore in bindings
    # AID for choice: 1000... (OnPlay) or 550... (Queued)
    choice_actions = [a for a in actions if (1000 <= a < 2000) or (550 <= a < 1000)]
    if len(choice_actions) < 1:
        print(f"FAILED: Found actions {actions}")
    assert len(choice_actions) >= 1

    # Perform discard (choice 0)
    state.step(choice_actions[0])

    # Should return to Main phase (4)
    assert state.phase == 4

    # Verify hand size decreased (relative to draw) -> 5
    p0 = state.get_player(0)
    assert len(p0.hand) == 5
    assert len(p0.discard) == 1