Tic-Tac-Toe

Play tic-tac-toe in your browser — pass-and-play with a friend or against an unbeatable minimax computer.

X to move

X wins
0
O wins
0
Draws
0
Moves played
0
No uploads. Your files stay on your device.

Free forever, no sign-up, no cookies. Buy me a coffee

How it works

Tic-tac-toe (noughts and crosses) is played on a 3×3 grid: X moves first and the first player to line up three of their marks in a row, column or diagonal wins. If all nine squares fill up with no line, the game is a draw. Click a square or move around the board with the arrow keys and press Enter or Space — every square is a real button, so the whole game is keyboard accessible and announced to screen readers through the live status line.

The computer opponent uses the minimax algorithm, searching every possible continuation and scoring a win as 10 − depth, a loss as depth − 10 and a draw as 0, so it prefers quick wins and slow losses. Because tic-tac-toe is a solved game, Impossible plays perfectly and can never be beaten — the best you can manage is a draw. Medium only takes an immediate win or blocks an immediate threat, and Easy picks a random empty square. Random moves come from a seeded generator, so adding ?seed=42 to the URL replays the same computer choices every time. Everything — the search, the scoreboard and the move list — runs in your browser; nothing is uploaded.

Frequently asked questions

How does the unbeatable computer work?

The Impossible difficulty uses the minimax algorithm. Before every move it searches every legal continuation to the end of the game and scores each outcome from its own point of view: a win is 10 minus the number of moves it took, a loss is that depth minus 10, and a draw is 0. Subtracting the depth makes it prefer the fastest win and the slowest loss. Tic-tac-toe is a solved game with only 255,168 possible games, so this search is instant and perfect — against Impossible the very best result available to you is a draw. Medium only grabs an immediate win or blocks an immediate threat, and Easy plays a random empty square.

How do you always win at tic-tac-toe?

You cannot force a win against an opponent who also plays perfectly — perfect play from both sides is always a draw. You can only win when the other player errs, so the practical strategy is to never make the first mistake: take the centre if it is free, otherwise take a corner; always complete three in a row when you can; always block your opponent's two-in-a-row; and look for forks, moves that create two winning threats at once so only one can be blocked. Opening in a corner is the strongest practical try, because the centre is the only reply that does not lose.

Can I play two players on one device?

Yes — Two players (pass and play) is the default mode, so you and a friend take turns on the same screen with X moving first. The live status line always says whose turn it is, the scoreboard tracks X wins, O wins and draws across games, and Undo takes back the last move (and un-scores a finished game). Switch the Opponent dropdown to Play the computer at any time; changing the opponent or difficulty starts a fresh board. Every square is a button, so arrow keys move the focus and Enter or Space places your mark.

Report a bug