【问题标题】:How to store the first step of best value in a minimax tree?如何将最佳值的第一步存储在极小极大树中?
【发布时间】:2019-06-18 17:30:11
【问题描述】:

我有一个极小极大树和一个评估函数。极小极大函数只返回一个整数(最佳值)。如何存储建立最佳值的第一步? 这是我的代码:

    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 的第一步。现在我将移动存储在“移动”变量中,但它不能正常工作。

【问题讨论】:

    标签: minimax


    【解决方案1】:

    在实际的 minimax 算法实现中,使用哈希表来输入评估的分数和移动,包括 hashkey,对于玩家和棋子的每个位置都是唯一的值。这在执行“强制移动”时也很有用。

    在移动评估期间,hashkey、分数和移动位置记录在结构和哈希表中。因此,搜索成功后,返回整个结构体,以便更新图形和游戏状态。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多