A modern, colorful web-based Tic-Tac-Toe game featuring an unbeatable AI opponent powered by the minimax algorithm. Built with Flask backend and vanilla JavaScript frontend.
- 🤖 Unbeatable AI - Minimax algorithm ensures perfect play
- 🎯 Player Choice - Choose to play as X or O
- 📊 Statistics Tracking - Win/loss/draw record with win rate
- 📱 Responsive Design - Works on desktop and mobile devices
- 🔄 Quick Restart - Multiple restart options after game ends
- Python 3.11 or higher
- pip (Python package manager)
-
Clone the repository
git clone https://github.com/steve-jr/tic-tac-toe-ai.git cd tic-tac-toe-ai
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
-
Open in browser
http://localhost:5000
Endpoint | Method | Description |
---|---|---|
/ |
GET | Serve main game page |
/state |
GET | Get current game state |
/select-player |
POST | Choose X or O |
/move |
POST | Make a move |
/reset |
POST | Reset game |
{
"board": [["X", null, "O"], [null, "X", null], ["O", null, null]],
"currentPlayer": "X",
"humanPlayer": "X",
"isHumanTurn": true,
"isTerminal": false,
"winner": null,
"isDraw": false,
"needsPlayerSelection": false
}
The AI uses the minimax algorithm with alpha-beta pruning to evaluate all possible game states and choose the optimal move. This makes the AI unbeatable - the best you can do is draw! Game state stored in Flask sessions (cookies). Each player gets their own game instance
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Minimax algorithm implementation inspired by CS50 AI course at UMich
- UI design inspired by modern glassmorphism trends
- Built with Flask and pure JavaScript for simplicity
- Create an issue for bug reports
- Start a discussion for feature requests
- Email: [email protected]
- Visit URL https://tic-tac-toe-ai-production-faf0.up.railway.app
Made with ❤️ and ☕ by Steve Junior