gekro
GitHub LinkedIn

Tic Tac Toe

Play free Tic Tac Toe against a computer at three levels, including one that never loses, or against a friend on the same device.

Turn Your turn (X)

You (X)0

Draws0

Computer (O)0

Unbeaten streak (Medium): 0 - best saved: -

Arrow keys move between squares, Enter or Space places your mark, and the number keys 1 to 9 place one directly (1 is top left, 9 is bottom right). The tally counts finished games (against the computer, or X and O wins in two-player mode); the unbeaten streak counts only finished games against the computer, where a win or a draw extends it and a loss ends it. Restarting a game you have already moved in also ends the streak. Difficulty and "You play" apply to the computer only.

How the computer plays

Easy picks any empty square at random. Medium takes a winning square if it has one, otherwise blocks yours, otherwise picks at random. Unbeatable uses minimax: it imagines every possible continuation, assumes you will always reply as well as you can, and plays the square whose worst case is best. Only 5,478 different positions can ever occur, so it simply solves all of them, and it never loses as X or as O. Against perfect play every game is a draw.

As-is, no warranty. These apps are free under their listed license and run entirely in your browser. Use at your own risk — don't blame me if your PC catches fire, your dog runs away, or the math turns out wrong. Verify anything that actually matters. None of this is professional financial, medical, legal, or engineering advice.

© 2026 Rohit Burani · MIT · Built at gekro.com · View source ↗

Guide

How to play

Take turns placing X and O on a 3 x 3 grid. The first to get three in a row, across, down or diagonally, wins. If the board fills up with no line, it is a draw. X always goes first.

Pick Computer or Two players on this device under Opponent. Against the computer, choose a difficulty and whether you play X (you move first) or O (the computer moves first). Click or tap a square, or use the keyboard: arrow keys move between squares, Enter or Space places your mark, and the number keys 1 to 9 place one directly (1 is the top left, 9 is the bottom right). X is drawn in sky blue and O in rose, inside a violet frame, and the Turn pill and the tally boxes use the same two colours (amber for draws). On a device with a mouse, hovering an empty square shows a faint preview of the mark you are about to place. The winning line sweeps in green, and it is also outlined, filled and underlined, so it does not rely on colour alone.

The computer answers after a short pause of about a third of a second, and the board is locked while it thinks. If your system asks for reduced motion, the pause, the pop-in animation, the winning sweep and the small dots that appear after a win are all switched off.

How it works

The board has only nine squares, so it can be searched completely. Counting by exhaustive enumeration, which the test suite repeats on every run:

  • 5,478 different positions can ever occur in a legal game, counting the empty board once and counting a position once however it was reached.
  • 255,168 different complete games can be played, meaning distinct sequences of moves that end in a win or a full board. Of those, 131,184 end in an X win, 77,904 in an O win and 46,080 in a draw. These count move sequences, not probabilities, because a player choosing moves at random does not make every sequence equally likely.

The three difficulties use that structure in different amounts:

  • Easy picks a random empty square. It only ever plays a legal move, and nothing more.
  • Medium looks one move ahead. If it can complete a line, it does. Otherwise, if you could complete a line next turn, it blocks that square. Otherwise it plays at random. It never misses a win or a block that is right in front of it, but it does not plan, so a fork (two threats at once) beats it.
  • Unbeatable uses minimax. In plain words: for every square it could play, it imagines every reply you could make, every reply it could make to that, and so on to the end of the game. It assumes you will always choose the reply that is worst for it, and it picks the square whose worst case is best. A win counts for more the sooner it arrives, so it takes quick wins. When several squares are equally good it picks one at random, so games differ. Because there are only 5,478 positions, each is solved once and remembered, and the whole search is effectively instant.

What the tests prove about Unbeatable: they walk every possible sequence of opponent moves, with Unbeatable playing any of its best moves at each turn, once with it as X and once with it as O. It does not lose in a single one. Two Unbeatable players always draw, which matches the long-known result that Tic Tac Toe is a draw under perfect play. The tests also check the minimax values against a plain, separate depth-first search of every position, and check that Medium takes an immediate win and an immediate block in every position where one exists.

Privacy and storage

Nothing is uploaded and there is no account. Your session tally (wins, draws, losses, or X wins, draws and O wins in two-player mode) lives only in the open page and disappears when you leave it. The only thing saved is your best unbeaten streak per difficulty, as small whole numbers inside a small JSON object in your browser’s local storage under one key. Clearing site data removes it. The page address records your settings (opponent, difficulty, side) so you can bookmark them, and nothing else.

Limits

  • Only finished games against the computer count toward the streak. A win or a draw extends it and a loss ends it. Restarting a game you have already moved in also ends the streak, so walking away from a lost game does not protect it.
  • The unbeaten streak counts draws, which is why it is the number worth watching on Unbeatable: you cannot win there, so a draw is the best result.
  • Two-player mode shares one device and has no streak or saved score.
  • Difficulty and “You play” apply only to the computer. In two-player mode both menus are switched off, so changing a game in progress is not possible; they keep their last values, which stay in the page address for when you play the computer.
  • It plays the standard 3 x 3 game only: no bigger boards, no online play, no undo.

Everything runs locally in your browser.

All Fun tools →

For informational purposes only. Not financial, medical, or legal advice. You are solely responsible for how you use these tools.