fs: 实现 超出边界(Fail-Soft) 的 Alpha-Beta 搜索

This commit is contained in:
Calcitem 2020-05-04 14:11:25 +08:00
parent f41c338e29
commit bb50055fda
1 changed files with 18 additions and 15 deletions

View File

@ -739,6 +739,7 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta, Node *no
// 评价值 // 评价值
value_t value; value_t value;
node->value = -VALUE_INFINITE;
// 临时增加的深度,克服水平线效应用 // 临时增加的深度,克服水平线效应用
depth_t epsilon; depth_t epsilon;
@ -850,7 +851,7 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta, Node *no
#endif #endif
if (unlikely(position->phase == PHASE_GAMEOVER) || // 搜索到叶子节点(决胜局面) // TODO: 对哈希进行特殊处理 if (unlikely(position->phase == PHASE_GAMEOVER) || // 搜索到叶子节点(决胜局面) // TODO: 对哈希进行特殊处理
!depth || // 搜索到第0层 depth <= 0 || // 搜索到第0层
unlikely(requiredQuit)) { unlikely(requiredQuit)) {
// 局面评估 // 局面评估
node->value = Evaluation::getValue(st, position, node); node->value = Evaluation::getValue(st, position, node);
@ -978,28 +979,30 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta, Node *no
undoMove(); undoMove();
if (value >= beta) { if (value >= node->value) {
#ifdef TRANSPOSITION_TABLE_ENABLE node->value = value;
hashf = TT::hashfBETA;
#endif
node->value = beta;
goto out;
}
if (value > alpha) { if (value > alpha) {
#ifdef TRANSPOSITION_TABLE_ENABLE #ifdef TRANSPOSITION_TABLE_ENABLE
hashf = TT::hashfEXACT; hashf = TT::hashfEXACT;
#endif #endif
alpha = value; alpha = value;
if (depth == originDepth) { if (depth == originDepth) {
best = m; best = m;
}
}
if (value >= beta) {
#ifdef TRANSPOSITION_TABLE_ENABLE
hashf = TT::hashfBETA;
#endif
node->value = beta;
goto out;
} }
} }
} }
node->value = alpha;
out: out:
#ifdef DEBUG_AB_TREE #ifdef DEBUG_AB_TREE