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

from engine.game.game_state import GameState
from engine.models.ability import Ability, Effect, EffectType, TargetType, TriggerType
from engine.models.card import MemberCard


def test_logging_ability_resolution():
    gs = GameState()
    # gs.initialize_game() # Does not exist
    gs.member_db = {}
    gs.live_db = {}
    # gs._init_jit_arrays() # Will be called later after adding card
    p0 = gs.players[0]

    # Setup: Create a card with "On Play: Draw 1"
    # We mock it in member_db manually for isolation
    card_id = 9900
    ability_text = "Draw 1 card."
    card = MemberCard(
        card_id=card_id,
        card_no="LOG-TEST-001",
        name="Logging Honoka",
        # rarity="R", # Removed invalid field
        cost=1,
        # color="Pink", # Removed invalid field? Wait, check definition. Color is implicit triggers?
        # Actually standard MemberCard doesn't check color.
        # source="Test", # Invalid
        # grading="None", # Invalid
        blades=1,
        hearts=np.zeros(7, dtype=int),
        blade_hearts=np.zeros(7, dtype=int),
        abilities=[
            Ability(
                trigger=TriggerType.ON_PLAY,
                effects=[Effect(EffectType.DRAW, 1, TargetType.SELF, {})],
                conditions=[],
                costs=[],
                raw_text=ability_text,
            )
        ],
    )
    gs.live_db = {}

    # CRITICAL: Set Class-level DB for JIT initialization
    GameState.member_db[card_id] = card
    gs.member_db = GameState.member_db  # Ensure instance sees it too if shadowed elsewhere

    # Give energy
    p0.energy_zone = [2001, 2002]  # 2 energy
    p0.tapped_energy[:] = False  # Reset all to False

    # Add card to hand logic (hack force)
    p0.hand = [card_id]
    p0.hand_added_turn = [1]

    # CRITICAL: Re-initialize JIT arrays because we added a new high-ID card
    gs._init_jit_arrays()

    # Play the card (Action ID 1 = Play hand[0] to Stage[0])
    # Action ID: 1 + (0*3) + 0 = 1

    # We need to bypass get_legal_actions mask check for pure unit test or ensure it's legal
    # It should be legal (cost 1, have 2 energy)

    # Setup masks
    gs.turn_number = 1
    gs.phase = gs.phase.MAIN  # 4

    gs.verbose = True
    print(f"Legal mask for Action 1: {gs.get_legal_actions()[1]}")

    # Execute action
    gs = gs.step(1)

    # Check Logs
    print("\n--- Rule Log ---")
    for entry in gs.rule_log:
        print(entry)

    # Verify specific log contents
    found_resolution = False
    for entry in gs.rule_log:
        if "Logging Honoka" in entry and "Resolving DRAW" in entry:
            found_resolution = True
            # Also check if text snippet is there
            assert "Draw 1 card" in entry or "Draw 1 card"[:20] in entry

    assert found_resolution, "Log should contain source name and effect type"