A simple terminal-based Tic-Tac-Toe game in Python where a human player competes against an AI.
- โ Unbeatable AI using Minimax with Alpha-Beta Pruning
- ๐ฏ Prioritizes quick wins and avoids losses
- โป๏ธ Backtracking logic to simulate all possible game outcomes
Clone this repository:
git clone https://github.com/yourusername/tic-tac-toe-ai.git
Run the game:
python game.py
- Choose to play as X or O
- X always moves first
- Enter your moves using row and column indices (0 to 2), for example:
Your move (row and column, from 0 to 2): 0 1
play()
โ Starts and manages the game loopminimax()
โ Main recursive algorithm for optimal decision-makingbest_move()
โ Finds the best move for the AI using MinimaxisGameOver()
โ Checks for a win or drawpossible_moves()
โ Returns available moves on the boardshow_board()
โ Displays the board in the console
- Python 3.6 or higher
- No external libraries required
AI is thinking...
X | O | O
-----------
| O | X
-----------
O | X | X
-----------
O wins!
This project is open-source and free to use.
Made by pdrzxzz | Computer Science Student ๐