理解minmax伪代码

3
我正在自学极小化极大算法,希望有人能回答我几个问题。
首先,在第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

1
:= 是一种赋值运算。 - Maroun
1
“请问‘这是否有伪代码示例,还是我的理解有误?’的意思是什么?它已经是伪代码了。” - Luke
1个回答

3
  • bestValue := −∞: 将负无穷(最小可能的数)赋值给bestValue
  • max(bestValue, v) 返回 bestValue 或者 v,取决于哪一个更
  • min(bestValue, v) 返回 bestValue 或者 v,取决于哪一个更

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接