Skip to main content

Tic Tac Toe

Classic X and O game. Play against the computer or a friend.

About Tic Tac Toe

Tic Tac Toe, also known as Noughts and Crosses, Xs and Os, or in India as "Zero-Kaata", is one of the oldest paper-and-pencil games still played daily by millions. Versions of three-in-a-row grid games go back at least to ancient Egypt, where similar boards have been found scratched into the roofing tiles of a temple in Kurna. The Romans played a close cousin called Terni Lapilli. By the 19th century, the modern three-by-three grid with X and O markers had settled into the form we still recognise. It is, I'd argue, the perfect first game to teach a child: the rules take ten seconds, every round ends in under a minute, and the strategy depth is genuinely deeper than it looks at first.

Our HTML5 version offers three single-player difficulty modes against an AI opponent, plus a local two-player mode so you can hand the laptop or phone to a friend. The Easy AI plays a random legal move and is suitable for beginners or young children learning the game. The Medium AI blocks immediate wins and takes any immediate win it sees but does not look further ahead. The Hard AI uses the minimax algorithm, the same family of techniques that powered the first computer chess programs in the 1950s, which means perfect play and an unbeatable opponent. Against the Hard AI every game ends in either a loss for you or a draw. There is no winning move.

How to Play Tic Tac Toe

The board is a 3×3 grid of empty squares. Two players take turns placing their marker, traditionally X for the first player and O for the second, in any empty square. The first player to align three of their own markers in a row, column, or diagonal wins the game. If the board fills up without anyone making a line, the result is a draw. Tap or click any empty cell on your turn. In two-player mode the device passes between players each turn; in solo mode the AI moves immediately after you.

One of the first mathematical results most children ever encounter is that Tic Tac Toe is a solved game. With perfect play from both sides the result is always a draw, never a win. That is also the reason a four-year-old eventually stops finding the game exciting against an adult, and the reason it has stayed in the cultural memory for so long: it is the first game most of us learn we cannot "beat" the way we beat Snake or Pong, only avoid losing.

Strategy Guide: 6 Ways to Stop Losing

  1. Take the centre first. If you go first and the centre is empty, take it. The centre square is part of four winning lines (two diagonals, one row, one column), more than any other cell. Statistically, no other opening gives you better chances.
  2. If the centre is taken, take a corner. When you are going second and the AI grabs the centre, the only reply that does not lose is a corner. Edges look symmetrical but they are part of only three lines and lead to forced losses against good opponents.
  3. Always check for forks. A "fork" is a position where you threaten to win in two different lines on your next move. Your opponent can only block one, so the other wins. Forks usually appear when you control three of the four corners and the centre.
  4. Block your opponent's forks before they happen. When you spot that the opponent is one move away from creating a fork, take that square first or force them to defend by threatening a win of your own.
  5. Don't chase wins that don't exist. Against an opponent who knows the basics, accept early that a draw is a good outcome. Greedy moves trying to "force" a win against perfect play create the very holes a fork exploits.
  6. Watch the diagonals. Diagonal lines are easier to miss than rows and columns. Train yourself to check both diagonals every move, especially when the centre is taken.

Common Mistakes I See Beginners Make

  • Opening with an edge. Edges are the worst opening move and let a knowledgeable opponent force a win within four moves.
  • Blocking instead of attacking. If you can make a winning line yourself, take it, even if your opponent is one move from winning. They will spend their next move blocking your win instead of completing theirs.
  • Forgetting to count threats. Late-game, count how many lines each side is one move from completing. Whoever has more is in trouble.
  • Playing too fast. Even at speed, a deliberate two-second pause to scan the diagonals will save more games than a fast reflexive move.

FAQ

Can the AI really be unbeatable?

Yes, on Hard difficulty. The Hard AI plays the minimax algorithm, which enumerates every possible future board state and picks the one that minimises your best response. Against perfect play from both sides, Tic Tac Toe is mathematically proven to end in a draw, there is no opening move that forces a win.

What's the difference between the difficulty levels?

Easy AI moves randomly into any empty square. Medium AI blocks your immediate winning threats and takes any winning move it sees, but only looks one move ahead. Hard AI uses minimax to look at every possible game continuation, you cannot win against it, only draw.

Is Tic Tac Toe good for children?

Excellent. There is no violence, the rules are simple enough for a four-year-old, and the game introduces basic strategic thinking: pattern recognition, forward planning, and the concept of forced moves. It is also one of the easiest games to use as a teaching tool for "if I do this, what will my opponent do?" reasoning.

How many possible Tic Tac Toe games are there?

There are 255,168 possible games when you account for all legal sequences of moves. After removing reflections and rotations of the board, only 138 are essentially different. Of those, 91 end in an X win, 44 in an O win, and 3 in a draw, under non-optimal play.

Who goes first, X or O?

The traditional rule is X first. In our solo mode, you play X and the AI plays O so you always have the first-move advantage. In two-player mode either player can start; we recommend alternating between rounds.

What's the oldest known version of this game?

Three-in-a-row games appear on Egyptian temple roofing tiles dated around the first century BCE. The Roman Terni Lapilli is the same game with three pieces per player rather than nine total marks. The modern X-and-O notation stabilised in 19th-century England under the name "Noughts and Crosses."

Why does every game against the Hard AI end in a draw?

Because Tic Tac Toe is a "solved" game. Computer scientists proved decades ago that perfect play from both sides always leads to a draw. The Hard AI plays perfectly, so the best outcome you can achieve is a draw, which itself takes some skill to force.

Is there a way to actually win against perfect play?

No. The proof is exhaustive and well-known: every opening you make has at least one reply that prevents a forced win, and the same is true at every subsequent move. Your goal against a strong opponent should be to never lose. A drawn game against the Hard AI is a perfectly played game on your side.