理解 minmax 伪代码

Understanding the minmax pseudocode

我正在自学 minimax 算法,我有几个问题希望有人能回答。

首先在第 05 行 - := 是什么意思?

同样在第 08/14 行,我注意到方法 maxmin 是用两个参数调用的,这个方法 return 是什么? return 是迄今为止找到的最大值还是最小值?有这方面的伪代码示例还是我误解了?

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)returnsbestValuev,以大者为准
  • min(bestValue, v)returnsbestValuev,以较小者为准

由于这是伪代码,我们可以假设您将用来实现它的任何语言都提供函数 maxmin。如果没有,您可以自己轻松实现它们。