Tic-Tac-Toe
Medium computer · Single games · game 1
You · X
0
Draws
0
Computer · O
0
Your move. You're X.
Press a square to play it. Keys 1 to 9 play the squares in reading order; with the board focused, the arrow keys move between squares.
Play tic-tac-toe online, free
Tic-tac-toe, also called noughts and crosses, is played on a 3×3 grid: two players take turns marking a square with X or O, and the first to get three in a row across, down or diagonally wins. If all nine squares fill with no line, the game is a draw. On this page you can play the computer at four levels, from an Easy opponent that plays almost at random to an Unbeatable one that has worked out every possible game, or play a friend on the same phone or computer. Matches can be single games or best of 3, 5 or 7, the first move alternates so nobody keeps the advantage, and Undo and Hint are there when you want to learn. It runs in your browser with nothing to install and no account, and your record is saved on your device.
How to play
- Pick an opponent. Choose vs Computer and a level, or 2 Players to pass the device back and forth. Changing either starts a fresh match.
- Place your mark. Tap or click an empty square. X always moves first, and whoever starts the game plays X; the scoreboard shows which mark each side has this game.
- Get three in a row. The first complete line wins and is struck through. A full board with no line is a draw.
- Keep playing. Press Next game (or tap the board) for the next game. By default the first move alternates; in Options you can choose who always starts and play a best-of match.
- Get help. Undo takes back your last move (and the computer's reply). Hint highlights the strongest square for whoever is to move.
With a keyboard, the keys 1 to 9 play the squares in reading order (1 is the top left, 5 the centre, 9 the bottom right). You can also Tab to the board, move with the arrow keys and press Enter. U undoes, H gives a hint and N starts the next game.
The four computer levels
| Level | How it plays | Can you win? |
|---|---|---|
| Easy | Plays almost at random. It takes a winning square about half the time and never blocks you. | Easily |
| Medium | Always takes a win and blocks your direct threats, then grabs the centre or a corner. Forks beat it. | Yes, with a fork |
| Hard | Looks three moves ahead, so it sets up its own forks and never misses a block, but it can't see a fork you're preparing. | Yes, with a trap it can't see |
| Unbeatable | Searches every possible game and never loses. The best you can do is a draw. | No: a draw is the best result |
Unbeatable uses minimax: before every move it plays out each possible continuation to the end, assuming you always find your best reply. Among moves that are equally good it chooses the one that leaves you the most ways to go wrong, so when it goes first it opens in a corner, where seven of your eight replies lose. Getting a draw against it is the real test of your defence.
How to win at tic-tac-toe
Tic-tac-toe can't be won against a perfect player, but almost everyone makes mistakes, and nearly every win comes from a fork: one move that makes two threats at once. Your opponent can block only one of them.
A worked example: the opposite-corner trap
- As X, take the top-left corner.
- O takes the centre (the only reply that doesn't lose outright).
- Take the opposite corner, bottom right. Now O must be careful.
- If O plays another corner, say top right, it threatens the diagonal, so you block in the bottom-left corner.
- That block gives you two open lines at once, down the left side and along the bottom. O can stop only one, and you win with the other.
The Medium computer falls for this every time it takes a corner at step 4, and so does the Hard computer most of the time, because the fork happens just beyond what it looks at. The correct defence for O at step 4 is an edge square, which forces you to block and keeps the game level.
Strategy tips
- Win, then block, then build. Every turn, look first for a square that wins, then for one your opponent needs, and only then set up your own threats.
- Open in a corner. It leaves your opponent a single safe reply. The centre is solid but gives away less; an edge is the weakest start.
- Answer a corner with the centre. Every other reply to a corner opening loses against correct play.
- Answer the centre with a corner. An edge reply to a centre opening lets X build a fork.
- As O, don't copy corners. If X holds two opposite corners and you have the centre, play an edge, not a corner.
- Count lines, not squares. A square is only as strong as the open lines through it. The centre sits on four, each corner on three, each edge on two.
Common mistakes
- Making a threat that forces your opponent to block in the very square that gives them a fork.
- Blocking one threat while missing that the other player already has two.
- Answering a corner or centre opening with an edge square. Against correct play that reply loses, which is why the computer at Unbeatable never makes it.
- Thinking only one move ahead. The Hard computer does exactly that plus one, which is why the trap above works on it.
Tic-tac-toe by the numbers
If you list every way a game can unfold, move by move, until someone wins or the board is full, there are 255,168 different games. The first player wins 131,184 of them, the second player 77,904, and 46,080 are draws. That tilt toward X is why going first matters and why the first move alternates here by default. Yet with best play from both sides every game is a draw: the advantage only turns into a win if the second player slips.
Playing with a friend
In 2 Players mode the computer stays out of it: you share one screen, the status line says whose turn it is and which mark they have, and the scoreboard counts wins for Player 1 and Player 2 plus draws. Turn on a best-of-5 match in Options for a proper contest, and use Undo for take-backs if you both agree. If you'd rather play something with more depth on the same device, try Connect Four, where you need four in a row on a 7×6 grid, checkers or chess. To settle who goes first, a round of rock paper scissors works too.
A little history
Three-in-a-row boards have been found scratched into roofing tiles from ancient Egypt, from around 1300 BC, and the Romans played a version called terni lapilli, "three pebbles at a time", in which each player had only three pieces to move around. The pencil-and-paper game has been a classroom staple for generations. It also has a place in computing history: OXO, written by Sandy Douglas in 1952 for the EDSAC computer at the University of Cambridge, played noughts and crosses against a person and is often cited as one of the earliest video games. Because the game is small enough to analyse completely, it has long been a favourite first example for teaching how computers search game trees, the same idea behind the Unbeatable level here and the stronger opponents in Reversi and Connect Four.
Frequently Asked Questions
Can you beat the computer at tic-tac-toe?
On Easy, Medium and Hard, yes. Easy plays almost at random, Medium falls for a fork, and Hard sets up its own forks but can't see yours coming. Unbeatable is different: it searches every possible game before it moves, so the best anyone can do against it is a draw.
Is tic-tac-toe always a draw?
With perfect play from both sides, yes. Neither player can force a win against an opponent who never makes a mistake, which is why games between experienced players almost always end level. Wins come from a missed block or, more often, a fork the other player didn't see.
What is the best first move in tic-tac-toe?
A corner. The centre is safe too, but a corner sets more traps: of the eight replies, only the centre avoids a forced loss, which is why the Unbeatable computer opens in a corner when it goes first. The four edge squares are the weakest opening.
How do you win tic-tac-toe every time?
Against a perfect opponent you can't; the game is a draw with best play. Against anyone who makes mistakes, start in a corner and aim for a fork: if they answer anywhere but the centre you can force a win, and even after a centre reply, taking the opposite corner sets a trap that beats the Medium and usually the Hard computer.
What is a fork in tic-tac-toe?
A move that creates two winning threats at once: two different lines that each need one more mark. Your opponent can block only one, so you complete the other next turn. Making forks, and stopping your opponent from making them, is the whole strategy of the game.
How do I play tic-tac-toe with a friend?
Choose 2 Players and pass the phone or share the keyboard. The scoreboard keeps a running count for Player 1 and Player 2, and by default the two of you take turns going first, so the first-move advantage is shared fairly. Pick a best-of-3, 5 or 7 match in Options for a proper contest.
How does the unbeatable tic-tac-toe computer work?
It uses minimax: before each move it plays out every possible continuation to the end and assumes you will always reply with your best move. Tic-tac-toe is small enough to search completely in a fraction of a second. When several moves are equally good, it picks the one that leaves you the most ways to go wrong.
Who goes first in tic-tac-toe?
X always moves first, and whoever starts plays X. Here the two sides alternate by default, so you go first in one game and the computer (or your friend) in the next. In Options you can make one side always start instead.
How many possible games of tic-tac-toe are there?
Counting every distinct sequence of moves until someone wins or the board is full, there are 255,168. The first player wins 131,184 of them, the second player 77,904, and 46,080 end in a draw. Many are rotations or mirror images of each other, which is why the game can be solved by hand.
Is tic-tac-toe the same as noughts and crosses?
Yes. Noughts and crosses is the usual British name, and Xs and Os is another. The rules are identical: a 3×3 grid, players alternate, and three in a row across, down or diagonally wins.
Is my score saved?
Yes, on this device only. Your settings, the current game and match, and your record against each computer level are kept in your browser's local storage, so they survive a reload. Nothing is uploaded, and Reset record in Options clears the statistics.
Can I play with a keyboard?
Yes. Press 1 to 9 to play a square (1 is the top left, 9 the bottom right, in reading order), or Tab to the board and use the arrow keys and Enter. U undoes your last move, H shows a hint and N starts the next game.
More games to play
Free, browser-based, and instant — no installs or accounts.