理解Negamax的约束

这段代码片段用于计算井字游戏中某个位置的最佳移动。我几乎理解了代码的每一部分,除了for循环中的条件,即minRating != LOSING_POSITION。这段代码来自于给定的伪代码实现。

moveT FindBestMove(stateT state, int depth, int & rating) {for (*each possible move or until you find a forced win*) { *Make the move. Evaluate the resulting position, adding one to the depth indicator. Keep track of the minimum rating so far, along with the corresponding move. Retract the move to restore the original state.* }*Store the move rating into the reference parameter.Return the best move.*}

我无法将for循环的第二个条件与给定的代码相匹配,该条件指出直到找到强制获胜。我无法找到这个事实与minRating != LOSING_POSITION之间的相似性

moveT FindBestMove(stateT state, int depth, int & rating) {Vector<moveT> moveList;GenerateMoveList(state, moveList);int nMoves = moveList.size();if (nMoves == 0) Error("No moves available");moveT bestMove;int minRating = WINNING_POSITION + 1;for (int i = 0; i < nMoves && minRating != LOSING_POSITION; i++) { moveT move = moveList[i]; MakeMove(state, move); int curRating = EvaluatePosition(state, depth + 1); if (curRating < minRating) {  bestMove = move;  minRating = curRating;  } RetractMove(state, move); }rating = -minRating;return bestMove;}int EvaluatePosition(stateT state, int depth) {int rating;if (GameIsOver(state) || depth >= MAX_DEPTH) { return EvaluateStaticPosition(state);}FindBestMove(state, depth, rating);return rating;}

回答:

你的程序从将WINNING_POSITION(我认为这是对手的胜利)赋值给minRating开始,然后遍历所有移动,试图找到造成最大损害的移动,从而最小化minRating

EvaluatePosition返回LOSING_POSITION时,这意味着这个移动在所有情况下都会导致对手输掉,因此可以终止搜索,并认为这个移动是最佳移动。

如果没有明显的LOSING_POSITIONS,那么你的算法会根据静态评估选择“最佳”移动。

Related Posts

L1-L2正则化的不同系数

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

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

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

f1_score metric in lightgbm

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

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

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

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

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

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

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

发表回复

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