首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果Negamax的初始函数调用是最小化根节点而不是最大化,那么Negamax的初始函数调用会是什么样子?

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

Stack Overflow用户
提问于 2019-12-21 16:43:27
回答 1查看 278关注 0票数 4

Negamax通常如下所示:

代码语言:javascript
复制
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

最初的调用是negamax(rootNode, depth, −∞, +∞, 1),如果最大化玩家调用它。

我以最大化玩家调用Negamax的方式实现了Negamax,但是每个rootNode都是最大化玩家的移动方式之一:

代码语言:javascript
复制
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

因为Negamax返回一个值,所以我想要一个board状态(move)。因此,我手动完成了Negamax的第一级操作,这样我就可以解析出最佳的移动位置。但是,我应该在哪些值上调用negamax呢?为了更具有声明性,如果最大化玩家名为negamaxHandlernegamaxHandler应该调用:

代码语言:javascript
复制
negamax(child, depth-1, −∞, +∞, 1)
-negamax(child, depth-1, −∞, +∞, 1)
negamax(child, depth-1, +∞, −∞, -1)
-negamax(child, depth-1, +∞, −∞, -1)

还是别的什么?澄清:

negamaxHandler

  • each顶级调用
  • 最大化玩家调用negamaxHandler中的negamax应该最小化
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-27 08:33:43

正确的函数调用最终为-negamax(child, depth-1, −∞, +∞, -1),尽管需要更改negamaxHandler函数:

代码语言:javascript
复制
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

negamaxHandler被称为negamaxHandler(−∞, +∞, 1)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59438037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档