This is a fully-featured Tic-Tac-Toe game with a graphical user interface built using Python and Tkinter. The game includes two AI implementation options:
- MiniMax.py - Classic minimax algorithm implementation
- AlphaBeta.py - Enhanced minimax with alpha-beta pruning for improved performance
-
🎯 Two Game Modes:
- 👤 Single Player - Test your skills against an AI that never makes mistakes
- 👥 Multiplayer - Play with a friend on the same computer
-
🎭 Player Options:
- 🥇 Play as X (first) or O (second) in single player mode
- 🔄 Easily switch between game modes
-
🧠 Two AI Implementation Options:
- 🤖 MiniMax.py - Classic recursive algorithm that explores all possible game states
- ⚡ AlphaBeta.py - Optimized algorithm that prunes unnecessary branches for faster decisions
-
🎨 User-Friendly Interface:
- Clean, intuitive design
- Visual feedback for game status
- Winning combinations get highlighted
- Make sure you have Python installed (3.6 or newer)
- The game uses Tkinter which comes pre-installed with most Python installations
- Run either implementation:
OR
python MiniMax.py # For the classic minimax AIpython AlphaBeta.py # For the faster alpha-beta pruning AI
-
MiniMax.py
- 📊 Explores the entire game tree
- 🧮 Makes optimal decisions but may be slower
- 💻 Simpler implementation to understand
-
AlphaBeta.py
- ⚡ Much faster, especially for the opening moves
- 🎯 Makes identical decisions to minimax
- 🔍 Intelligently skips evaluating branches that won't affect the final decision
- Launch either version of the game
- Select your preferred game mode (Single Player or Multiplayer)
- In Single Player mode, choose whether to play first (X) or second (O)
- Click on any empty cell to make your move
- In Single Player mode, the AI will automatically respond
- The first player to get three marks in a row (horizontally, vertically, or diagonally) wins
- If all cells are filled with no winner, the game ends in a draw
- Mouse: Click on any empty cell to place your mark
- New Game Button: Start a fresh game with current settings
- Exit Button: Close the game
- Game Menu: Access additional options
- Programming Language: Python 3
- GUI Framework: Tkinter
- AI Algorithms:
- Minimax (MiniMax.py)
- Alpha-Beta Pruning (AlphaBeta.py)
- Board Representation: List with values 0 (empty), 1 (O), and -1 (X)
- 🎯 Corner cells (particularly the first move) are strategically strong positions
- 🛡️ Block your opponent's potential winning moves
- 🏆 Against either AI implementation, a draw is the best possible outcome with perfect play
__init__: Sets up the game window and initializes variables- UI Creation Methods: Build the interface components
- Game Logic Methods: Handle player actions and game state
- AI Methods:
- MiniMax.py:
minimax()implements the standard algorithm - AlphaBeta.py:
alpha_beta()implements the optimized version
- MiniMax.py:
Feel free to modify the code to customize:
- 🎨 Colors and appearance
- 💪 AI difficulty (by limiting the search depth)
- 🏆 Add score tracking between games
- 🔊 Add sound effects
- The standard minimax algorithm can be slow on first move (evaluating all possible game trees)
- Window size is fixed and may not adapt well to all screen resolutions
This project is open source and available under the MIT License.
- Original terminal-based implementation adapted to GUI
- Minimax and Alpha-Beta pruning algorithms implemented for perfect AI play
Enjoy the game! 🎮