Negamax - 玩家移动两次

发布于 2024-12-25 05:43:13 字数 571 浏览 4 评论 0原文

如果满足条件,同一玩家会移动,您如何处理这种游戏?

我尝试过这样的事情,但我认为这不太正确:

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
            if (condition is met) // the same player moves
               val := negamax(child, depth-1, α, β, color)
            else
               val := -negamax(child, depth-1, -β, -α, -color)
            if val≥β
                return val
            if val≥α
                α:=val
        return α

How do you handle games where, if a condition is met, the same player moves ?

I tried something like this but I don't think it's quite right:

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
            if (condition is met) // the same player moves
               val := negamax(child, depth-1, α, β, color)
            else
               val := -negamax(child, depth-1, -β, -α, -color)
            if val≥β
                return val
            if val≥α
                α:=val
        return α

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

还给你自由 2025-01-01 05:43:13

不要尝试为此改变极小极大算法本身,而是修改游戏表示来适应。基本上有两种解决方案:

  1. 将单个玩家的一系列动作表示为一步。当游戏很简单时这会起作用,但并不总是如此。我为一款游戏编写了一个 AI 引擎,其中生成这棵树(在游戏规则中被描述为一个“移动”)是 PSPACE 困难的(并且对于真实游戏来说 n 非常大),这意味着它在计算上不可行。另一方面,如果以这种方式建模对于您的特定游戏来说很容易,那么就这样做
  2. 。 将一个玩家所做的动作序列表示为交替动作的动作序列,其中另一个玩家做任何事情。也就是说,只要满足您的条件,您就向游戏状态添加一条信息,以便其他玩家可以做出的唯一动作不会改变状态。这个方法在数学上是正确的,当我使用它时,它在实践中效果很好。唯一需要记住的复杂性是,如果您使用迭代加深,您将在评估一个玩家移动的游戏树时连续多次。 其他哈希一起使用的存储启发式时,您可能还需要小心

在设计与 转置表 和我不知道的文献中的 讨论您的特定问题。当我想出上面的解决方案 2 时,我感觉很聪明,但我怀疑许多其他人也发明了同样的技巧。

我应该说,正确处理极小极大系列是出乎意料的困难。用高级语言设计游戏搜索人工智能时的一个技巧是在更简单的游戏(缩小棋盘尺寸、使用井字游戏等)上测试您的搜索算法,以确保正确性。如果游戏足够小,你可以。通过手工玩游戏来确保其结果有意义;b.测试高级算法,例如 negascout,确保它们给出与 naive negamax 相同的答案。尝试将具有游戏特定行为(评估函数、棋盘表示、搜索和存储启发式等)的代码远离执行树搜索的代码也是一个好主意。

Dont try changing the minimax algorithm itself for this, instead modify the game representation to accommodate. There are basically two solutions:

  1. Represent the sequences of moves made by a single player as one move. This works when the game is simple, but wont always. I wrote an AI engine for a game where generating this tree (described as one "move" in the game rules) is PSPACE hard (and had a very large n for real games) meaning it was not computationally feasible. On the other-hand, if modeling it this way is easy for your particular game, do it that way
  2. Represent the sequences of moves made by one player as a sequences of moves alternating moves, where the other player does do anything. That is, you add a piece of information to the game state whenever your condition is met, such that the only move the other player can make does not change the state. This method is mathematically correct, and when I used it worked pretty well in practice. The only complexity to keep in mind is that if you use iterative deepening you will under evaluate game trees where one player moves many times in a row. You also may need to be careful when designing storage heuristics to be used with the transposition table and other hashes

I know of no literature that discuses your particular problem. I felt clever when I came up with solution 2 above, but I suspect many other people have invented the same trick.

I should say, getting the minimax family right is surprisingly hard. A trick when designing game search AIs in high level languages is to test your search algorithms on simpler games (reduced board size, use tic-tac-toe, etc) to ensure correctness. If the game is small engough you can a. make sure its results make sense by playing the game out by hand and b. test advanced algorithms like negascout by making sure they give the same answer as naive negamax. It is also a good idea to try to keep code with game specific behavior (evaluation functions, board representations, search and storage heuristics, etc) away from the code that does tree searches.

弥繁 2025-01-01 05:43:13

在 negamax 中,您正在探索一个树结构,其中每个节点都有与玩家的移动相对应的子节点。如果在某些情况下,玩家可以移动两次,您可能会将该玩家的“移动”视为该玩家所做的两次移动序列。更一般地说,您应该将当前游戏状态的子级视为当前玩家在轮到他们后可以进入游戏的所有可能状态。这包括一步移动可达到的所有游戏状态,以及如果玩家能够在一回合内进行两步移动则可通过两步移动达到的所有游戏状态。因此,您应该保持 negamax 的基本逻辑不变,但更新代码以生成后继状态,以处理单个玩家可以移动两次的情况。

希望这有帮助!

In negamax, you are exploring a tree structure in which each node has children corresponding to the moves made by a player. If in some case a player can move twice, you would probably want to think of the "move" for that player as the two-move sequence that player makes. More generally, you should think of the children of the current game state as all possible states that the current player can get the game into after their turn. This includes all game states reachable by one move, plus all the game states reachable in two moves if the player is able to make two moves in one turn. You should, therefore, leave the basic logic of negamax unchanged, but update your code to generate successor states to handle the case where a single player can move twice.

Hope this helps!

两人的回忆 2025-01-01 05:43:13

当条件满足时,不要减少深度。

When condition is met, don't decrement depth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文