int MiniMax(char _board[9], player _player) //Function
{
int best_val = -INFINITY, index = 0; //Set best_val to minus infinity, so we will always have
//a correct best move (one will always be higher than minus infinity).
std::list<int> move_list;
char best_moves[9] = {0}; //Set all the best moves to zero so we don't accidently
//use a move with a high value from the last evaluation...
generate_moves(_board, move_list); //Function call, presumably finding possible moves.
while(!move_list.empty()) //While there are still possible moves remaining.
{
_board[move_list.front()] = _player.symbol; //Make a move on the board (I think)
cSymbol = _player.symbol;
int val = MinMove(_board, _player); //Another function call
if(val > best_val) //If the value of this move is better than the best move found so far.
{
best_val = val;//Make this the new best move.
index = 0;
best_moves[index] = move_list.front() + 1;
} elseif(val == best_val) { //If the value of this move is equal to the best move found.
best_moves[++index] = move_list.front() + 1;
}
_board[move_list.front()] = 0;
move_list.pop_front();
}
if(index > 0)
{
index = rand() % index;
}
return best_moves[index]; //Return this best move.
}