Unbeatable AI Tic Tac Toe

Unbeatable Hard Mode  ·  Custom Board  ·  Free on LK Forge
Your turn
You
0
·
Draws
0
·
AI
0
Options
3 × 3Win: 3 in a row
Share this X Facebook Reddit

How to Play

  • Choose a board size — from the classic 3×3 up to 10×10. Boards larger than 3×3 require 4 in a row to win.
  • Pick your piece — circle or square.
  • Select a difficulty — Easy, Medium, or Hard.
  • Click a cell to place your piece. The AI responds immediately.
  • Get N in a row horizontally, vertically, or diagonally to win.

AI Tic Tac Toe pits you against a minimax-driven opponent on any board from 3×3 to 10×10. Games are scored across the session. Reset the score counter any time to start fresh.

About the Unbeatable AI

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.

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.

Is the AI really unbeatable? We benchmarked it.

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:

Hard AI vs a random opponent — win / draw split (0 losses) 3×3 4×4 5×5 6×6 win draw lkforge.com/games/tictactoe
BoardWin lengthvs randomvs greedy
3×3391.8% W · 8.2% D · 0 Ldraw · 0 L
4×4472.5% W · 27.5% D · 0 Ldraw · 0 L
5×5496.7% W · 3.3% D · 0 Ldraw · 0 L
6×64100% W · 0 Lwin · 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, or see how the minimax search itself works. More strategy tips are in the Tic-Tac-Toe strategy guide, and every post is indexed on the Tic-Tac-Toe blog.

How to Never Lose at Tic-Tac-Toe

On the classic 3×3 board, perfect play always ends in a draw — so being unbeatable is a strategy you can learn, not just an AI you play against. Follow these five rules and you will never lose:

  1. Open in the centre. It sits on four of the eight winning lines — more than any other square. If you move first, take it.
  2. If you move second and the centre is taken, grab a corner, not a side. A corner denies your opponent the easiest forks; a side hands them one.
  3. Complete your own three-in-a-row whenever you can — winning outright beats every other rule.
  4. Otherwise block any line where the opponent already has two. Never leave an open two-in-a-row standing on your turn.
  5. Watch the forks. A fork is a single move that makes two threats at once, so the opponent can only block one. Play a fork when you have it; when they set one up, break it early — ideally by making a threat of your own that forces their reply.

Do all five and the worst outcome is a draw, every game — which is exactly what the Hard AI above does to you. Put it to the test: try to hold a draw against Hard mode, or read why even the best first move can’t force a win.

Frequently Asked Questions

Can you beat Hard mode?

On a classic 3×3 board, no — Hard mode runs a full minimax search and plays perfectly, so the best any opponent can force is a draw. On 4×4 and larger boards, yes, a skilled player can win because the AI's search depth is capped for performance. The bigger the board, the more room there is to set up a fork before the AI can see it coming.

How do you win at Tic Tac Toe against the AI?

On a classic 3×3 board the Hard AI plays a perfect minimax game, so you cannot beat it — the best you can force is a draw by opening in the centre or a corner and always blocking the AI's two-in-a-row. To actually win against the AI, set the difficulty to Easy or Medium, or play a larger board (4×4 up to 10×10) where its limited search depth lets a sharp player set up a double threat the AI can't block. A double threat, or fork, is one move that creates two winning lines at once, so the AI's limited lookahead can only stop one of them.

How do you never lose at tic-tac-toe?

On the 3×3 board tic-tac-toe is a forced draw, so you can play it unbeatably with five rules: take the centre if you move first; if you move second and the centre is gone, take a corner rather than a side; always complete your own three-in-a-row when you can; otherwise block any line where the opponent already has two; and watch for forks — a single move that creates two threats at once — playing your own and breaking theirs early. Follow all five and the worst result is a draw, every game. These are the same five rules the Hard AI above follows, which is why it never loses a single 3×3 game.

What is alpha-beta pruning?

Alpha-beta pruning is an optimisation that skips game-tree branches that cannot affect the final decision. It lets the AI search deeper without slowing down. On this page's opening 3×3 move, it cuts the search from 549,945 positions to 36,528 — a 93% reduction — for the exact same result.

Is it free?

Yes, this Tic Tac Toe game is free. No account, no download, no payment — play instantly in any browser, desktop or mobile. The game runs entirely in your browser with no ads and no sign-up wall, and your score tally is saved locally on your device rather than to an account.

Does it work on mobile?

Yes, the game works on mobile. The board scales automatically to fit any screen — tap cells to play exactly as you would with a mouse. The whole game runs client-side in your browser, so rotating your phone or resizing the window redraws the board at the right size instantly, with no app to install.

Why does Easy mode still block me sometimes?

Easy picks moves randomly, which occasionally lands on a blocking cell by chance. It makes no deliberate strategic decisions. Switch to Medium or Hard if you want the AI to block and attack on purpose every time.

Can I play other AI games on LK Forge?

Yes, LK Forge has other AI games too. The games hub has AI opponents in Chess, Checkers, Othello, Connect 4, and Minesweeper, plus AI Sudoku, AI 2048, Color Lines, Brain Puzzles, and Memory Match. If you'd rather play with words, try the Word Generator and Word Unscrambler at lkforge.com/tools/.

Can I play Tic Tac Toe against the computer online?

Yes — Tic Tac Toe against the computer is free to play online, right in your browser, against an AI opponent, 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.

Is this an unbeatable Tic Tac Toe game?

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. Our benchmark of all 642 possible 3×3 games confirms it: the AI lost zero times.

Add This Tic-Tac-Toe AI to Your Website

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:

Copy this code

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.