gpt4 book ai didi

c++ - 了解 Negamax 的约束

转载 作者:行者123 更新时间:2023-11-28 07:52:05 26 4
gpt4 key购买 nike

这段代码是为计算井字游戏中某个位置的最佳移动而构建的。我几乎得到了代码的每一部分,除了 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,那么您的算法会根据静态评估选择“最佳”着法。

关于c++ - 了解 Negamax 的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13559698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com