如何将最优值的第一步存储在极小极大树中?

How to store the first step of best value in a minimax tree?

我有一个 minimax 树和一个评估 function.The minimax 函数 return 只有一个整数(最佳值)。我如何存储建立最佳值的第一步? 这是我的代码:

    int Brain::MiniMax(GameBoard gb, int depth,int Turn,int lastcount) //0->Max 1->Min
{   
    if (depth == 5)
        return Evaluation(lastcount, gb);
    int bestval = 0;
    if (Turn == 0)
    {
        bestval = -100;
        vector<pair<int, pair<int, int>>> possibleFences = this->PossibleFences(gb);
        for (int i = 0; i < possibleFences.size(); i++)//ForFences
        {
            int cnt = 0;
            NextShortestPathMove(cnt, gb.OpponentPawn,gb);
            if (gb.CanPutFence(possibleFences[i].first, possibleFences[i].second.first, possibleFences[i].second.second) == 0)
                continue;
            gb.PutFence(possibleFences[i].second.first, possibleFences[i].second.second, possibleFences[i].first);          
            int value = MiniMax(gb, depth + 1,1, cnt);
            if (value > bestval)
            {
                bestval = value;
                move = possibleFences[i];
            }
        }
        return bestval;
    }
    else if (Turn == 1)
    {
        bestval = +100;
        int** possibleMoves = this->PossibleMoves(gb.OpponentPawn.Row, gb.OpponentPawn.Column, gb.OpponentPawn,gb);

        for (int i = 0; i < 6; i++)
        {
            if (possibleMoves[i][0] == -1)
                continue;
            int cnt = 0;
            NextShortestPathMove(cnt, gb.OpponentPawn,gb);
            gb.MoveOpponentPlayer(possibleMoves[i][0], possibleMoves[i][1]);
            int value = MiniMax(gb, depth + 1, 0,cnt);
            bestval = min(value, bestval);
        }
        return bestval;
    }   
}

例如最后如果bestval = 10,我想要选择这个bestval的第一步。现在我将移动存储在 'move' 变量中,但它不能正常工作。

在实际的 minimax 算法实现中,哈希 table 用于输入评估的分数和移动,包括 hashkey,对于玩家和棋子的每个位置都是唯一的值。这在执行 "force move".

期间也很有用

在移动评估期间,哈希键、分数和移动位置被记录在一个结构中,哈希也被记录在 table 中。因此,在成功搜索后,将返回整个结构以启用图形和游戏状态的更新。

典型的哈希条目如下所示:

struct HashEntry {
    int move;
    int score;
    int depth;
    uint64_t posKey;
    int flags;
};