【问题标题】:MinMax algorithm not working properlyMinMax 算法无法正常工作
【发布时间】: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


【解决方案1】:

你完成了一项相当复杂的任务:) MiniMax 实现本身几乎没问题,看看 WIKI 页面:

Minimax Algorithm

我认为最小化玩家应该使用最佳移动 = +infinity(在你的情况下为 Integer.MAX_VALUE)

但是,既然您说您的程序运行得相当糟糕,我将提供另一个观察结果。我认为只有当你有一个非常好的评估函数(在你的情况下是 EvaluatePieceScore() 方法)时,该算法才会起作用。这就是“艺术”隐藏的地方。您确定您的方法实现足够好吗?我这么说是因为通常人们把主要精力花在实现这个功能上,而不是算法本身上。

希望对你有帮助

【讨论】:

  • 我确信我的 EvaluatePieceScore() 工作正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 2011-12-07
  • 2018-04-13
  • 2014-05-20
相关资源
最近更新 更多