我正在自学 minimax 算法,我只是有几个问题希望有人能回答。
首先在第 05 行 - :=
是什么意思?
同样在第 08/14 行,我注意到方法 max
或 min
被调用时带有两个参数,这个方法会返回什么?它会返回到目前为止找到的最大值或最小值吗?有这方面的伪代码示例还是我误解了?
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
最佳答案
-
bestValue := −∞
:将负无穷大(可能的最小数字)分配给bestValue
-
max(bestValue, v)
返回bestValue
或v
, 以较大 为准
-
min(bestValue, v)
返回bestValue
或v
, 以较小 为准
由于这是伪代码,我们可以假设您将用来实现它的任何语言都提供函数 max
和 min
.如果没有,您可以自己轻松实现它们。
关于pseudocode - 理解 minmax 伪代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35721636/