FILE 002
Unbeatable Tic-Tac-Toe
DECLASSIFIEDBrowser game with an unbeatable Minimax AI
- Role
- Developer (personal project)
- Year
- 2022
- Stack

01Overview
A tic-tac-toe game in the browser where you play O against an AI that never loses. Before every move, the AI uses the Minimax algorithm to play out every possible rest of the game and picks the move with the best guaranteed result.
You vs. AI · Minimax search over the full game tree · win, loss and draw detection with the winning line highlighted · replay · vanilla JavaScript, no dependencies.
02The problem
Hand-written rules for a tic-tac-toe bot (“block when they have two in a row”) easily miss a case. The goal: an opponent that never loses because it looks ahead at every possible game instead of following rules.
03My approach
- A.01
Score each finished game: +10 if the AI (X) wins, −10 if you (O) win, 0 for a draw.
- A.02
Try every free square, then every possible reply, recursively until each game ends.
- A.03
Back up the scores: on its turn the AI takes the highest (MAX); on yours it assumes you take the lowest (MIN).
- A.04
Play the move with the best backed-up score. The 9-square board is small enough to search the whole tree, with no depth limit.
04Key screens
Unbeatable Tic-Tac-Toe: Minimax on a real position: X wins at once (+10) instead of blocking (0) or losing (−10)
Unbeatable Tic-Tac-Toe: New game: you play O and move first
Unbeatable Tic-Tac-Toe: Best play on both sides ends in a draw› swipe for all 4 screens
05Technical highlights
- Game engine
- Minimax · full game tree
- Front end
- Vanilla JS · HTML · CSS
- Platform
- Vercel
06Outcome
Because it assumes you always play your best move, the AI can’t be beaten: every game ends in a win for the machine or a draw.