Tic-Tac-Toe Solver

Enter any Tic-Tac-Toe position, pick whose turn it is, and a perfect-play engine highlights the best move and tells you whether it's a win, a loss or a draw. Everything runs in your browser, nothing is uploaded.

How to Use the Solver

Click a square to cycle it through blank, X and O, and recreate the position on your board. Set whose turn it is, then press Solve. The best move (or moves, if several are equally good) lights up in green, and the message tells you the outcome with perfect play — a forced win, a certain loss, or a draw. Clear empties the board.

How the Solver Works

Tic-Tac-Toe is small enough to solve exactly. The engine uses minimax: it plays out every possible continuation to the end of the game, assuming both sides play perfectly, and scores each — a win, a loss or a draw — preferring faster wins and slower losses. The move that leads to the best guaranteed result is the answer. Because it searches the entire game tree, the advice is provably optimal. It all runs on your device.

Frequently Asked Questions

How do I enter a position?
To enter a position, click a square to cycle it through blank, X and O until the board matches yours. Set the Whose turn? selector to X to move or O to move. Then press Solve to see the best move for that player.
Does it play perfectly?
Yes — the solver plays perfectly. It searches the whole game tree with minimax, so it always finds a move that guarantees the best possible outcome: a win if one is forced, otherwise a draw. Because the board has only nine squares, that tree is small enough to search exhaustively every time.
Can Tic-Tac-Toe always be won?
No — Tic-Tac-Toe cannot always be won. Between two perfect players every game ends in a draw. A win only appears when the opponent makes a mistake, and the solver shows you exactly how to punish one and how never to make one.
What do the highlighted squares mean?
The green highlighted squares are the best moves for the side to move. Several may be highlighted at once, which means they are equally good under perfect play and you can take any of them. A square left unhighlighted leads to a worse result than the highlighted ones.
Is anything uploaded?
No — nothing you enter is uploaded. The board and the search run entirely in your browser, so no position is sent to a server. Closing the tab clears the board.

Related Solvers & Games

Prefer to play? Take on the unbeatable AI Tic-Tac-Toe. Solving other games? Try the Connect 4 Solver or the Sudoku Solver, or browse all AI solvers & analyzers.

New to the theory? TicToe.org's guide on how to never lose at tic-tac-toe walks through the key positions this solver evaluates.

Add This Tic-Tac-Toe Solver to Your Website

Put the Tic-Tac-Toe Solver on your own page — free, no sign-up, no watermark. It runs entirely in your visitors' browsers. Copy the snippet and paste it into your page's HTML.

The credit line under the widget links back to LK Forge — please keep it so others can find it too.