A classic Tic-Tac-Toe game where the computer plays perfectly using the Minimax algorithm.
Challenge it if you dare—you can only draw or lose!
- Perfect Play: Implements a full Minimax search.
- Clean GUI: Built with Pygame.
- Modular Code: AI logic completely isolated in
tictactoe.pyfor easy testing. - Replay Anytime: Instant reset to play again.
- Game-Tree Search: Explores every possible sequence of moves until a terminal board state is reached.
- Utility Scoring:
+1if X wins-1if O wins0if draw
- Optimal Decision:
max_valuechooses moves that maximise X’s outcome.min_valuechooses moves that minimise it for O.
Because Tic-Tac-Toe has a small search space, the AI can look at all possibilities and never miss the best move.
- Clone the repository
git clone https://github.com/eyoab-t/tictactoe-ai.git cd tictactoe-ai - Install Dependencies
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
- Run the game
python runner.py
About This Project
This was my first AI project, originally built in 2023 and uploaded here in 2025. — Eyoab