✕ TIC-TAC-TOE — VS AI

Free · Browser · No Download · No Account · Strategy
⬡ Open full screen →
HOW TO PLAY
  • You are X. Click any empty square to place your mark.
  • The AI plays O and responds immediately after your move.
  • Get three in a row — horizontal, vertical, or diagonal — to win.
  • Choose Easy for a forgiving game, Hard for a challenge, Unbeatable for the algorithm experience.

Tic-tac-toe is one of those rare games where the rules fit on a napkin and the strategy can fill a textbook. The 3×3 grid, two marks (X and O), and a single win condition — three in a row — have been enough to occupy mathematicians, computer scientists, and anyone with a pencil and a bored minute since at least the 1st century BCE.

The game's ancient origins are disputed, but versions of crossed lines and marks appear in Roman history around 100 BCE in a game called terni lapilli. The modern name comes from a 19th-century British children's game where a pencil was placed between the fingers and thrown at a grid while the eyes were closed — essentially a precursor to the "random placement" variant. By the 20th century, the standard two-player alternating version had become the definitive form.

What makes tic-tac-toe genuinely interesting from a computational perspective is that it was one of the first games to be played on a computer. In 1952, British computer scientist Alexander Douglas wrote OXO (also called Noughts and Crosses) as part of his PhD thesis on human-computer interaction at the University of Cambridge. It ran on the EDSAC computer, displayed on a cathode ray tube screen, and allowed a human to play against the computer. OXO is considered one of the first graphical computer games ever made.

The Mathematics of the Game

There are 255,168 possible unique games of tic-tac-toe (counting rotations and reflections as distinct). Of those, 131,184 are first-player wins, 77,904 are second-player wins, and 46,080 are draws. When both players play optimally, the result is always a draw — making tic-tac-toe a "solved" game. There is no room for creativity at the expert level; there is only correct play and incorrect play.

The minimax algorithm — the engine behind this game's Unbeatable AI — was formalised by John von Neumann in 1928 but became computationally practical in the 1950s. For tic-tac-toe, the game tree is small enough that a computer can evaluate all possible futures from any board position in milliseconds. The AI assigns a score to each possible outcome (win, loss, draw), then selects the move that maximises its minimum guaranteed score. Against this algorithm, the best result a human player can achieve is a draw.

Strategy Tips

Frequently Asked Questions

Can you beat the unbeatable AI?
Not by playing perfectly — the Unbeatable mode uses the minimax algorithm, which always selects the optimal move. The best you can achieve is a draw. Easy and Hard modes introduce deliberate imperfection.
How does the AI work?
The Unbeatable AI uses minimax with alpha-beta pruning. It maps all possible future board states, scores them (+10 AI win, -10 player win, 0 draw), and always picks the move that maximises its minimum guaranteed score.
Is tic-tac-toe always a draw if both players play perfectly?
Yes. Tic-tac-toe is a solved game. With optimal play from both sides, the result is always a draw. This is why experienced human vs human games quickly become repetitive.
What are the best opening moves?
The centre square is statistically strongest (4 possible winning lines). Corner squares are second strongest (3 lines each). Edge squares are weakest (2 lines each).

MORE CLASSIC GAMES: