【发布时间】:2014-07-16 19:40:06
【问题描述】:
我正在研究国际象棋引擎,现在正在尝试实现 Minimax 算法。目前我已经整理了一个mimimax代码,但它并没有真正正常工作。考虑到我不是一个好的国际象棋棋手,我在几分钟内就击败了引擎。
我希望有人可以查看我的极小极大代码并告诉我我写的正确。
提前致谢。
这是我的代码:
private int MiniMax(Game game, int depth){
return Max(depth);
}
private int Max(int depth){
if (depth <= 0
|| this.chessgame.getGameState() == Game.GAME_STATE_END_YELLOW_WON
|| this.chessgame.getGameState() == Game.GAME_STATE_END_BROWN_WON){
return EvaluatePieceScore();
}
int max = -Integer.MIN_VALUE;
List<Move> moves = generateMoves(false);
for(Move allMove : moves){
executeMove(allMove);
int score = -Mini(depth - 1);
undoMove(allMove);
if( score > max){
max = score;
}
}
return max;
}
private int Mini(int depth) {
if (depth <= 0
|| this.chessgame.getGameState() == Game.GAME_STATE_END_YELLOW_WON
|| this.chessgame.getGameState() == Game.GAME_STATE_END_BROWN_WON){
return EvaluatePieceScore();
}
int min = Integer.MIN_VALUE;
List<Move> moves = generateMoves(false);
for(Move allMove : moves){
executeMove(allMove);
int score = -Max(depth - 1);
undoMove(allMove);
if( score > min){
min = score;
}
}
return min;
}
【问题讨论】:
-
一件事是 -Integer.MIN_VALUE 不起作用。
-
@resueman,我做出了改变,但没有改善
-
你在和哪个
depth比赛?如果它是低数字,有可能轻松获胜。在MiniMax方法中,您只调用Max,这是可疑的(应该为其他玩家调用Min)。
标签: java algorithm artificial-intelligence chess