Tic-tac-toe against the computer

Play tic-tac-toe (noughts and crosses) online against the computer. Three levels; on expert the machine plays perfectly — can you hold the draw? Free, no sign-up.

What this game is

Tic-tac-toe — noughts and crosses — is the best-known game ever played on squared paper, and for most of us the first game played against someone who could count further ahead.

Three by three, two marks, one goal: three in a row. The rules take ten seconds, which is exactly why the game became the classic teaching example: it is where people show how a machine looks ahead, what a game tree is, and what "solved" means.

The answer has been known for a long time: with perfect play on both sides tic-tac-toe is always a draw. You cannot beat the expert level — but you do not have to lose to it either. The question is whether you can hold the draw.

Rules

How to play better

A bit of history

Three-in-a-row games on a small board are very old; the familiar pencil-and-paper form and its names — tic-tac-toe in America, noughts and crosses in Britain — settled in the nineteenth century.

In 1952 Alexander Douglas wrote OXO at Cambridge for the EDSAC computer: a person played against the machine, and the board was shown on a small screen. It is often called one of the first computer games. In 1961 Donald Michie built MENACE, a "machine" that learned tic-tac-toe out of matchboxes filled with beads: after each game the beads for good moves were added to and the bad ones taken away. It is one of the earliest examples of reinforcement learning.

Searching the whole game is a beginner's programming exercise: there are 255,168 different games, and only 765 positions once rotations and reflections are set aside. The result is known: a draw. It is the smallest of the solved games in our reference of solved games, and its big sister is ultimate tic-tac-toe, nine boards in one.

About the levels

Normal notices only its own win: if it can put a third mark in a row, it does. Otherwise it plays anywhere and does not see your threats.

Hard also blocks your threats, and with a free move takes the centre, then the corners. A fork beats it: it cannot cover two threats at once.

Expert knows the value of every one of a few thousand positions and makes no mistakes. Among the moves that keep the best result, it picks the one that leaves you the most losing replies. It cannot be beaten; a draw against it is the best there is.

Where to go from here