云库可选: 服务支持 cloud 请求参数, 油猴面板加'使用云库'开关(v1.5.0)

This commit is contained in:
AwesomeXiangQi committed 2026-09-13 14:15:28 +08:00
1 parent 77b73554b1
commit d3c667a61c
2 files changed
+30 -14

No files matched your search

+14 -11
View File
@@ -31,20 +31,22 @@ class Service:
await self.engine.quit()
await self.cloud.close()
async def bestmove(self, moves_site, fen=None, movetime=None, depth=None):
async def bestmove(self, moves_site, fen=None, movetime=None, depth=None, req_cloud=None):
moves_ucci = [site_to_ucci(m) for m in moves_site]
fen = fen or fen_from_moves(moves_ucci)
# 1. 云库优先
try:
cloud_hit = await self.cloud.best(fen, moves_count=len(moves_ucci))
except Exception as e:
log.warning('cloud error: %s', e)
cloud_hit = None
if cloud_hit and not depth:
mv, score, note = cloud_hit
return {'ok': True, 'source': 'cloud', 'move': ucci_to_site(mv),
'score': f'cp {score}', 'note': note, 'ms': 0}
# 1. 云库优先(请求可显式关闭; 深度模式强制引擎)
use_cloud = req_cloud if req_cloud is not None else True
if use_cloud and not depth:
try:
cloud_hit = await self.cloud.best(fen, moves_count=len(moves_ucci))
except Exception as e:
log.warning('cloud error: %s', e)
cloud_hit = None
if cloud_hit:
mv, score, note = cloud_hit
return {'ok': True, 'source': 'cloud', 'move': ucci_to_site(mv),
'score': f'cp {score}', 'note': note, 'ms': 0}
# 2. 皮卡鱼兜底
try:
@@ -96,6 +98,7 @@ def make_app(args):
fen=req.get('fen'),
movetime=req.get('movetime'),
depth=req.get('depth'),
req_cloud=req.get('cloud'),
)
return web.json_response(out)
except Exception as e: