Spaces:
Sleeping
Sleeping
| import numpy as np | |
| import pytest | |
| from engine.game.enums import Phase | |
| from engine.game.game_state import GameState | |
| from engine.models.card import LiveCard, MemberCard | |
| class TestUIActionMapping: | |
| def setup(self): | |
| # Reset GameState databases for clean test | |
| GameState.member_db = {} | |
| GameState.live_db = {} | |
| self.game = GameState() | |
| self.p0 = self.game.players[0] | |
| self.p1 = self.game.players[1] | |
| # Register some sample cards | |
| self.game.member_db[1] = MemberCard( | |
| card_id=1, card_no="M-1", name="M1", cost=1, hearts=np.zeros(7), blade_hearts=np.zeros(7), blades=1 | |
| ) | |
| self.game.live_db[101] = LiveCard(card_id=101, card_no="L-1", name="L1", score=1, required_hearts=np.zeros(7)) | |
| self.game.live_db[102] = LiveCard(card_id=102, card_no="L-2", name="L2", score=1, required_hearts=np.zeros(7)) | |
| def test_stage_selection_range(self): | |
| """Action IDs 560-562 should map to stage slots 0-2.""" | |
| self.game.phase = Phase.MAIN | |
| self.p0.stage[0] = 1 | |
| # Mock a pending choice for member selection | |
| self.game.pending_choices = [("TARGET_MEMBER", {"effect": "tap", "player_id": 0})] | |
| # Action 560 -> Slot 0 | |
| self.game.take_action(560) | |
| assert bool(self.p0.tapped_members[0]) is True | |
| def test_live_zone_target_range(self): | |
| """Action IDs 820-822 should map to live zone slots 0-2.""" | |
| self.p0.live_zone = [101, 102] | |
| self.game.pending_choices = [("TARGET_LIVE", {"effect": "discard", "player_id": 0})] | |
| # Action 820 -> Discard first live card | |
| self.game.take_action(820) | |
| assert 101 in self.p0.discard | |
| assert len(self.p0.live_zone) == 1 | |
| def test_performance_range(self): | |
| """Action IDs 900-902 should trigger performance during performance phase.""" | |
| self.game.phase = Phase.PERFORMANCE_P1 | |
| # Must avoid auto-resolve if no choices, but _execute_action calls _do_performance directly | |
| self.p0.live_zone = [101] | |
| self.p0.live_zone_revealed = [True] | |
| self.game.take_action(900) | |
| # Verify that phase advanced to P2 (or LIVE_RESULT if only one player can perform, but here P2 is next) | |
| assert self.game.phase in (Phase.PERFORMANCE_P2, Phase.LIVE_RESULT) | |
| def test_energy_zone_selection(self): | |
| """Action IDs 830-849 should map to energy zone indices 0-19.""" | |
| self.p0.energy_zone = [1, 2, 3] | |
| self.p0.tapped_energy = np.zeros(64, dtype=bool) | |
| self.game.pending_choices = [("TARGET_ENERGY_ZONE", {"effect": "discard", "player_id": 0})] | |
| # Action 831 -> Discard energy card at index 1 (value 2) | |
| self.game.take_action(831) | |
| assert 2 in self.p0.discard | |
| assert len(self.p0.energy_zone) == 2 | |
| def test_success_lives_selection(self): | |
| """Action IDs 760-819 should map to success lives indices.""" | |
| self.p0.success_lives = [101, 102] | |
| self.game.pending_choices = [("TARGET_SUCCESS_LIVES", {"effect": "place_energy", "player_id": 0})] | |
| # Action 760 -> Move first success live to energy | |
| self.game.take_action(760) | |
| assert 101 in self.p0.energy_zone | |
| assert len(self.p0.success_lives) == 1 | |