from engine.game.game_state import GameState from engine.models.opcodes import Opcode def test_recover_live_opcode(): state = GameState() p = state.players[0] p.discard = [100, 1001, 200] # Member, Live, Member # RECOVER_LIVE (v=1) seg = [Opcode.RECOVER_LIVE, 1, 0, 0] state._resolve_effect_opcode(Opcode.RECOVER_LIVE, seg, {}) assert 1001 in p.hand assert 1001 not in p.discard assert len(p.discard) == 2 def test_recover_member_opcode(): state = GameState() p = state.players[0] p.discard = [100, 1001, 201] # Member, Live, Member # RECOVER_MEMBER (v=1) seg = [Opcode.RECOVER_MEMBER, 1, 0, 0] state._resolve_effect_opcode(Opcode.RECOVER_MEMBER, seg, {}) assert 201 in p.hand assert 201 not in p.discard assert len(p.discard) == 2 def test_swap_cards_opcode(): state = GameState() p = state.players[0] p.hand = [1, 2, 3] p.hand_added_turn = [0, 0, 0] p.main_deck = [4, 5, 6] # SWAP_CARDS (v=2) seg = [Opcode.SWAP_CARDS, 2, 0, 0] state._resolve_effect_opcode(Opcode.SWAP_CARDS, seg, {}) assert len(p.hand) == 3 assert 1 not in p.hand assert 2 not in p.hand assert 4 in p.hand assert 5 in p.hand assert len(p.discard) == 2 def test_add_to_hand_deck_opcode(): state = GameState() p = state.players[0] p.main_deck = [10, 11] # ADD_TO_HAND (v=1, a=2) seg = [Opcode.ADD_TO_HAND, 1, 2, 0] state.current_player = 0 state._resolve_effect_opcode(Opcode.ADD_TO_HAND, seg, {}) p0 = state.players[0] print(f"DEBUG: Player 0 Hand: {p0.hand}") print(f"DEBUG: Player 0 Deck: {p0.main_deck}") assert 10 in p0.hand assert len(p0.main_deck) == 1 def test_flavor_action_and_modal_answer(): state = GameState() # FLAVOR_ACTION (Opcode) seg = [Opcode.FLAVOR_ACTION, 0, 0, 0] state._resolve_effect_opcode(Opcode.FLAVOR_ACTION, seg, {}) assert len(state.pending_choices) == 1 choice_type, params = state.pending_choices[0] assert choice_type == "MODAL_CHOICE" assert params["title"] == "何が好き?" # Opponent answers choice 1 (Singing) # MODAL_CHOICE actions start at 800 state._handle_choice(801) assert state.last_choice_answer == 1 # CHECK_MODAL_ANSWER (v=1) seg_cond = [Opcode.CHECK_MODAL_ANSWER, 1, 0, 4] # v=1, comp=EQ (4) res = state._resolve_condition_opcode(Opcode.CHECK_MODAL_ANSWER, seg_cond, {}) assert res is True # CHECK_MODAL_ANSWER (v=2) seg_cond2 = [Opcode.CHECK_MODAL_ANSWER, 2, 0, 4] # v=2, comp=EQ (4) res2 = state._resolve_condition_opcode(Opcode.CHECK_MODAL_ANSWER, seg_cond2, {}) assert res2 is False