Tic-Tac-Toe vs AI - Play Unbeatable Noughts & Crosses
Games & Puzzles
Play Tic-Tac-Toe against Easy, Medium, or Impossible AI, with clear blunder rates, or challenge a friend in two-player mode. Track wins, losses, and draws.
Click New Game to start.
How to use this tool
- Choose "vs AI" or "2 Players" mode. In vs AI, choose Easy, Medium, or Impossible.
- Click any empty cell to place your mark. You play X first against the AI.
- Get three in a row - horizontally, vertically, or diagonally - to win.
Rules
Tic-tac-toe is a two-player game played on a 3×3 grid. Players alternate marking squares: one player places X, the other places O. The first to mark three squares in a horizontal, vertical, or diagonal line wins. If all nine squares are filled with no winner, the game is a draw (also called a “cat’s game”).
Controls: click any empty square to place your mark.
Perfect play
Tic-tac-toe is a solved game: with optimal play from both sides, every game ends in a draw. Impossible uses the minimax algorithm and always chooses one of the best-scoring legal moves. Easy and Medium use the same search, but may deliberately choose a weaker move: Easy does so 70% of the time and Medium 30% of the time when a weaker legal move exists. If all legal moves are tied for best, every level chooses a best move.
Optimal strategy
- Go first in the center: the center square participates in 4 winning lines (all 3 rows/columns, and both diagonals). It is the strongest opening move.
- If you go second: if the opponent takes the center, play a corner. If the opponent takes a corner, play the center.
- Create forks: a fork is a position where you have two ways to win on your next move. The opponent can only block one, so you win. Forks are the only way to beat a non-optimal opponent.
- Block forks first: if your opponent is building a fork, disrupt it by creating your own two-in-a-row that forces them to defend instead.
Fun fact
Tic-tac-toe is one of the simplest examples of a game tree - a branching structure representing all possible moves. The full game tree has about 255,168 possible games before accounting for symmetry. It was among the first games to be fully analyzed by computers and remains a classic teaching example in artificial intelligence.
AI algorithm: plain minimax
The computer opponent uses plain minimax: it recursively evaluates every
possible continuation to a win, loss, or draw. The AI playing O tries to maximize the score,
while the human playing X is assumed to minimize it. The search uses a depth-aware score:
10 - depth for an O win, depth - 10 for an X win, and 0
for a draw. This rewards the AI for winning sooner and for delaying a loss when it cannot avoid
one.
The shipped search does not use alpha-beta pruning or claim a reduced node count; it evaluates the available move tree directly. The 3×3 game has a small enough search tree for this simple approach. Easy and Medium apply their stated blunder chance after comparing each legal move's minimax score, and select a lower-scoring legal move only when one is available.
On Impossible, optimal play from both sides ends in a draw; if X makes a mistake, the AI can win. Easy and Medium can be beaten because their deliberate blunders sometimes leave a winning reply. The selected difficulty is stored in this browser, like the cumulative score and the in-progress game save; board play and move selection stay on the device.
Variants
- 4×4 tic-tac-toe: requires 4 in a row; more complex with many more possible games.
- 3D tic-tac-toe (4×4×4): played on a 4×4×4 grid; first player wins with optimal play.
- Ultimate tic-tac-toe: a 3×3 grid of 3×3 boards; each small win claims a large board square; significantly more complex and strategic.
Frequently asked questions
Can I ever beat the AI?
Easy and Medium can deliberately choose a non-best legal move, so you can beat them. Impossible always chooses a minimax-best move; optimal play against it ends in a draw, and you cannot force a win.
How do the AI difficulty levels work?
Easy chooses a legal move below the minimax-best score 70% of the time when a worse move exists. Medium does so 30% of the time. Impossible never blunders, and every level chooses a best move when no worse legal move exists.
Who goes first?
In AI mode, you play as X and always move first. In 2-player mode, X goes first.
More games & puzzles
- 2048Slide numbered tiles on a 4×4 grid to combine them and reach the 2048 tile in this addictive puzzle game.
- Aim TrainerImprove your mouse accuracy and click speed. Targets appear at random positions - click them as fast as possible. Track your accuracy and average reaction time.
- Blind Spot TestFind your eye's natural blind spot (optic disc) using a monocular fixation test. Cover one eye, fixate on the cross, and discover where the dot vanishes from your field of view.
- Block StackerStack falling tetrominoes to clear lines in this Tetris-style puzzle game.
- Brick BreakerBreak all the bricks with a bouncing ball and paddle.
- Checkers GamePlay checkers (draughts) against an AI opponent in your browser.