⭕ Tic Tac Toe

Play tic tac toe against a friend or a computer opponent with easy, medium and unbeatable hard difficulty.

Game Mode

Difficulty

You play as

Draw

ties

🤖 Computer is thinking

How to play

1.

Take turns placing your mark on an empty square by clicking it.

2.

Get three in a row — horizontally, vertically, or diagonally — to win.

3.

In vs Computer mode: Easy is random, Medium is smart, Hard is unbeatable.

4.

Hard uses the Minimax algorithm. Your best result against it is a draw!

Related Tools

How the computer opponent chooses its move

The three difficulty levels use genuinely different logic. Easy simply picks at random from the empty squares, which means it will miss both winning moves and blocks, so a careless player can still beat it but a careful one always will.

Medium plays strategically most of the time but deliberately chooses at random on roughly three moves in ten. That injected randomness is what makes it beatable: it will usually take a win and usually block yours, but not always, so games stay competitive rather than grinding to inevitable draws.

Hard runs minimax with alpha-beta pruning. Minimax explores the full game tree from the current position, assuming the computer maximises its own score and that you play to minimise it, scoring a win, a draw and a loss at the terminal positions and propagating those values back up. Alpha-beta pruning discards branches that cannot affect the final choice, which makes the search fast enough to be instantaneous on a nine-square board. Because tic tac toe is a solved game, perfect play always ends in a draw, so a hard opponent never loses. A short delay is added before it moves, so the reply does not appear instantly.

Worked example: why the centre and corners matter

The board has nine squares and eight winning lines: three rows, three columns and two diagonals. How many of those lines a square belongs to is what makes it valuable.

The centre square sits on four lines, its row, its column and both diagonals. Each corner sits on three: a row, a column and one diagonal. Each edge square sits on only two. So the centre is worth twice as much as an edge by that measure, and it is why an opening move to the centre is the strongest available.

Here is a concrete trap. You take the centre as X. The computer replies on an edge rather than a corner. You then take a corner, threatening a line through the centre. The opponent must block. You take a second corner that sits on a different line also running through your centre, and you now have two separate threats in one move. Only one can be blocked, so your next move wins.

Against the hard opponent that sequence never gets started, because minimax sees the fork several moves ahead and answers your centre opening with a corner, which is the only reply that holds the draw.

Reading the scoreboard and playing to a draw

The scoreboard counts wins for X, wins for O and draws for the whole session, and it survives a board reset, so it accumulates across a run of games. In player versus computer mode you are always the human symbol, so your column of the scoreboard is the one to watch. Against the hard setting a healthy record looks like a long row of draws: that is the correct result, not a failure.

If you are losing to medium, the fix is almost always to stop chasing your own line and start watching the opponent's. Before every move, check whether they have two in a line with the third square empty, and block it. Only when there is no immediate threat should you build your own.

The two openings worth learning are centre and corner. If you move first and take the centre, the only reply that draws is a corner. If you take a corner first, the only reply that draws is the centre. Anything else loses against accurate play.

Two-player mode adds no computer logic: it alternates turns and checks the eight winning lines after each move, so spotting threats is up to the players.

Frequently Asked Questions

No. Hard uses minimax with alpha-beta pruning, which evaluates every possible continuation and always selects an optimal move. Tic tac toe is a solved game in which perfect play by both sides ends in a draw, so the best result available against hard is a drawn game. Try medium if you want to win.
The centre, because it belongs to four of the eight winning lines while a corner belongs to three and an edge to only two. After a centre opening, the only reply that holds a draw is a corner. If you open in a corner instead, your opponent must take the centre to survive.
Yes. Select the player versus player mode and the board alternates between X and O with no computer involvement, so two people can share one screen and take turns. Player names are editable, and the scoreboard tracks wins for each symbol plus drawn games across the session.
Easy picks a random empty square every time, so it regularly misses both wins and blocks. Medium plays strategically but chooses randomly about thirty percent of the time, which means it usually takes a win and usually blocks yours while still leaving openings. Medium is the setting where games stay genuinely competitive.
It builds the tree of all remaining moves and scores each finished position as a win, loss or draw. Scores propagate back up on the assumption that the computer picks the highest and you pick the lowest, so the move chosen is the best against perfect defence. Alpha-beta pruning skips branches that cannot change the outcome.