如何修复倾向于自我毁灭的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

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

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