何时终止使用 alpha beta 修剪和转置表的迭代加深?

When to terminate iterative deepening with alpha beta pruning and transposition tables?

我如何知道何时可以停止使用 negamax alpha beta p运行ing 和换位表增加迭代加深算法的深度?以下伪代码取自维基页面:

function negamax(node, depth, α, β, color)
 alphaOrig := α

 // Transposition Table Lookup; node is the lookup key for ttEntry
 ttEntry := TranspositionTableLookup( node )
 if ttEntry is valid and ttEntry.depth ≥ depth
     if ttEntry.Flag = EXACT
         return ttEntry.Value
     else if ttEntry.Flag = LOWERBOUND
         α := max( α, ttEntry.Value)
     else if ttEntry.Flag = UPPERBOUND
         β := min( β, ttEntry.Value)
     endif
     if α ≥ β
         return ttEntry.Value
 endif

 if depth = 0 or node is a terminal node
     return color * the heuristic value of node

 bestValue := -∞
 childNodes := GenerateMoves(node)
 childNodes := OrderMoves(childNodes)
 foreach child in childNodes
     val := -negamax(child, depth - 1, -β, -α, -color)
     bestValue := max( bestValue, val )
     α := max( α, val )
     if α ≥ β
         break

 // Transposition Table Store; node is the lookup key for ttEntry
 ttEntry.Value := bestValue
 if bestValue ≤ alphaOrig
     ttEntry.Flag := UPPERBOUND
 else if bestValue ≥ β
     ttEntry.Flag := LOWERBOUND
 else
     ttEntry.Flag := EXACT
 endif
 ttEntry.depth := depth 
 TranspositionTableStore( node, ttEntry )

 return bestValue

这是迭代深化调用:

while(depth < ?)
{
    depth++;
    rootNegamaxValue := negamax( rootNode, depth, -∞, +∞, 1)
}

当然,当我知道游戏中的总步数时,我可以使用 depth < numberOfMovesLeft 作为上限。但是如果没有给出这个信息,我什么时候知道另一个 negamax 调用没有比之前的 运行 更好的结果?我需要在算法中更改什么?

简短的回答是:当你运行没时间(并且换位表与answer/question无关)


这里我假设你的评估函数是合理的(给出了很好的位置近似值)。

将迭代加深与 alpha beta 相结合的主要思想如下:假设您有 15 秒的时间来想出最佳着法。你能搜索多远?我不知道,也没有人知道。您可以尝试搜索到 depth = 8 才发现搜索在 1 秒内完成(因此您浪费了 14 秒的可用时间)。通过反复试验,您发现 depth = 10 会在 13 秒内给出结果。所以你决定一直使用它。但是现在出现了严重错误(您的 alpha beta 不够好,一些职位需要花费太多时间来评估)并且您的结果在 15 秒内还没有准备好。所以你要么随机移动,要么输掉比赛。

为了永远不会发生这种情况,准备好一个好的结果真是太好了。因此,您执行以下操作。获取 depth=1 的最佳结果并存储。找到 depth=2 的最佳结果并覆盖它。等等。不时检查剩余时间,如果它真的接近时间限制 - return 你的最佳选择。

现在您无需担心时间问题,您的方法将给出您迄今为止找到的最佳结果。通过对不同子树的所有这些重新计算,您只会浪费一半的资源(如果您检查整棵树,但在 alpha-beta 中您很可能不会)。额外的好处是,现在您可以在每次深度迭代中从最好到最差重新排序移动,从而使 p运行ing 更具攻击性。