This project is an implementation of the classic Tic-Tac-Toe game using React.js, featuring an AI opponent using the minimax algorithm.
Click below to play: https://wongcolin45.github.io/ReactTacToe/
- Interactive Tic-Tac-Toe game board
- Play against an AI opponent
- Ability to generate AI moves
- Game state management (win/lose/draw detection)
- Reset game functionality
The main game component that renders the Tic-Tac-Toe board and handles game logic.
A component to display the game result when the game ends.
Contains the core game logic, including:
Boardclass for managing the game stategetBestMovefunction implementing the minimax algorithm for AI movesgameResultfunction to determine the game outcome
- The game starts with an empty 3x3 grid.
- You can choose to go first or second:
- To make your move, simply click on an empty tile on the board.
- To have the AI make a move, click the "generate move" button.
- The game is flexible - you can make multiple moves in a row or let the AI make multiple moves by clicking the "generate move" button multiple times.
- The current player's turn is tracked internally, so the correct symbol (X or O) will be placed regardless of who makes the move.
- Use the "generate move" button whenever you want the AI to play the best possible move based on the current board state.
- The game continues until one player wins by getting three in a row (horizontally, vertically, or diagonally) or the board is full, resulting in a draw.
- Once the game is over, the result will be displayed.
- Click the "reset" button at any time to start a new game.
This flexible play style allows you to:
- Play against the AI traditionally (alternating turns)
- Set up specific board states and test the AI's response
- Have the AI play against itself by repeatedly clicking "generate move"
- Take back moves by resetting and recreating the desired board state
The AI uses the minimax algorithm to determine the best move, making it a challenging opponent that plays optimally given the current board state.
- Clone this repository
- Navigate to the project directory
- Run
npm installto install dependencies - Run
npm startto start the development server
- React.js
- JavaScript (ES6+)
- Add difficulty levels for the AI
- Implement a score tracking system
- Add animations for a more engaging user experience
Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.