Tic Tac Toe

Play noughts and crosses against three levels of computer opponent — or pass the device and play a friend. Scores are kept on this device.

🔒 Your data never leaves your device🆓 Free🙅 No sign-up
🫵 Your turn — you are X
Click a square, or use Tab and the arrow keys and press Enter.

📊 Score

🏆 You
0
🤝 Draws
0
🤖 Computer
0
Games played
0
🔒 Everything runs in your browser. Your score tally is saved only on this device, and nothing is uploaded.

How to play

  1. Choose your opponent: 🤖 Vs computer or 👥 Two players on the same device.
  2. Against the computer, pick a strength — Easy, Medium or Unbeatable — and decide whether it moves first.
  3. Claim a square by clicking or tapping it, or by tabbing into the board and pressing Enter. You are ❌ unless the computer opens, in which case you are ⭕.
  4. Get three of your marks in a row — across, down or diagonally. The winning three are highlighted in green.
  5. Press 🔁 Rematch for another game. The running tally of wins, draws and losses sits under the board.

Rules

Nine squares, two players, alternating turns, and one goal: three in a row. There are eight ways to make a line — three rows, three columns and two diagonals. If all nine squares fill up without a line, the game is a draw.

That is the whole rulebook, which is exactly why the game is interesting to think about. A few conventions of this particular board are worth stating:

Situation What happens here
A square is already taken Nothing happens — taken squares are disabled
The board fills with no line Draw, counted in the tally
You change level or first player The current game resets
You switch between modes Each mode keeps its own score tally

Strategy that actually works

Against a weak opponent, a simple priority list wins most games. On your turn, work down it and take the first thing that applies:

  1. Win now. If two of your marks share a line and the third square is free, take it.
  2. Block now. If your opponent has two in a line, take the third square before they do.
  3. Make a fork. Take a square that gives you two separate threats at once. Your opponent can only block one.
  4. Stop their fork. If they are about to create two threats, either block the key square or force them to respond by making a threat of your own.
  5. Take the centre, then an opposite corner, then any corner, then an edge.

Point three is where most games are decided. A fork is not a clever trick so much as the whole game: since your opponent can only answer one threat per turn, creating two simultaneously is a guaranteed win. The classic version is to take two opposite corners with the centre already contested — whichever corner you complete, a line runs through it two ways.

The maths behind a solved game

Tic tac toe is solved, meaning the outcome is known from the empty board with best play from both sides: a draw. This is not an opinion about the game, it is a fact you can verify by exhaustion, and the Unbeatable level does exactly that.

The number of distinct positions is small enough to search completely. A naive upper bound is 3⁹ = 19,683 ways to fill nine squares with X, O or blank, but most of those are unreachable — they have the wrong number of each mark, or contain two completed lines. Filtering down to legal, reachable positions leaves 5,478, of which 958 are finished games. Counting the order moves were played in gives 255,168 possible complete games. By computing standards that is nothing.

The algorithm behind the Unbeatable level is minimax: from any position, assume both sides play their best, score the leaves of the tree — a win for the computer as positive, a loss as negative, a draw as zero — and pass the best available value back up. Because the tree is tiny, it can be searched to the very end every single move, and a player that always sees the end of the game cannot be tricked.

Two refinements make it behave well rather than merely correctly:

  • Alpha-beta pruning. As the search runs it keeps track of the best result each side has already guaranteed elsewhere. When a branch cannot possibly beat that, it stops exploring it. The answer is identical; the work is a fraction. In code this reads as if (alpha >= beta) break;.
  • Depth-preferred scoring. A win at move three and a win at move nine are both wins, so plain minimax is indifferent between them — which makes a computer that toys with you, taking the long route to a victory it already has. Scoring a win as 10 - depth and a loss as depth - 10 makes it prefer the quickest win and the slowest loss, so it finishes you off cleanly and makes you work for a win when it is losing.

There is one more asymmetry worth knowing: the first player has a genuine advantage. Going first does not force a win against perfect play, but it wins far more often against imperfect play, simply because more of the opponent’s possible replies are mistakes. If you can beat the Medium computer comfortably as X, try turning on “Computer moves first” and see how much harder the same opponent feels.

Privacy

Everything happens in your browser. The computer’s moves are calculated on your own device — there is no server involved in a game — and your win, draw and loss counts live in this browser’s localStorage, separately for the computer and two-player modes. Nothing is uploaded, there is no account, and pressing Reset score or clearing your site data removes the tally for good.

Frequently asked questions

Can I beat the Unbeatable computer?

No, and that is not a limitation of this page. Tic tac toe is a solved game — with perfect play from both sides it is always a draw, and perfect play never loses. The Unbeatable level searches every remaining position, so a draw is the best result available to you. If you want to win, drop to Easy or Medium.

What is the difference between the three levels?

Easy picks any free square at random. Medium takes a winning move if it has one, blocks yours if you have one, and otherwise prefers the centre, then a corner, then an edge - it plays one move ahead, so it can still be caught by a fork. Unbeatable searches the full game tree and plays the move that wins fastest or loses slowest.

Who moves first?

You do by default, playing X. Turn on "Computer moves first" and it takes X while you play O, which is much harder against a strong opponent - the first player has a real edge in this game.

How do I play against another person?

Switch the opponent toggle to Two players. X and O then alternate on the same device, and the score panel tracks X wins, draws and O wins instead of you-versus-computer.

Can I play with the keyboard?

Yes. Tab into the board, move between squares with the arrow keys or W, A, S and D, and press Enter or Space to claim one. Results are announced to screen readers as they happen.

Is my score saved?

Your win, draw and loss counts are kept in this browser's local storage, separately for the computer and two-player modes. They are not sent anywhere and do not follow you to another device. The Reset score button clears the tally for whichever mode you are in.

Related tools

Last reviewed: