2
        int minmax(Board game, int depth)
        {
            if (game.IsFinished() || depth < 0)
                return game.Score(game.Turn);

            int alpha = int.MinValue + 1;
            foreach (Point move in game.Generate_Moves())
            {
                Board currentBoard = game;
                currentBoard.Do_Move(move); 

                alpha = max(alpha, -minmax(currentBoard, depth-1));
                currentBoard.Undo_Move(move);
            }

            return alpha;
        }

この小さな関数は、ゲームが勝ち、負け、引き分けのいずれであるかを教えてくれますが、どうすれば勝つための動きを得ることができますか?私のPointクラスは、2つの座標X、Yを持つ単純なクラスであり、後で答えをポイントとして取得したいので、後で次のように言うことができgame.Do_Move(myPoint)ます。

一部の機能が明確でない場合:

game.IsFinished()-勝つ/負ける/引く場合はtrueを返し、そうでない場合はtrueを返します。

game.Score(turn)-次の手でプレーヤーが負け/引き分け/勝った場合は-1/0/1を返します

game.Generate_Moves()-利用可能な動きのリストを返します

game.Do_Move()-ゲームに移動を適用するvoid

game.Undo_Move()-自分自身のために話します

4

2 に答える 2

1

It would be enough if the minimax function which gets called on the root node of the game tree returns both, the choosen move and the score. For all other nodes of the game tree, the function needs only to return the score. Thus the usual way is to implement two slightly different minimax functions – Look at Note #2 in the description to this NegaMax Framework.
Applied to your minimax interface you would have following additional function:

int minimaxWithMove(Board game, int depth, Point& choosen)
{
    assert (!game.IsFinished() && depth > 0); // not possible at root node
    int alpha = int.MinValue + 1;
    foreach (Point move in game.Generate_Moves())
    {
        Board currentBoard = game;
        currentBoard.Do_Move(move);
        int score = -minmax(currentBoard, depth-1);
        if (score > alpha)
        {
            alpha = score;
            choosen = move;
        }
    }
    return alpha;
}

Note that I have removed the call to Undo_Move as it is not needed because you make a copy of game in each iteration.

于 2012-02-13T21:22:52.380 に答える
0

ミニマックス定理を適用する必要があります。

基本的にゲームツリーを作成する必要があります。ツリー内の各ノードはボードの位置であり、各子は合法的な移動の結果です。リーフノード(ゲームが終了する場所)にはgame.score()に従ったスコアがあり、一方のプレーヤーはハイスコアにつながるパスを下に移動を選択しようとし、もう一方のプレーヤーは低を強制する移動を選択しようとしますスコア。この定理は、そのアイデアを厳密に適用する方法を理解するのに役立ちます。

于 2012-02-10T15:04:11.027 に答える