【发布时间】:2018-04-05 07:30:25
【问题描述】:
我正在使用带有井字游戏、黑白棋等的极小极大算法。
如何在算法中正确添加一个玩家跳过回合的可能性(当没有有效的移动时)?
01 function minimax(node, depth, maximizingPlayer)
02 if depth = 0 or node is a terminal node
03 return the heuristic value of node
04 if maximizingPlayer
05 bestValue := −∞
06 for each child of node
07 v := minimax(child, depth − 1, FALSE)
08 bestValue := max(bestValue, v)
09 return bestValue
10 else (* minimizing player *)
11 bestValue := +∞
12 for each child of node
13 v := minimax(child, depth − 1, TRUE)
14 bestValue := min(bestValue, v)
15 return bestValue
谢谢。
【问题讨论】:
-
应该在图中编码,而不是极小极大算法。
-
这可能取决于游戏,但您通常不会在没有有效动作时输掉吗?这就是你的算法已经实现的。
-
这取决于游戏。以下是黑白棋规则中的一句话:“玩家轮流轮流。如果一个玩家无法做出有效的移动,则将游戏传给另一个玩家。当两个玩家都无法移动时,游戏结束。”
-
然后添加确定 node.Children 的代码,因为必须再次执行该步骤(对于其他玩家)。然后也可以解决“两个玩家”的问题。
-
玩家没有移动的节点只有一个子节点,其棋盘状态不变。孩子还需要表明没有采取任何行动。该指示最初为 0。当没有移动时,它会增加,并在任一玩家移动时重置为 0。如果指示达到 2,则说明双方均未移动,游戏结束。
标签: minimax