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 best move to the user. I am trying hard to return the best move, but cannot decide when to choose the best move. Help, anyone?

moveT MiniMax(stateT state)

{

moveT best move;

max_move(state,bestMove);

return the best move;

}

int max_move(stateT state,int & bestMove)

{

int v = -10000;

if(GameIsOver(state))

{

return EvaluateStaticPosition(state);

}

vector<moveT> moveList;

GenerateMoveList(state, moveList);

int nMoves = moveList.size();

for(int i = 0 ; i < nMoves ; i++)

{

moveT move = moveList[i];

MakeMove(state, move);

int curValue = min_move(state,bestMove);

if(curValue > v)

{

v = curValue;

bestMove = move;

}

RetractMove(state, move);

}

return v;

}

int min_move(stateT state, int &bestMove)

{

int v = 10000;

if(GameIsOver(state))

{

return EvaluateStaticPosition(state);

}

vector<moveT> moveList;

GenerateMoveList(state, moveList);

int nMoves = moveList.size();

for(int i = 0 ; i < nMoves; i++)

{

moveT move = moveList[i];

MakeMove(state, move);

int curValue = max_move(state,depth+1,bestMove);

if(curValue < v)

{

curValue = v;

}

RetractMove(state, move);

}

return v;

}

P.S.: There is another 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.

Update: The whole code can be found here: __http://ideone.com/XPswCl__