Spaces:
Sleeping
Sleeping
File size: 2,162 Bytes
463f868 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import random
import time
import engine_rust
def debug_game(seed=1238, sims=1000):
print(f"=== Debugging Matching Game 5: Seed={seed}, Sims={sims} ===")
db_path = "data/cards_compiled.json"
with open(db_path, "r", encoding="utf-8") as f:
db_json = f.read()
db = engine_rust.PyCardDatabase(db_json)
member_pool = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
live_pool = [1000, 1001, 1002, 1003, 1004, 1005]
game = engine_rust.PyGameState(db)
rng = random.Random(seed)
p0_deck = [rng.choice(member_pool) for _ in range(40)] + [rng.choice(live_pool) for _ in range(10)]
p1_deck = [rng.choice(member_pool) for _ in range(40)] + [rng.choice(live_pool) for _ in range(10)]
p_energy = [200] * 12
p0_live_ids = [rng.choice(live_pool) for _ in range(3)]
p1_live_ids = [rng.choice(live_pool) for _ in range(3)]
game.initialize_game_with_seed(p0_deck, p1_deck, p_energy, p_energy, p0_live_ids, p1_live_ids, seed)
step_count = 0
while not game.is_terminal() and step_count < 500:
cp = game.current_player
ph = game.phase
start = time.time()
if cp == 0:
legal_mask = game.get_legal_actions()
legal_indices = [idx for idx, val in enumerate(legal_mask) if val]
if not legal_indices:
game.step(0)
else:
if game.phase < 1:
action = 0 if rng.random() < 0.2 else rng.choice(legal_indices)
else:
action = rng.choice(legal_indices)
game.step(int(action))
dur = time.time() - start
if step_count % 50 == 0:
print(f"Step {step_count}: P0 Random took {dur:.4f}s")
else:
game.step_opponent_mcts(sims)
dur = time.time() - start
if dur > 1.0 or step_count % 10 == 0:
print(f"Step {step_count}: P1 MCTS ({sims}) took {dur:.2f}s (Phase {ph})")
step_count += 1
print(f"Winner: {game.get_winner()} in {step_count} steps")
if __name__ == "__main__":
debug_game()
|