简体   繁体   English

如果 Negamax 的初始函数调用是最小化根节点而不是最大化,它会是什么样子?

[英]What would Negamax' initial function call look like were it to minimize root node rather than maximize?

Negamax typically looks like the below: Negamax 通常如下所示:

function negamax(node, depth, α, β, color) is
    if depth = 0 or node is a terminal node then
        return color × the heuristic value of node
    childNodes := generateMoves(node)
    childNodes := orderMoves(childNodes)
    value := −∞
    foreach child in childNodes do
        value := max(value, −negamax(child, depth − 1, −β, −α, −color))
        α := max(α, value)
        if α ≥ β then
            break (* cut-off *)
    return value

And the initial call is negamax(rootNode, depth, −∞, +∞, 1) if the maximizing player called it.如果最大化玩家调用它,初始调用是negamax(rootNode, depth, −∞, +∞, 1)

I've implemented Negamax in a way where the maximizing player calls it, but each rootNode is one of the maximizing players moves:我已经以最大化玩家调用它的方式实现了 Negamax,但每个rootNode都是最大化玩家移动之一:

function negamaxHandler() is
    bestValue := −∞
    bestNode := null
    childNodes := generateMoves(currentGameState)
    foreach child in childNodes do
        value := negamax(child, depth-1, ???, ???, ???)
        if value > bestValue then
            bestValue := value
            bestNode := child
    return bestNode

Because Negamax returns a value, I instead want a board state (move).因为 Negamax 返回一个值,所以我想要一个棋盘状态(移动)。 So I do the first level of Negamax manually so I can parse where the best move is.所以我手动完成了 Negamax 的第一级,这样我就可以解析出最佳移动的位置。 But for what values should I call negamax on?但是对于什么值我应该调用negamax呢? To be more declarative, if maximizing player called negamaxHandler , should negamaxHandler call:为了更具说明性,如果最大化名为negamaxHandler播放器,则应negamaxHandler调用:

negamax(child, depth-1, −∞, +∞, 1)
-negamax(child, depth-1, −∞, +∞, 1)
negamax(child, depth-1, +∞, −∞, -1)
-negamax(child, depth-1, +∞, −∞, -1)

Or something else?或者是其他东西? To clarify:澄清:

  • maximizing player calls negamaxHandler最大化玩家调用negamaxHandler
  • each top level call to negamax in negamaxHandler should minimize negamax中对negamax每个顶级调用negamaxHandler应该最小化

The correct function call ended up being -negamax(child, depth-1, −∞, +∞, -1) , although the negamaxHandler function needed to be changed:正确的函数调用最终是-negamax(child, depth-1, −∞, +∞, -1) ,尽管需要更改negamaxHandler函数:

function negamaxHandler(α, β, color) is
    bestValue := −∞
    bestNode := null
    childNodes := generateMoves(currentGameState)
    foreach child in childNodes do
        value := -negamax(child, depth-1, -β, -α, -color)
        if value > bestValue then
            bestValue := value
            bestNode := child
        α := max(bestValue, α)
        if α ≥ β then
           break
    return bestNode

With negamaxHandler being called as negamaxHandler(−∞, +∞, 1) . negamaxHandler被称为negamaxHandler(−∞, +∞, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM