Upload folder using huggingface_hub
Browse files- app.py +8 -2
- lichess-bot/remote_engine.py +11 -1
app.py
CHANGED
|
@@ -120,7 +120,7 @@ async def make_move(req: MoveRequest):
|
|
| 120 |
return JSONResponse({'ai_move': None, 'eval': 0.0})
|
| 121 |
|
| 122 |
# MCTS runs 150 simulations
|
| 123 |
-
result = await rust_engine_pool.play(board, chess.engine.Limit(time=req.time_limit), info=chess.engine.
|
| 124 |
ai_move = result.move.uci()
|
| 125 |
|
| 126 |
if "score" in result.info:
|
|
@@ -129,14 +129,20 @@ async def make_move(req: MoveRequest):
|
|
| 129 |
ai_eval = 1.0 if score.mate() > 0 else -1.0
|
| 130 |
else:
|
| 131 |
ai_eval = max(-1.0, min(1.0, score.score() / 1000.0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
except Exception as e:
|
| 134 |
import traceback
|
| 135 |
traceback.print_exc()
|
| 136 |
print(f"Engine error: {repr(e)}")
|
| 137 |
ai_move = None
|
|
|
|
| 138 |
|
| 139 |
-
return JSONResponse({'ai_move': ai_move, 'eval': ai_eval})
|
| 140 |
|
| 141 |
if __name__ == '__main__':
|
| 142 |
import uvicorn
|
|
|
|
| 120 |
return JSONResponse({'ai_move': None, 'eval': 0.0})
|
| 121 |
|
| 122 |
# MCTS runs 150 simulations
|
| 123 |
+
result = await rust_engine_pool.play(board, chess.engine.Limit(time=req.time_limit), info=chess.engine.INFO_ALL)
|
| 124 |
ai_move = result.move.uci()
|
| 125 |
|
| 126 |
if "score" in result.info:
|
|
|
|
| 129 |
ai_eval = 1.0 if score.mate() > 0 else -1.0
|
| 130 |
else:
|
| 131 |
ai_eval = max(-1.0, min(1.0, score.score() / 1000.0))
|
| 132 |
+
|
| 133 |
+
engine_info = {}
|
| 134 |
+
if "depth" in result.info: engine_info["depth"] = result.info["depth"]
|
| 135 |
+
if "nodes" in result.info: engine_info["nodes"] = result.info["nodes"]
|
| 136 |
+
if "nps" in result.info: engine_info["nps"] = result.info["nps"]
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
import traceback
|
| 140 |
traceback.print_exc()
|
| 141 |
print(f"Engine error: {repr(e)}")
|
| 142 |
ai_move = None
|
| 143 |
+
engine_info = {}
|
| 144 |
|
| 145 |
+
return JSONResponse({'ai_move': ai_move, 'eval': ai_eval, 'engine_info': engine_info})
|
| 146 |
|
| 147 |
if __name__ == '__main__':
|
| 148 |
import uvicorn
|
lichess-bot/remote_engine.py
CHANGED
|
@@ -80,8 +80,18 @@ def main():
|
|
| 80 |
response = requests.post(API_URL, json=payload, timeout=30)
|
| 81 |
data = response.json()
|
| 82 |
|
| 83 |
-
if "ai_move" in data:
|
| 84 |
move = data["ai_move"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
print(f"bestmove {move}")
|
| 86 |
else:
|
| 87 |
print("bestmove 0000")
|
|
|
|
| 80 |
response = requests.post(API_URL, json=payload, timeout=30)
|
| 81 |
data = response.json()
|
| 82 |
|
| 83 |
+
if "ai_move" in data and data["ai_move"]:
|
| 84 |
move = data["ai_move"]
|
| 85 |
+
|
| 86 |
+
if "engine_info" in data and data["engine_info"]:
|
| 87 |
+
info = data["engine_info"]
|
| 88 |
+
info_str = "info"
|
| 89 |
+
if "depth" in info: info_str += f" depth {info['depth']}"
|
| 90 |
+
if "nodes" in info: info_str += f" nodes {info['nodes']}"
|
| 91 |
+
if "nps" in info: info_str += f" nps {info['nps']}"
|
| 92 |
+
if info_str != "info":
|
| 93 |
+
print(info_str)
|
| 94 |
+
|
| 95 |
print(f"bestmove {move}")
|
| 96 |
else:
|
| 97 |
print("bestmove 0000")
|