LovecaSim / engine /tests /cards /batches /test_verification_batch_12.py
trioskosmos's picture
Upload folder using huggingface_hub
bb3fbf9 verified
import numpy as np
import pytest
from engine.game.enums import Phase
from engine.game.game_state import initialize_game
class TestVerificationBatch12:
@pytest.fixture
def game_state(self):
gs = initialize_game(use_real_data=True)
if not gs.member_db:
pytest.skip("Card data not loaded")
gs.active_player.tapped_energy = np.zeros(20, dtype=bool)
return gs
def get_card_id(self, gs, card_no):
for cid, card in gs.member_db.items():
if card.card_no == card_no:
return cid
for cid, card in gs.live_db.items():
if card.card_no == card_no:
return cid
pytest.fail(f"Card {card_no} not found")
def _test_live_retrieve(self, game_state, card_no):
"""
Generic test for "Retire self -> Retrieve Live from Discard"
Text: 自分の控え室からライブカードを1枚手札に加える (Add 1 Live from WR to Hand)
Cost: Type 5 (Sacrifice Self)
"""
gs = game_state
card_id = self.get_card_id(gs, card_no)
p1 = gs.players[0]
p1.stage[0] = card_id
# Setup discard with a valid Live card
live_id = 999
if live_id not in gs.live_db:
from engine.models.card import LiveCard
gs.live_db[live_id] = LiveCard(live_id, "D", "Dummy", 0, np.zeros(7, dtype=np.int32))
p1.discard = [live_id]
gs.current_player = 0
gs.phase = Phase.MAIN
# Activate (Action 200 for slot 0)
gs._execute_action(200)
# Cost: Retire
assert p1.stage[0] == -1, f"Card {card_no} should be retired (Cost)"
# Effect: Select Live from Discard
assert gs.pending_choices, "Should have pending choice"
choice_type, params = gs.pending_choices[0]
assert choice_type == "SELECT_FROM_DISCARD"
assert live_id in params["cards"]
gs._handle_choice(660) # Select index 0
assert live_id in p1.hand, "Live card should be in hand"
def _test_look3_pick1(self, game_state, card_no):
"""
Generic test for "Look 3, Add 1, Discard Rest" with Hand Discard Cost.
Text: 自分のデッキの上からカードを3枚見る... (Look 3 cards...)
Cost: Discard 1 card from hand (Type 3)
"""
gs = game_state
card_id = self.get_card_id(gs, card_no)
p1 = gs.players[0]
fodder_id = self.get_card_id(gs, "PL!-sd1-001-SD")
p1.hand = [card_id, fodder_id]
# Setup Deck
deck_ids = [901, 902, 903] # 3 Dummy IDs
p1.main_deck = deck_ids + [888] * 5
gs.current_player = 0
gs.phase = Phase.MAIN
gs._execute_action(1) # Play Card
# Verify Cost: Discard from Hand
assert gs.pending_choices, "Expected pending choice (Cost)"
choice_type, params = gs.pending_choices[0]
# We assume strict compliance: Cost Type 3 = TARGET_HAND
if choice_type == "TARGET_HAND" and params.get("reason") == "cost":
assert fodder_id in p1.hand
# Select fodder (index 0 if card_id played, or index 0 of remaining?)
# Played card is removed. Hand has [fodder]. Index 0.
gs._handle_choice(500)
else:
pytest.fail(f"Expected Discard Cost (TARGET_HAND), got {choice_type}")
# Verify Effect: Look 3, Pick 1
assert gs.pending_choices
choice_type, params = gs.pending_choices[0]
assert "SELECT" in choice_type # SELECT_FROM_LIST usually for Look & Choose
assert len(params["cards"]) == 3
# Pick 2nd card (902)
target_pick = params["cards"][1]
gs._handle_choice(601) # Index 1
assert target_pick in p1.hand
# Discard should contain: 1 (Cost) + 2 (Unpicked) = 3
assert len(p1.discard) == 3
def test_pls_bp2_009_p_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!S-bp2-009-P")
def test_pls_bp2_009_r_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!S-bp2-009-R")
def test_pls_pb1_004_p_plus_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!S-pb1-004-P+")
def test_pls_pb1_004_r_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!S-pb1-004-R")
def test_plsp_bp1_011_p_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!SP-bp1-011-P")
def test_plsp_bp1_011_r_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!SP-bp1-011-R")
def test_plsp_pb1_018_n_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!SP-pb1-018-N")
def test_plsp_sd1_006_sd_live_retrieve(self, game_state):
self._test_live_retrieve(game_state, "PL!SP-sd1-006-SD")
def test_pl_sd1_016_sd_look3_pick1(self, game_state):
self._test_look3_pick1(game_state, "PL!-sd1-016-SD")
def test_pln_pr_004_pr_look3_pick1(self, game_state):
self._test_look3_pick1(game_state, "PL!N-PR-004-PR")