如何修复倾向于自我毁灭的MinMax算法?

我在尝试为跳棋游戏编写使用MinMax的AI算法。一切都在最终测试前都很好…… 电脑选择任意棋子后就朝我的棋子走来。他真的很想快速死去。以下是我的代码:

public MoveAndPoints MinMax(Dictionary<int, Field> gameBoard, string myColor, Boolean maximizingPlayer, int depth)    {        MoveAndPoints bestValue = new MoveAndPoints();        if (0 == depth)        {            return new MoveAndPoints(((myColor == enemyColor) ? 1 : -1) * evaluateGameBoard(gameBoard, myColor), bestValue.move);        }                    MoveAndPoints val = new MoveAndPoints();        if (maximizingPlayer)        {            bestValue.points = int.MinValue;            foreach (Move move in GetPossibleMoves(gameBoard, myColor))            {                gameBoard = ApplyMove(gameBoard, move);                bestValue.move = move;                val = MinMax(gameBoard, Extend.GetEnemyPlayerColor(myColor), false, depth - 1);                bestValue.points = Math.Max(bestValue.points, val.points);                gameBoard = RevertMove(gameBoard, move);            }            return bestValue;        }        else        {            bestValue.points = int.MaxValue;            foreach (Move move in GetPossibleMoves(gameBoard, myColor))            {                gameBoard = ApplyMove(gameBoard, move);                val = MinMax(gameBoard, Extend.GetEnemyPlayerColor(myColor), true, depth - 1);                bestValue.points = Math.Min(bestValue.points, val.points);                gameBoard = RevertMove(gameBoard, move);            }            return bestValue;        }    }

这是我的启发式函数:

public int evaluateGameBoard(Dictionary<int, Field> gameBoard, string color){    return Extend.GetNumberOfPieces(gameBoard, color) - Extend.GetNumberOfPieces(gameBoard, Extend.GetEnemyPlayerColor(color));}

例如,我有这样的场景:

enter image description here


他没有选择其他地方移动,而是选择了死亡:

enter image description here

如果我自己选择死亡,他只会因为这是他唯一的移动而杀死我。有人能帮我修复这个问题吗?我认为问题出在MinMax里。我几乎可以肯定这不是一个很严重的问题,但我实在找不到 🙁

这是我的树的深度3:enter image description here


回答:

我没有你所有的代码,所以我无法完全验证这些问题。但我相信至少你的一个问题是你在玩家之间混淆了颜色。在你的MinMax调用中,你为两个位置传递了相同的颜色:

这是最大化玩家内部的调用:

val = MinMax(gameBoard, Extend.GetEnemyPlayerColor(myColor), false, depth - 1);

这是另一个调用:

val = MinMax(gameBoard, Extend.GetEnemyPlayerColor(myColor), true, depth - 1);

你正确地切换了是否最大化,但你不应该在玩家之间切换颜色。

实际上,你真的希望始终跟踪根节点处的玩家是谁,因为所有的评估都是相对于根节点处的玩家进行的。在这种情况下,你只需始终传递颜色,并且只在评估函数中使用敌人的颜色。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注