A simple terminal-based Tic-Tac-Toe game where you play as X against a basic AI playing as O.
The AI can block your winning move and tries to win when it gets a chance!
- 3×3 grid with position labels (e.g.,
TopL,MidC,BotR) - Input validation and board rendering
- Win detection for both players
- Basic AI with:
- Win detection
- Block opponent’s winning move
- Random fallback move
The AI (O) tries to:
- Win if it can by completing any winning triplet.
- Block the player (
X) if the player is about to win. - Otherwise make a random valid move.
-
Clone the repository:
git clone https://github.com/sherrymir/tic-tac-toe-ai.git cd tic-tac-toe-ai -
Run the game:
python game.py
-
Enter your move when prompted using position keys like
TopL,MidC,BotR, etc.
TopL | TopC | TopR
-----+------+-----
MidL | MidC | MidR
-----+------+-----
BotL | BotC | BotR
Example input:
Where do you wanna put X e.g(TopL,MidC,BotR): MidC
tic-tac-toe-ai/
└── game.py # Main game logic with AI
- Smarter minimax-based AI
- GUI version with Pygame or Tkinter
- Two-player local mode
- Score tracking