Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| # Ensure we can import engine | |
| sys.path.append(os.getcwd()) | |
| import engine_rust | |
| def setup_game(): | |
| db_path = "engine/data/cards_compiled.json" | |
| with open(db_path, "r", encoding="utf-8") as f: | |
| cards_data_raw = f.read() | |
| db = engine_rust.PyCardDatabase(cards_data_raw) | |
| state = engine_rust.PyGameState(db) | |
| return state, db | |
| def test_ai_freeze_fix(): | |
| state, db = setup_game() | |
| # Init game with a card that has an OnLiveStart choice | |
| KOTORI_ID = 249 | |
| members = [KOTORI_ID] * 48 | |
| lives = [10001] * 12 | |
| energy = [20001] * 12 | |
| state.initialize_game(members, members, energy, energy, lives, lives) | |
| # Setup state to trigger OnLiveStart | |
| state.set_stage_card(0, 0, KOTORI_ID) | |
| state.set_live_card(0, 0, 10001, True) # Revealed | |
| state.current_player = 0 | |
| state.phase = 6 # PERFORMANCE_P1 | |
| print(f"Initial Phase: {state.phase}") | |
| # Step to trigger OnLiveStart and enter Response phase | |
| state.step(0) | |
| print(f"Phase after step(0): {state.phase}") | |
| if state.phase != 10: # Phase::Response | |
| print("FAILED to reach Response phase. Checking logs...") | |
| for line in state.rule_log: | |
| print(line) | |
| return | |
| print(f"Pending Card ID: {state.pending_card_id}") | |
| # Get legal actions | |
| legal_actions = state.get_legal_action_ids() | |
| print(f"Legal Action IDs: {legal_actions}") | |
| # Test 1: Verify integrated_step works and doesn't freeze | |
| # We'll use action 0 for integrated_step (MCTS mode) | |
| print("\nAttempting integrated_step (MCTS Mode)...") | |
| # This calls step_opponent_mcts if it's player 1's turn or interactive. | |
| # Wait, current_player is 0. integrated_step(0, ...) should call step(db, 0). | |
| # But Phase 10 is interactive. | |
| # Let's switch player to 1 to simulate AI turn. | |
| # state.current_player = 1 # Not writable? Let's check. | |
| # Actually, integrated_step simulates until PLAYER 0's turn. | |
| # If it's already player 0's turn, it just calls step(action) once. | |
| # Let's try to pass a choice via step | |
| if 560 in legal_actions: | |
| print("Selecting Pink color (Action 560)...") | |
| state.step(560) | |
| print(f"Phase after step(560): {state.phase}") | |
| if state.phase == 10: | |
| print("Selecting first mode (Action 560)...") | |
| state.step(560) | |
| print(f"Phase after second step: {state.phase}") | |
| print("\nVERIFICATION SUCCESSFUL") | |
| if __name__ == "__main__": | |
| try: | |
| test_ai_freeze_fix() | |
| except Exception as e: | |
| print(f"\nVERIFICATION FAILED: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |