Home › Fun & Games › Tic Tac Toe

Tic Tac Toe

Get three in a row before your opponent does. Play against the computer on Easy, Medium or Unbeatable, or pass the device to a friend for a 2-player game.

You (X)0
Draws0
Computer (O)0

Your move

Scores are kept separately for each difficulty and for 2-player games, and saved on this device. Press N for a new game.

Advertisement

How to use the Tic Tac Toe

  1. Choose a mode: vs Computer or 2 players.
  2. Pick a difficulty (Easy, Medium or Unbeatable) and who makes the first move.
  3. Tap a square to place your X. The computer replies with O, or your friend takes the next turn.
  4. Get three in a row horizontally, vertically or diagonally to win. A full board with no line is a draw.
  5. Press Play again or N for the next game. The scoreboard keeps track of wins and draws.

How the unbeatable AI works

The computer uses minimax, a classic game-tree search. For every empty square it imagines placing its O there, then assumes you reply with your best move, then it replies with its best move, and so on until each line of play ends. A finished game is scored +10 for a computer win, −10 for a loss and 0 for a draw, adjusted by the number of moves so that faster wins and slower losses score better. The computer then chooses a move with the highest guaranteed score. Alpha-beta pruning skips branches that cannot change the decision, so the search takes only a few milliseconds.

Because tic tac toe is small (only 5,478 legal positions), minimax can search the whole game. When several moves are equally good, the computer picks one at random, so games do not always look the same even though it never loses.

Tic tac toe by the numbers

FactValue
Possible games (move sequences)255,168
Games won by the first player131,184
Games won by the second player77,904
Games ending in a draw46,080
Legal board positions (including the empty board)5,478
Different finished positions958
Result with perfect playDraw

Strategy tips

  • Win if you can, block if you must. Always check for a square that completes your line, then for one that stops your opponent's.
  • Create a fork. A fork is a move that threatens two lines at once; your opponent can only block one.
  • Open in a corner. If your opponent answers with anything other than the centre, you can force a win.
  • Answer a corner with the centre. As the second player, taking the centre after a corner opening is the only reply that avoids losing.
  • Watch the opposite-corners trap. If you hold the centre and your opponent holds two opposite corners, play an edge, not a corner, to avoid a fork.

Frequently asked questions

Can you beat the Unbeatable computer?

No. On Unbeatable the computer uses the minimax algorithm to search every possible continuation and always picks a best move, so the best you can do is a draw. Tic tac toe is a solved game: with perfect play from both sides it always ends in a draw.

What is the difference between Easy, Medium and Unbeatable?

Easy picks a random empty square every turn. Medium plays the perfect move about 60% of the time and a random move otherwise, so it makes occasional mistakes you can exploit. Unbeatable always plays perfectly.

How do I play against a friend?

Choose 2 players. Player X and player O take turns on the same screen, and the scoreboard counts wins for each player separately from your games against the computer.

Who goes first?

By default the first move alternates between X and O every game, which keeps things fair. You can also set X or O to always start under First move.

What is the best first move in tic tac toe?

Against a perfect opponent every first move leads to a draw, but a corner gives the opponent the most chances to go wrong: the only reply that does not lose is the centre. The centre is also a strong, safe opening.

How many possible tic tac toe games are there?

There are 255,168 different possible games if you count every sequence of moves until someone wins or the board is full. The first player wins 131,184 of them, the second player 77,904, and 46,080 end in a draw.

Related tools