A modern implementation of the classic Tic-Tac-Toe game built with React, TypeScript, and Chakra UI. This application allows players to play against each other or against a CPU with an intelligent algorithm. The game is hosted on GitHub Pages.
Try the game here: https://6gal6ler6.github.io/react-tic-tac-toe/
- Play against another person or a CPU
- Intelligent CPU player using the minimax algorithm
- Dark and Light mode using Chakra UI
- Game history tracking wins and draws
- Responsive design
- Hosted on GitHub Pages
- React
- TypeScript
- Chakra UI
- React Router
- GitHub Pages
- Node.js
- npm or yarn
- Clone the repository:
git clone https://github.com/6gal6ler6/react-tic-tac-toe.git
cd react-tic-tac-toe
- Install the dependencies:
npm install
# or
yarn install
- Start the development server:
npm start
# or
yarn start
The application will be available at http://localhost:3000
.
To deploy the application to GitHub Pages:
- Build the application:
npm run build
# or
yarn build
- Deploy to GitHub Pages:
npm run deploy
# or
yarn deploy
The application will be available at https://6gal6ler6.github.io/react-tic-tac-toe
.
App.tsx
: The main application component that sets up routing.Game.tsx
: The main game component that handles game logic, state management, and rendering.Board.tsx
: The component that renders the game board.Square.tsx
: The component that renders each square on the board.OpponentSelection.tsx
: The component that allows the user to select the opponent (Player or CPU).
The application is broken down into reusable components, each responsible for a specific part of the UI and logic.
State management is handled using the useState
and useEffect
hooks. The game state, including the current board, the next player, and whether the game is over, is managed within the Game
component.
React Router is used for navigation within the application. The HashRouter
component is used to ensure compatibility with GitHub Pages.
The CPU opponent uses the minimax algorithm to make intelligent moves. The algorithm recursively evaluates possible game states to choose the optimal move.
The Context API is used to manage global state for tracking game history, including wins and draws.
Chakra UI is used for styling and theming. The application supports both dark and light modes.
The application is deployed to GitHub Pages using the gh-pages
package. The homepage
field in package.json
is configured to ensure the application works correctly on GitHub Pages.
react-tic-tac-toe/
β
βββ public/
β βββ index.html
β βββ ...
β
βββ src/
β βββ components/
β β βββ Board.tsx
β β βββ Game.tsx
β β βββ OpponentSelection.tsx
β β βββ Square.tsx
β β βββ ...
β βββ context/
β β βββ GameContext.tsx
β βββ App.tsx
β βββ index.tsx
β βββ theme.ts
β βββ ...
β
βββ .gitignore
βββ package.json
βββ README.md
βββ ...
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.