Games are scored across the session. Reset the score counter any time to start fresh.
The AI uses minimax with alpha-beta pruning — the same family of algorithms behind competitive chess and checkers engines. It evaluates every possible move sequence to find the one that leads to the best outcome.
Curious how it decides? Watch minimax and alpha-beta run, step by step →
On a standard 3×3 board, Hard mode searches the complete game tree, which makes it the hardest bot you can face: a mathematically unbeatable Tic Tac Toe opponent where perfect play forces a draw, never a win. On larger boards (4×4 and up) the search depth is capped for performance, which gives skilled players a real chance to win.
Easy mode picks random moves. Medium uses a greedy heuristic that plays intelligently but makes mistakes.
How minimax works: At each turn the algorithm assumes both players play optimally. It builds a tree of every possible move sequence, assigns +1 for an AI win, 0 for a draw, and −1 for a loss at each leaf, then propagates those scores back up — maximising on the AI's turns, minimising on yours. The move with the highest score at the root is always played.
Why alpha-beta pruning matters: Choosing its opening move at full depth, a plain minimax search visits 549,945 board positions. Alpha-beta pruning discards entire branches the moment it confirms they cannot change the decision, cutting that to 36,528 — a 93% reduction for an identical result, which is why Hard mode responds instantly on 3×3. (These are measured counts — see the benchmark below.)
Difficulty levels in practice: Beginner skips the optimal move most of the time — useful for teaching without discouraging early losses. Medium applies the heuristic with deliberate errors, creating a challenging-but-beatable opponent for casual play. Hard uses the full minimax tree with zero errors: provably optimal, always.
Winning on larger boards: On 4×4 and bigger grids the search depth is capped, so the AI cannot see far enough ahead to guarantee a win. The most reliable strategy is the fork — a move that creates two simultaneous winning threats the AI cannot both block. Setting up a fork one or two moves before the AI's depth limit is the clearest path to victory on 4×4 and up.
We ran the exact engine on this page through a reproducible benchmark. On 3×3 there's no sampling: Hard mode's reply to any position is deterministic, so we enumerated every reachable game — every move you could make, answered by the AI.
Across all 642 possible 3×3 games, the AI lost 0. Playing second, as it does here: 386 wins, 183 draws, 0 losses. Playing first: 71 wins, 2 draws, 0 losses. On a 3×3 board the best any opponent can force is a draw — that's not a claim, it's the whole game tree.
On larger boards the search depth is capped, so we simulated games against random and greedy opponents. It still never lost — but forcing a win gets harder as the board grows:
| Board | Win length | vs random | vs greedy |
|---|---|---|---|
| 3×3 | 3 | 91.8% W · 8.2% D · 0 L | draw · 0 L |
| 4×4 | 4 | 72.5% W · 27.5% D · 0 L | draw · 0 L |
| 5×5 | 4 | 96.7% W · 3.3% D · 0 L | draw · 0 L |
| 6×6 | 4 | 100% W · 0 L | win · 0 L |
That's 0 losses across 628 simulated games up to 6×6, on top of the exhaustive 3×3 proof. A capped search depth still leaves room for a sharp human to engineer a fork the AI can't see far enough ahead to stop — which is exactly why the larger boards give you a real chance to win.
Reproduce this. The engine and the benchmark are open source — run node benchmark.js yourself: github.com/lucian-devops/tictactoe-ai. The engine there is the exact file this page ships.
For the deeper theory of why 3×3 is a forced draw under perfect play, read the game theory of Tic Tac Toe.
On 3×3, the minimax algorithm plays perfectly — the best outcome is a draw. On 4×4 and larger, yes, a strong player can win because the AI's search depth is limited.
On a classic 3×3 board the Hard AI plays perfect minimax, so you can't beat it — open in the centre or a corner and block every two-in-a-row to force a draw. To actually win, drop to Easy or Medium, or play a larger board (up to 10×10) where its limited depth lets you set up a double threat.
An optimisation that skips game-tree branches that cannot affect the final decision. It lets the AI search deeper without slowing down.
Yes. No account, no download, no payment. Play instantly in any browser — desktop or mobile.
Yes. The board scales automatically to fit any screen. Tap cells to play exactly as you would with a mouse.
Easy picks moves randomly, which occasionally lands on a blocking cell by chance. It makes no deliberate strategic decisions.
Yes — try AI Chess, AI Checkers, AI Othello, AI Connect 4, AI Minesweeper, AI Sudoku, AI 2048, Color Lines, Brain Puzzles, or Memory Match on the games hub, or explore free word tools like the Word Generator and Word Unscrambler at lkforge.com/tools/.
Yes — this is a free online Tic Tac Toe game you play against the computer (an AI opponent) right in your browser, with no app and no sign-up. Pick Easy, Medium, or Hard: on a classic 3×3 board the Hard AI is mathematically unbeatable, so the best you can force is a draw, while larger boards up to 10×10 give you a real chance to win. It works on both desktop and mobile.
On a classic 3×3 board, yes — Hard mode runs full minimax search, making it a mathematically unbeatable Tic Tac Toe AI and one of the hardest bots online: the best you can force is a draw. Drop to Easy or Medium, or play a larger board up to 10×10, for a real chance to win.
Free to embed — drop the playable board and its unbeatable minimax AI into any website, blog, or classroom page. No sign-up, nothing to install; it runs entirely in your visitor's browser. Copy this code and paste it into your page's HTML where you want the game to appear:
The <iframe> is the live game; the <p> beneath it is a plain credit link — keep it, and the widget stays free to embed. Need step-by-step help for WordPress, Squarespace, Wix, Ghost or Notion? See how to add a Tic-Tac-Toe game to your website.
Want the best move for a position rather than a game? Try the Tic-Tac-Toe solver.