This project is a web-based implementation of the classic Tic Tac Toe game, where a human player competes against an AI opponent. The AI uses the minimax algorithm to make optimal moves, providing a challenging gameplay experience.
- Interactive web-based Tic Tac Toe game
- Play against an AI opponent that uses the minimax algorithm
- Responsive design that works on desktop and mobile devices
- Simple and intuitive user interface
- Clone this repository or download the source code.
- No additional dependencies are required as this project uses vanilla HTML, CSS, and JavaScript.
- Open the
index.html
file in a web browser. - The game board will be displayed, and you can start playing immediately.
- Click on any empty cell to make your move (you'll be playing as 'X').
- The AI opponent will automatically make its move (playing as 'O').
- Continue playing until there's a winner or the game ends in a tie.
- Use the "Reset Game" button to start a new game at any time.
index.html
: The main HTML file that structures the game interface.style.css
: Contains all the CSS styles for the game layout and appearance.logic.js
: Implements the game logic, AI opponent, and user interactions.
The AI opponent uses the minimax algorithm to determine the best move. This algorithm works by:
- Simulating all possible future game states.
- Assigning a score to each end state (win = +10, lose = -10, tie = 0).
- Choosing the move that leads to the best possible outcome for the AI, assuming the human player also plays optimally.
This makes the AI very challenging to beat. The best a human player can achieve against this AI is a tie.
You can customize the game by modifying the following:
- Adjust the styling in
style.css
to change the game's appearance. - Modify the delay of the AI's move in
logic.js
by changing the timeout value in thehandleCellClick
function. - Experiment with the scoring in the
minimax
function to adjust the AI's behavior.
Contributions to improve the game are welcome. Please feel free to submit issues or pull requests.
This project is open source and available under the MIT License.