質問

私はGoogle検索やStackoverflowのためにこの問題がいまだにわからないどのようにミニマックス機能です。

このwikipediaには擬似コードの機能:

function integer minimax(node, depth)
    if node is a terminal node or depth <= 0:
        return the heuristic value of node
    α = -∞
    for child in node:                       # evaluation is identical for both players 
        α = max(α, -minimax(child, depth-1))
    return α

その他複数の国民の損失が非常に大きく機能のことは基本的に同じもの;ようにしている材料への適用にC++、およびアドバイスをお聞かせてい:

double miniMax(Board eval, int iterations)
{
    //I evaluate the board from both players' point of view and subtract the difference
    if(iterations == 0)
        return boardEval(eval, playerNumber) - boardEval(eval, opponentSide());

    /*Here, playerTurn tells the findPossibleMoves function whose turn it is;
    I mean, how do you generate a list of possible moves if you don't even know
    whose turn it's supposed to be? But the problem is, I don't see where I can
    get playerTurn from, as there are only 2 parameters in all the examples of
    minimax I've seen*/
    vector<int> moves = eval.findPossibleMoves(playerTurn);

    //I'm assuming -∞ in the wikipedia article means a very low number?
    int result = -999999999;

    //Now I run this loop to evaluate each possible move
    /*Also, the Lua example in the wiki article has
      alpha = node.player==1 and math.max(alpha,score) or math.min(alpha,score)
      Is alpha a boolean there?!*/
    for(int i = 0; i * 2 < moves.size(); i++)
    {
        //I make a copy of the board...
        Board temp = eval;

        /*and make the next possible move... once again playerTurn crops up, and I
        don't know where I can get that variable from*/
        temp.putPiece(moves[i * 2], moves[i * 2 + 1], playerTurn);

        /*So do I create a function max that returns the bigger of two doubles?*/
        result = max(result, -miniMax(temp, iterations - 1));
    }

    return result;
    /*So now I've returned the maximum score from all possible moves within a certain
    # of moves; so how do I know which move to make? I have the score; how do I know
    which sequence of moves that score belongs to?*/
}

ご覧の通り、いか戸惑いこのミニマックス機能です。ください少なくとも与えてくれるヒントを教えてくれるので助かります。

よろしく!:)

役に立ちましたか?

解決

そのサンプルからWikipediaにはNegaMax アルファ/ベータ刈り込み.

する手助けになるかもしれにより、ネーミング直線:

  • その基本となるのは、国民の損失が非常に大きく、文字通り実施しながら2つの方法をとるが(相互で再帰的分の1の各側となります。

  • Lazyプログラマとで、この入NegaMax、メソッドを戦略的に配置 - オペレーター

  • Α/Βの剪定は身体の安全を確保するためウィンドウの移動(複数の深度)の検出に死んでます。

playerTurn 使用定番です。にNegaMaxできることから、深度(繰り返し)が奇数のもの.ているのは、より使いやすく2つのパラメータ(myColor,otherColor)取り替えながら使用してくださいでになります。

他のヒント

あなたのミニマックス()関数は、それがこれまでに見つかった最良の動きを覚えておいてください。だから、代わりにこのコード:


  /*So do I create a function max that returns the bigger of two doubles?*/
  result = max(result, -miniMax(temp, iterations - 1));

あなたはこのような何かを行う必要があります:


  /*So do I create a function max that returns the bigger of two doubles?*/
  double score = -miniMax(temp, iterations - 1);
  if (score > result)
  {
     result = score;
     bestMove = i;
  }

もちろん、あなたが変数「bestMove」と最善手を返す方法は、呼び出し側にいなければなりません。

最初に再帰的playerTurnへの引数、およびコールminiMax現在のプレーヤーの動きとしてminiMax変数を追加します。

また、opponentSideplayerTurnの関数であることが必要である。

あとゲーム木探索の 将棋プロwiki.ご質問を移動す:と思うので共通してmax-。二つの違い最大の機能を一つにしていることだけを返しまでのスコア、その他を返します点を移動します。を再帰呼出し順序のようなもの:

maxWithBestMoveReturn(...) --> min(...) --> max(...) --> min(...)

あの論文擬似コードのアルファベータアルゴリズム

ご質問、コメント: いる。max(アルファ、スコアはmath.min()アルファアンダーバー)がアルファbooleanありますか?!

無アルファがウィンドウバインドされている、アルファベータアルゴリズムです。アルファ値が更新された新しい値とします。がアルファ、ベータが交換され、再帰呼出しのnegamax機能をアルファ変数のベータ変数の再帰呼出し.

一つの注playerTurn変数:のミニマックスまたはアルファ-ベータアルゴリズムは必要ありません。ようなので、情報を次--、板構造です。の機能findPossibleMovesとboardEval情報について一覧を取得してからはボード構造です。

一つの注意を再帰休み条件:がわかれば、コード、そしてまいの iterations == o.このアルゴリズムに達したのが望ます。だがない場合が可能の移動左の史跡にアルゴリズムに達すること。これによっ書:

vector<int> moves = findPossibleMoves(...);
if (!moves.size())
    return boardEval(...);
あなたの擬似コードでは、ノード変数は、現在のボードの位置(または任意の)に関するすべての情報が含まれていなければなりません。この情報は、そのそれを回す移動させることで含まれるであろう。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top