Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int MiniMax(int Board[3][3], int depth, bool isMaximizing)
- {
- //Check if anybody won
- checkkWinner(Board);
- if (Winner == 1)
- {
- return MoveValues[1];
- }
- else if (Winner == 2)
- {
- return MoveValues[0];
- }
- else if (AvailableSpots == 0)
- {
- return MoveValues[2];
- }
- if (isMaximizing == true)
- {
- int bestScore = INT_MIN;
- for(int i = 0; i < 3; i++)
- {
- for(int j = 0; j < 3; j++)
- {
- if(Board[i][j] == 0)
- {
- Board[i][j] = 2;
- int score = MiniMax(Board, depth + 1, false);
- Board[i][j] = 0;
- bestScore = max(score,bestScore);
- }
- }
- }
- return bestScore;
- }
- else
- {
- int bestScore = INT_MAX;
- for(int i = 0; i < 3; i++)
- {
- for(int j = 0; j < 3; j++)
- {
- if(Board[i][j] == 0)
- {
- Board[i][j] = 1;
- int score = MiniMax(Board, depth + 1, true);
- Board[i][j] = 0;
- bestScore = min(score,bestScore);
- }
- }
- }
- return bestScore;
- }
- }
- void BotF::BestMove()
- {
- int bestScore = INT_MIN;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (Map[i][j] == 0)
- {
- Map[i][j] = 2;
- int score = MiniMax(Map, 0, false);
- Map[i][j] = 0;
- if (score > bestScore)
- {
- bestScore = score;
- I = i;
- J = j;
- }
- }
- }
- }
- Map[I][J] = 2;
- DrawMap[I][J] = Opponent;
- Winner = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment