This is an implementation of an AI player for the game Tic-Tac-Toe. The AI is designed to play the game intelligently by using the minimax algorithm to search for the optimal move.
To run the Tic-Tac-Toe AI, you will need to have Python installed on your system. Clone this repository and navigate to the project directory. Then, run the following command:
python runner.py
- Choose to play as either "X" or "O".
- Click on an empty cell to make a move.
- The game ends when there is a winner or a tie.
- Click on "Play Again" to start a new game.
-
runner.py
: The main file that runs the Tic-Tac-Toe game and AI player. It uses the Pygame library for the graphical user interface. -
tictactoe.py
: Contains the game logic and functions for managing the Tic-Tac-Toe board, including player turns, actions, and the minimax algorithm.
The Tic-Tac-Toe AI requires the Pygame library to be installed. You can install it using pip:
pip install pygame
The Tic-Tac-Toe AI uses the minimax algorithm to determine the optimal move for the current player. The minimax algorithm is a recursive algorithm that evaluates all possible moves and chooses the move that leads to the best outcome.
The AI follows the following steps to play the game:
- Determine the player who has the next turn.
- If it is the AI's turn, apply the minimax algorithm to find the best move.
- If it is the user's turn, wait for a click event to make a move.
- Check if the game has ended after each move.
- If the game has ended, display the result and provide an option to play again.