Negamax总是应该返回正值吗?

时间:2012-01-16 06:40:03

标签: recursion artificial-intelligence minimax

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)

然后,无论我们将函数称为什么深度,此函数总是会返回正值。这假设启发式值本身总是正的。

1 个答案:

答案 0 :(得分:1)

是的,如果叶节点的评估分数为正,则negamax将返回正值。这就是颜色值的乘法所实现的,它确保如果存在奇数个递归的negamax调用,则始终存在反向否定来反转最终的否定。这是因为奇数个递归调用,颜色总是-1。如果存在偶数个递归调用,则所有否定都将被取消,颜色将为1,这将使返回的值不受影响。

请注意,如果您使用color == -1调用negamax(另一方需要移动),则必须取消该调用才能获得正确的值。那就是:

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