AI (Exp 6)
AI (Exp 6)
Experiment 6
Experiment No. - 6
formation/correction/ Answer to
(03) (03)
6.1 Aim:
To implement adversarial search using the Minimax algorithm for a two-player game and demonstrate
the strategy for winning.
CO 2: Apply the most suitable search strategy and represent a natural language description of statements
in logic and apply the inference rules to design problem-solving agents.
Implement the Minimax algorithm for a simple two-player game, such as Tic-Tac-Toe. Demonstrate
how the algorithm helps in finding the optimal strategy for the maximizing player.
The Minimax algorithm is a decision-making algorithm used in adversarial games, such as Tic-Tac-
Toe, Chess, and Checkers. It is designed to minimize the possible loss in a worst-case scenario, and it
assumes that both players (the maximizing and minimizing players) play optimally.
Maximizing Player: The player who tries to maximize their chances of winning.
Minimizing Player: The opponent who tries to minimize the maximizing player’s chances of winning.
The maximizing player chooses the move that leads to the highest possible score.
The minimizing player chooses the move that leads to the lowest possible score.
Consider the following Tic-Tac-Toe configuration where it’s the turn of the maximizing player (X):
X | O | X
O | X |
| O |
The maximizing player (X) has two possible moves: placing X in either the bottom-left or bottom-right
empty cell.
X | O | X X | O | X
O | X | OR O | X |
| O | X X | O |
X | O | X
O | X |
O | O | X
X | O | X
O | X |
X | O | O
3. Outcome Evaluation:
o Left board: The game results in a draw since neither player can win.
o Right board: The game results in a draw as well.
4. Minimax Decision: Since both options lead to a draw, the Minimax algorithm will choose the
first available move. The final move for X would be in the bottom-left cell (arbitrarily chosen
since both outcomes are equal).
6.6 Procedure:
o The objective is to implement the Minimax algorithm for a two-player game like Tic-Tac-Toe.
2. Define the Game Environment:
o Create a 3x3 grid for the Tic-Tac-Toe game.
3. Write the Evaluation Function:
o Implement a function to evaluate the board for win, loss, or draw conditions.
4. Implement Minimax:
o Write the Minimax function to recursively explore the game tree and return the best move for the
maximizing player.
5. Run the Program:
o Test the program with various configurations and verify that the algorithm returns the optimal
move.
6. Analyze the Output:
o The output should show the optimal value for the maximizing player, which in the case of a draw
would be 0.
6.7 Conclusion:
6.8 Questions: