Spaces:
Running
Running
update app.py
Browse files
app.py
CHANGED
|
@@ -95,12 +95,31 @@ def get_move(board_text, player=None):
|
|
| 95 |
elif player == "2":
|
| 96 |
game.move_count = 1
|
| 97 |
else:
|
| 98 |
-
# infer from
|
| 99 |
-
game.move_count = 0 if
|
| 100 |
game._cached_matrix = None
|
| 101 |
searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5)
|
| 102 |
visits, _ = searcher.search_with_time_budget(game, 1.0)
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
move = move_to_uci(best_move)
|
| 105 |
print(f"[DEBUG] get_move OK: FEN={board_text} -> {move}")
|
| 106 |
return move
|
|
|
|
| 95 |
elif player == "2":
|
| 96 |
game.move_count = 1
|
| 97 |
else:
|
| 98 |
+
# Default: infer from FEN suffix or assume white
|
| 99 |
+
game.move_count = 0 if " w" in board_text.lower() else 1
|
| 100 |
game._cached_matrix = None
|
| 101 |
searcher = MCVSSearcher(None, None, zonedb, lambda_zone=1.0, k_zone=5)
|
| 102 |
visits, _ = searcher.search_with_time_budget(game, 1.0)
|
| 103 |
+
|
| 104 |
+
# Debug: show how many legal moves and visits
|
| 105 |
+
legal_moves = list(game.legal_moves())
|
| 106 |
+
print(f"[DEBUG] legal moves count: {len(legal_moves)}")
|
| 107 |
+
if legal_moves:
|
| 108 |
+
print(f"[DEBUG] sample legal move: {legal_moves[0] if len(legal_moves) > 0 else None}")
|
| 109 |
+
print(f"[DEBUG] visits count: {len(visits)}")
|
| 110 |
+
if visits:
|
| 111 |
+
print(f"[DEBUG] sample visit key: {next(iter(visits))}")
|
| 112 |
+
|
| 113 |
+
# Safely pick a move
|
| 114 |
+
if visits:
|
| 115 |
+
best_move = max(visits, key=visits.get)
|
| 116 |
+
else:
|
| 117 |
+
if not legal_moves:
|
| 118 |
+
raise ValueError("get_move: No legal moves in position.")
|
| 119 |
+
# Fallback: use first legal move
|
| 120 |
+
best_move = legal_moves[0]
|
| 121 |
+
print(f"[WARNING] visits empty; using fallback move: {best_move}")
|
| 122 |
+
|
| 123 |
move = move_to_uci(best_move)
|
| 124 |
print(f"[DEBUG] get_move OK: FEN={board_text} -> {move}")
|
| 125 |
return move
|