Tic Tac Toe
Play Tic Tac Toe against the computer on a 3×3 board.
FAQ
How do I play Tic Tac Toe?
What do the three difficulty levels change?
Can the computer move first?
How are wins, draws and streaks recorded?
How to use
- Pick a level and first move
Choose easy, normal or perfect at the top, then decide whether you or the computer opens the round. Changing either option starts a fresh round straight away.
- Tap a cell to place a mark
The side that moves first marks X and the other marks O. Tap an empty cell and the computer answers after a short pause, during which extra taps are ignored.
- Line up three to win
Any row, column or diagonal of three marks wins the round. If all nine cells fill up with no line, the round is a draw.
- Play with the keyboard
Move the cursor with the arrow keys and press Enter, or press 1 to 9 for the matching cell. Press N at any time for a new round.
- Track your record
The HUD counts wins, draws and losses plus your current streak. Your best streak is stored in this browser, so it survives a refresh.
About this tool
Tic Tac Toe is the easiest two-player board game to pick up: nine cells, one rule, and a round that lasts seconds. The play is richer than it looks. The first player has a few genuinely different openings, and the second player must choose between blocking and building a threat. Most people drew the grid on the back of a notebook as a child. The mathematics came much later, when game theory proved that perfect play from both sides always ends in a draw.
This version runs entirely in your browser. The three levels cover random play, mostly optimal play, and a full search. The perfect level walks the whole game tree with minimax before every move. It never misses your three in a row, and it never passes up its own win. Switch the level or the first player whenever you like, and the HUD keeps a running count of wins, draws, losses and your current streak.
How it works
The state space is small enough to brute force: fewer than six thousand legal positions, and the full tree was solved decades ago. The conclusion is that two perfect players always draw. The first player has no forced win, and the second player cannot force one either. Every careful game ends level, whatever order the nine cells happen to be filled in. That is why the draw shows up so often. One careless move decides the round.
Minimax walks every empty cell to the end of the game. On its own turn it keeps the move with the highest score, and on the opponent turn it assumes the lowest scoring reply. A win in fewer moves scores higher, and a loss in more moves costs less, so speed and delay both fall out of the search. The implementation also checks for an immediate three first, then blocks any immediate threat from the other side.
When to use it
- Thirty seconds in a queue
A round usually takes under a minute, so it fits into a lift ride or a coffee break. There is nothing to install and the board opens straight away. Losing costs nothing and winning feels good, which makes it an easy way to reset your attention between two tasks.
- Teaching the rules to a child
A three by three grid is simple enough for a child to follow. Turns, marks and a line of three are all visible at a glance. The easy level plays at random, so a young player wins often. The normal and perfect levels wait for the day they want a real opponent.
- Seeing a search algorithm work
If you are learning algorithms, this is the smallest useful minimax problem. The state space is tiny and every result can be checked by hand. Switch to the perfect level and watch it block each of your threats. Then read the recursion in the source and compare it with the board.
Tips & tricks
- Open on the centre or a corner: more lines means more chances to fork.
- If the opponent has two marks in a line, block before you build.
- Use the perfect level as a reference and replay its replies move by move.
Things to watch
- Chasing your own line
Building two marks in a row feels productive, but a threat you ignore is a threat that lands. Before every move, scan the opponent marks for two in a line. Blocking usually outranks extending your own position, because the side that scores first wins the round.
- Missing a double threat
One move can create two separate winning cells at once. You can only block one of them, so the round is decided on the next move. Stop the fork one turn earlier by taking the cell that would join both lines, and the double threat never appears.
- Hiding on the edges
A corner takes part in three lines, the centre in four, and an edge cell in only two. Opening on an edge hands the opponent more ways to build a fork. Prefer the centre or a corner, and count the lines a cell belongs to before you commit.