Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn bestMove in minimax algorithm for tictactoe
    primarykey
    data
    text
    <p>I have tried to code the minimax algorithm for tic-tac-toe given in Russel Norvig's book on Artificial Intelligence. It had everything except that the way to return the bestMove to the user. I am trying hard to return the bestMove, but cannot decide when to choose the bestMove. Help, anyone? </p> <pre><code>moveT MiniMax(stateT state) { moveT bestMove; max_move(state,bestMove); return bestMove; } int max_move(stateT state,int &amp; bestMove) { int v = -10000; if(GameIsOver(state)) { return EvaluateStaticPosition(state); } vector&lt;moveT&gt; moveList; GenerateMoveList(state, moveList); int nMoves = moveList.size(); for(int i = 0 ; i &lt; nMoves ; i++) { moveT move = moveList[i]; MakeMove(state, move); int curValue = min_move(state,bestMove); if(curValue &gt; v) { v = curValue; bestMove = move; } RetractMove(state, move); } return v; } int min_move(stateT state, int &amp;bestMove) { int v = 10000; if(GameIsOver(state)) { return EvaluateStaticPosition(state); } vector&lt;moveT&gt; moveList; GenerateMoveList(state, moveList); int nMoves = moveList.size(); for(int i = 0 ; i &lt; nMoves; i++) { moveT move = moveList[i]; MakeMove(state, move); int curValue = max_move(state,depth+1,bestMove); if(curValue &lt; v) { curValue = v; } RetractMove(state, move); } return v; } </code></pre> <p>P.S.: There are other pseudocode for finding the minmax value. However, they are focused on tic-tac-toe only, I am trying to extend it to other games. Thanks.</p> <p>Update : The whole code can be found here : <a href="http://ideone.com/XPswCl" rel="nofollow">http://ideone.com/XPswCl</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload