1
function negamax(node, depth, α, β, color)
    if node is a terminal node or depth = 0
        return color * the heuristic value of node
    else
        foreach child of node
            val := -negamax(child, depth-1, -β, -α, -color)
            {the following if statement constitutes alpha-beta pruning}
            if val≥β
                return val
            if val≥α
                α:=val
        return α

所以如果上面是我的 negamax 代码(从维基百科复制),它的调用如下:

negamax(origin, depth, -inf, +inf, 1)

那么,无论我们用什么深度调用这个函数,这个函数是否总是返回一个正值。这是假设启发式值本身始终为正。

4

1 回答 1

1

是的,如果叶子节点的评价分数是正的,negamax 会返回一个正值。这就是乘以颜色值所完成的,它确保如果有奇数个递归 negamax 调用,总是有一个反否定来反转最终否定。这是因为对于奇数的递归调用,颜色将始终为 -1。如果有偶数个递归调用,所有的否定都会被取消,颜色将为 1,这将不影响返回的值。

请注意,如果您使用 color == -1 调用 negamax(轮到另一方移动),您必须否定该调用才能获得正确的值。那是:

-negamax(origin, depth, -inf, +inf, -1)
于 2012-01-16T07:26:55.197 回答