This piece was adapted from an article originally published in 1957 by the mathematician and master puzzler Martin Gardner.
For 25 years, Gardner wrote a beloved column called “Mathematical Games” for Scientific American. To celebrate his legacy, in 2020 the magazine collected some of Gardner’s best pieces in an eBook titled Adventures in Flatland.
Who has not as a child played tic-tac-toe, that most ancient and universal struggle of wits of which Wordsworth wrote:
On supporting science journalism
If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.
At evening, when with pencil, and smooth slate
In square divisions parcelled out and all
With crosses and with cyphers scribbled o’er,
We schemed and puzzled, head opposed to head
In strife too humble to be named in verse.
Forms of tic-tac-toe were popular in ancient China, Greece and Rome—Ovid even mentioned it in his Art of Love.
At first sight, it’s hard to understand the enduring appeal of a game that seems no more than child’s play. While even in the simplest version of the game the number of possible moves is very large—15,120 different sequences for the first five moves alone—there are really only a few basic patterns, and any astute youngster can become an unbeatable player within an hour or so. But tic-tac-toe also has its more complex variations and strategic aspects.
In the lingo of game theory, tic-tac-toe is a two-person contest that is “finite” (it comes to a definite end). It has no element of chance and is played with “perfect information,” all moves being known to both players. If played “rationally” by both sides, the game must end in a draw. The only chance of winning is to catch an imperfect opponent in a “trap” where a row can be scored on the next move in two ways, only one of which can be blocked.
Of the three possible opening plays—a corner, the center or a side box—the strongest opening is the corner, because the opponent can avoid being trapped at the next move only by one of the eight possible choices: the center. The center opening, though, can be met by seizing one of the four corners. The side opening is in many ways the most interesting, because of the richness in traps it allows.
A very ancient variant of the game gives each player three counters (nowadays one player can use pennies and the other dimes). The two players take turns placing a counter on the board until all six are down. If neither player has won by getting three in a row, then each is allowed to move one counter per turn to an adjacent empty square, but she can move only vertically or horizontally, not diagonally.
Since the first player would have a sure win by placing her first counter in the center box, this opening is usually barred. But after any other opening, the second player must immediately take the center to avoid defeat. This game also ends in a draw with perfect play, but it swarms with potential traps on both sides.
Other variations of the game permit diagonal moves (one of them is attributed to early Native Americans). A freewheeling French version called “les pendus” (the hanged) allows any piece to be moved to any vacant cell. This game is believed drawn if played rationally, whatever the opening.
The moving-counter game can also be played with a matrix of 16 boxes (4 by 4), each player using four counters and striving to get four in a row. And in 1937, the magician John Scarne invented an interesting version called “teeko,” played on a 5 by 5 board. The players have four counters and can move one space per turn in any direction. The goal is to get the four in a row (straight or diagonal) or to assemble them in a square formation on four adjacent cells.
There’s also a reverse version of simple tic-tac-toe in which the first player to get three in a row loses. The second player has a decided advantage, but the first player can force a draw if he makes his initial move correctly. (We’ll leave it to you to discover what the first move must be.)
Several three-dimensional tic-tac-toe games have been created, as well. On a 3 by 3 by 3 cube, the first player has an easy win, but a more complex version with a 4 by 4 by 4 cube is probably a draw if played rationally.
Four-dimensional tic-tac-toe can be played on an imaginary hypercube cut into single-layer blocks. In the 4 by 4 by 4 by 4 version, the object is to get four marks in a straight line on the hypercube.
This is achieved by lining up four marks in a cube formed by piling up in serial order four blocks that occupy the same row or column or main diagonal. In this game, the first player is believed to have a sure win, but in the 5 by 5 by 5 by 5 version the game probably must be a draw if played perfectly.
The ancient Japanese game of gomoku (or five stones) is played on the intersections of a go board, which is equivalent to playing on a 19 by 19 square. Players take turns placing counters from an unlimited supply until one player wins by getting five in a line—vertical, horizontal or diagonal. No counter moves are allowed. The game became popular in England in the 1880s under the name of “gobang.”
The first electrical machine for playing tic-tac-toe was invented by Charles Babbage, the early 19th-century originator of calculating machines. Babbage planned to exhibit this machine in London to raise funds for more ambitious projects, but he never built it, because exhibits of other curious machines at the time turned out to be financial failures.
A novel feature of Babbage’s robot was the fact that, when faced with a choice between equally rational lines of play, the machine made its selection on a random basis through a built-in mechanism, choosing one play if the number of games it had won up to that point was odd and the alternate play if the number was even. “An inquiring spectator,” observed Babbage, “might watch a long time before he discovered the principle upon which [the robot] acted.”
It isn’t difficult to design a tic-tac-toe machine (or program a digital computer) to play a rational game, but the problem becomes more complicated if the machine is to be designed to win the maximum number of games against inexperienced players. The difficulty lies in guessing how a novice is most likely to play. Just how shrewd will he be?
To see the sort of complications that arise, let’s consider the simple game, identifying the cells by number as on the board depicted here. Assume that the novice opens by taking cell number 8. The machine might do well to make an irrational response by seizing cell 3! This would be fatal against an expert, because the opponent of the machine has a sure win if he next takes cell 9, but an inexperienced player is unlikely to hit upon this one winning reply.
In fact, he’ll be strongly tempted to take cell 4, because this leads to two promising traps against the robot. The machine, however, can now spring its own trap by taking cell 9, followed by 5 on the next move. In short, the machine may win more often with reckless strategies than with safe, rational lines of play, which are apt to lead to a draw.
A truly master player, robot or human, would not only know the most probable responses of novices in general but would also be able to analyze each individual opponent’s style of play to determine what sort of mistakes he’s likely to make, and also take account of the novice’s improvement with increasing experience. At this point, the humble game of tic-tac-toe plunges us into far from trivial questions of probability and psychology.
Reference: Mathematical Games. Martin Gardner in Scientific American Vol. 196, No. 3, 160-166; March 1957. doi:10.1038/scientificamerican0357-160
