I am trying to create an AI opponent for a two player 8x8 board game. After a research I found Minimax algorithm handy enough to do the job. The AI opponent I am creating will play against an other AI opponent or Human.
I have a doubt in understanding the minimax algorithm.
I am trying to create just ONE AI opponent but the explanations found on web says that I need to write code for both players(Minimum player and Maximum player) as I understand from the pseudo code below.
MinMax (GamePosition game) {
return MaxMove (game);
}
MaxMove (GamePosition game) {
if (GameEnded(game)) {
return EvalGameState(game);
}
else {
best_move < - {};
moves <- GenerateMoves(game);
ForEach moves {
move <- MinMove(ApplyMove(game));
if (Value(move) > Value(best_move)) {
best_move < - move;
}
}
return best_move;
}
}
MinMove (GamePosition game) {
best_move <- {};
moves <- GenerateMoves(game);
ForEach moves {
move <- MaxMove(ApplyMove(game));
if (Value(move) > Value(best_move)) {
best_move < - move;
}
}
return best_move;
}
I can further understand that Maximum player will be the AI I am going to develop and the minimum player is the opponent.
My question is why I have to write code for both Minimum and Maximum player to return the best move ?
The pseudo code given below is based on C#.
Thanks in advance.