LovecaSim / engine /tests /logic /test_discard_fix.py
trioskosmos's picture
Upload folder using huggingface_hub
bb3fbf9 verified
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