全程云库模式(cloud_always) + 修正 chessdb 分数口径为行棋方视角(去掉多余翻转); 油猴 v1.6.0 加'全程'开关

This commit is contained in:
AwesomeXiangQi committed 2026-09-13 14:22:05 +08:00
1 parent 06747bf76c
commit 1ed6a176cb
3 files changed
+32 -18

No files matched your search

+8 -10
View File
@@ -67,22 +67,20 @@ class CloudBook:
self._cache[fen] = (now + CACHE_TTL, result)
return result
async def best(self, fen, moves_count=0):
"""返回 (move, score_mover, depth_note)。
async def best(self, fen, moves_count=0, any_score=False):
"""返回 (move, score_mover, note)。
云库分数为红方视角; 轮黑时取负。分数不足 min_score 时放弃(交给引擎)。
moves_count 用于开局阶段放宽采纳阈值(前 8 回合云库几乎必赢)。
实测 chessdb 的 score 就是行棋方视角(与皮卡鱼 UCI 口径一致), 不需翻转。
any_score=True(全程云库): 无条件采纳云库最佳着法。
否则: 开局(≤16步)直接采纳, 中后局要求分数 ≥ min_score。
"""
entries = await self.query_all(fen)
if not entries:
return None
side_is_red = (fen.split()[1] == 'w')
sign = 1 if side_is_red else -1
scored = [(mv, sign * sc) for mv, sc in entries]
scored.sort(key=lambda x: -x[1])
scored = sorted(entries, key=lambda x: -x[1])
mv, sc = scored[0]
# 开局阈值低(云库碾压引擎), 中后局要求云库分足够好
threshold = self.min_score if moves_count >= 16 else 0
threshold = (-10 ** 9) if any_score else (
self.min_score if moves_count >= 16 else 0)
if sc < threshold:
return None
return mv, sc, f'{len(scored)}候选'
+8 -4
View File
@@ -31,15 +31,18 @@ class Service:
await self.engine.quit()
await self.cloud.close()
async def bestmove(self, moves_site, fen=None, movetime=None, depth=None, req_cloud=None):
async def bestmove(self, moves_site, fen=None, movetime=None, depth=None,
req_cloud=None, cloud_always=None):
moves_ucci = [site_to_ucci(m) for m in moves_site]
fen = fen or fen_from_moves(moves_ucci)
# 1. 云库优先(请求可显式关闭; 深度模式强制引擎)
# 1. 云库优先(请求可显式关闭; 全程云库模式无视分数门槛和深度强制)
use_cloud = req_cloud if req_cloud is not None else True
if use_cloud and not depth:
if use_cloud:
try:
cloud_hit = await self.cloud.best(fen, moves_count=len(moves_ucci))
cloud_hit = await self.cloud.best(
fen, moves_count=len(moves_ucci),
any_score=bool(cloud_always))
except Exception as e:
log.warning('cloud error: %s', e)
cloud_hit = None
@@ -99,6 +102,7 @@ def make_app(args):
movetime=req.get('movetime'),
depth=req.get('depth'),
req_cloud=req.get('cloud'),
cloud_always=req.get('cloud_always'),
)
return web.json_response(out)
except Exception as e: