A desktop Tic Tac Toe game built entirely in Python using PyQt5 — no HTML, CSS, JavaScript, or backend server involved. Everything is native Python GUI. Play against an AI powered by the Minimax algorithm, or challenge a friend in 2-player mode. 🧠✨
Don't want to install Python? A pre-built executable is already included in this repository:
- Go into the
distfolder - Download / run
TicTacToe.exe - Double-click to run — that's it! No installation, no dependencies required ✅
⚠️ Windows Defender or your antivirus might show a warning since the exe isn't code-signed. Click "More info" → "Run anyway" — the app is safe, this is common for PyInstaller-built executables.
- 🤖 Single Player vs AI — powered by the Minimax algorithm (50% perfect play, 50% random, so it's beatable)
- 👥 2 Player mode — play locally against a friend, turns alternate automatically
- 🏆 Winning line highlight — the winning 3 cells light up green
- ⏱️ AI "thinking" delay — a short pause before the AI moves, so it feels more natural
- ⬅️ Back navigation — return to the mode-selection screen anytime, with a confirmation prompt if a match is in progress
- 📊 Live scoreboard — tracks Player, AI, and Draw counts
- 🎨 Dark UI theme with cyan accents
tictactoe/
├── main.py # Full application: UI + game logic + entry point
├── ai.py # AI logic (Minimax algorithm)
├── requirements.txt # Python dependencies
├── icon.ico # App icon
├── dist/
│ └── TicTacToe.exe # Pre-built standalone Windows executable
└── README.md # This file
If you'd rather run it from the Python source code instead of the exe:
- 🐍 Python 3.8 or higher
- 🖥️ PyQt5
git clone https://github.com/0xfa-ni/TicTacToe.git
cd TicTacToe
pip install -r requirements.txt
python main.pyOn some systems you may need
python3instead ofpython.
A window will open showing the mode-selection screen. Choose Single Player (vs AI) 🤖 or 2 Player 👥 to start.
check_winner(board)— checks all 8 winning lines and returns"X","O","Draw", orNoneminimax(board, depth, is_maximizing)— recursively simulates every possible future move to score outcomesget_best_move(board)— the AI's move-selection logic: 50% of the time it plays a random move, 50% of the time it plays the mathematically optimal move (via Minimax)
| Class | Responsibility |
|---|---|
🖼️ ModeSelectScreen |
The landing screen — choose "vs AI" or "2 Player" |
🎲 GameScreen |
The board, scoreboard, status text, and all gameplay logic |
🪟 MainWindow |
Uses QStackedWidget to switch between the two screens |
If you modify the code and want to rebuild the executable:
pip install pyinstaller
python -m PyInstaller --onefile --windowed --icon="icon.ico" --add-data "icon.ico;." --name "TicTacToe" main.pyThe new executable will be generated in dist/TicTacToe.exe.
- 🎚️ Difficulty selector (Easy / Medium / Hard)
- 📝 Player name input for 2-player mode
- 🔊 Sound effects
- 💾 Persistent score storage across sessions
This is a personal project, created for learning purposes. Feel free to explore the code.