我想用 minimax 算法实现 PacMan 游戏,但我不能流利地理解算法的含义。我写了这段代码
public MOVE miniMax(Game game,Node[] nodes,int depth,Boolean pacMan){
int value;
MOVE thisMove;
int bestValue;
int score=0;
EnumMap<MOVE, MOVE[]> possibleMoves = nodes[game.getPacmanCurrentNodeIndex()].allPossibleMoves;
MOVE[] moves = possibleMoves.get(MOVE.NEUTRAL);
if(depth == 0)
score = evaluationFunction(game);
if(pacMan){
bestValue = -INF;
for(int i=0;i<moves.length;i++){
game.copy();
game.updatePacMan(moves[i]);
thisMove= miniMax(game,nodes,depth-1,Boolean.FALSE);
//bestValue = Math.max(bestValue, value);
}
return thisMove;
}else{
bestValue = INF;
for(int i=0;i<moves.length;i++){
game.copy();
game.updatePacMan(moves[i]);
thisMove= miniMax(game,nodes,depth-1,Boolean.TRUE);
//bestValue = Math.min(bestValue, value);
}
//return bestValue;
return thisMove;
}
}
public int evaluationFunction(Game game){
return 0;
}
我已经考虑到 Wikipedia 伪代码编写了这段代码,但是我有一个问题,我不知道如何将评估函数计算为整数,然后决定返回一个动作,我应该只返回一个动作。评估函数是计算一次移动还是在节点的所有可能移动中选择一个?