我在编写Reversi游戏的AI玩家,并决定使用NegaMax或MiniMax方法。伪代码如下:
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 val := -negamax(child, depth-1, -β, -α, -color) {the following if statement constitutes alpha-beta pruning} if val≥β return val if val≥α α:=val return α
但是我需要向这个函数传递Node对象,我该如何创建这个节点呢?比如,如何创建包含所有可能移动的Node状态,然后为Node中的每个可能移动创建子节点?
另外,如果你能帮助解释α和β值…
回答:
Node可能代表一个单一状态。在游戏中,这通常是棋盘的状态(对于Othello来说,就是棋子的位置、当前谁的回合等)。在使用alpha/beta剪枝的游戏中,生成所有下一个状态是可能的,但生成所有可能位置的所有状态则是不现实的。
如果你使用的是Java,那么Node对象可能有一个getChildren()方法,用于从该状态生成所有可能的移动,这些移动本身也是Node对象。
关于α和β值,它们通常初始化为Integer.MIN_VALUE和Integer.MAX_VALUE