Spaces:
Running
Running
| import numpy as np | |
| from engine.game.enums import Phase | |
| from engine.game.game_state import GameState | |
| from engine.models.card import LiveCard, MemberCard | |
| def test_multiple_live_selection_and_discard(): | |
| print("\n--- Starting Multiple Live Selection Test ---") | |
| gs = GameState() | |
| m1 = MemberCard( | |
| card_id=1, | |
| card_no="M1", | |
| name="Member 1", | |
| cost=1, | |
| hearts=np.array([2, 0, 0, 0, 0, 0, 0]), | |
| blade_hearts=np.zeros(7, dtype=np.int32), | |
| blades=0, | |
| img_path="m1.png", | |
| ) | |
| gs.member_db = {1: m1} | |
| gs.live_db = { | |
| 100: LiveCard( | |
| card_id=100, | |
| card_no="100", | |
| name="Live A", | |
| img_path="a.png", | |
| score=1, | |
| required_hearts=np.array([1, 0, 0, 0, 0, 0, 0]), | |
| ), | |
| 101: LiveCard( | |
| card_id=101, | |
| card_no="101", | |
| name="Live B", | |
| img_path="b.png", | |
| score=1, | |
| required_hearts=np.array([1, 0, 0, 0, 0, 0, 0]), | |
| ), | |
| } | |
| p = gs.players[0] | |
| p.stage[1] = 1 | |
| p.live_zone = [100, 101] | |
| print(f"Pre-performance hearts: {p.get_total_hearts(gs.member_db)}") | |
| gs.phase = Phase.PERFORMANCE_P1 | |
| gs._do_performance(0) | |
| print(f"Passed lives: {p.passed_lives}") | |
| assert len(p.passed_lives) == 2 | |
| gs.phase = Phase.LIVE_RESULT | |
| gs._do_live_result() | |
| print(f"Pending choices: {[c[0] for c in gs.pending_choices]}") | |
| assert len(gs.pending_choices) > 0 | |
| assert gs.pending_choices[0][0] == "SELECT_SUCCESS_LIVE" | |
| # Select Live A (Index 0 in [100, 101]) | |
| gs.take_action(600) | |
| print(f"DEBUG: Success lives: {p.success_lives}") | |
| print(f"DEBUG: Passed lives: {p.passed_lives}") | |
| print(f"DEBUG: Discard pile: {p.discard}") | |
| print(f"DEBUG: Pending choices after selection: {[c[0] for c in gs.pending_choices]}") | |
| assert 100 in p.success_lives | |
| assert 101 not in p.success_lives | |
| # 101 should be in discard because SELECT_SUCCESS_LIVE logic discards others | |
| assert 101 in p.discard | |
| # 101 should be in discard because SELECT_SUCCESS_LIVE logic discards others | |
| assert 101 in p.discard | |
| # With high-throughput optimization, the game auto-advances after selection. | |
| # It skips the "CONTINUE_LIVE_RESULT" confirmation. | |
| # Check that we advanced to next turn's ENERGY phase (via Active Phase) | |
| # The phase transition chain is: LIVE_RESULT -> _finish_live_result -> _do_active_phase (ENERGY) | |
| assert gs.phase == Phase.ENERGY, "Should advance to Active -> Energy Phase" | |
| # Verify no pending choices | |
| assert len(gs.pending_choices) == 0 | |
| print("Test passed!") | |
| if __name__ == "__main__": | |
| try: | |
| test_multiple_live_selection_and_discard() | |
| except Exception: | |
| import traceback | |
| traceback.print_exc() | |
| exit(1) | |