import os import sys # Ensure we can import engine sys.path.append(os.getcwd()) import engine_rust def setup_game(): # Load DB 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_live_start_interactivity(): state, db = setup_game() # Init game members = [249] * 48 lives = [10001] * 12 energy = [20001] * 12 state.initialize_game(members, members, energy, energy, lives, lives) # Setup state via new methods KOTORI_ID = 249 state.set_stage_card(0, 0, KOTORI_ID) state.set_hand_cards(0, [KOTORI_ID]) state.set_live_card(0, 0, 10001, True) # Reveal it to trigger 11.4 state.current_player = 0 state.phase = 6 # PERFORMANCE_P1 print("Starting Performance Phase (Triggering OnLiveStart)...") # Rule: step(0) progresses state.step(0) print(f"Phase after step: {state.phase}") # Dump ALL logs print("\n--- FULL ENGINE LOG ---") for line in state.rule_log: print(line) print("--- END LOG ---\n") if state.phase == 10: # RESPONSE print(f"Pending Card ID: {state.pending_card_id}") print(f"Pending Ab Idx: {state.pending_ab_idx}") # Take action 560 (Pink) print("Selecting Pink color (Action 560)...") state.step(560) if state.phase == 10: print("Paused for second choice (SELECT_MODE).") state.step(560) # Pick first heart mode print(f"Phase after second choice: {state.phase}") # Verify log log = state.rule_log print("\n--- TEST LOG SUMMARY ---") for line in log: if "(On Live Start)" in line or "Pausing" in line: print(line) trigger_count = sum(1 for line in log if "(On Live Start)" in line) print(f"On Live Start trigger count in log: {trigger_count}") p0_final = state.get_player(0) print(f"Hand size after discard: {len(p0_final.hand)}") # Assertions assert trigger_count == 1, f"Expected 1 trigger, found {trigger_count}." print("\nREPRODUCTION TEST PASSED") if __name__ == "__main__": try: test_live_start_interactivity() except Exception as e: print(f"\nREPRODUCTION TEST FAILED: {e}") import traceback traceback.print_exc() sys.exit(1)