Dots and boxes
Draw lines, close boxes and play again: dots and boxes against a computer at three levels or a friend on one phone, on boards from 2 by 2 to 8 by 8 boxes.
Dots and boxes is a pencil and paper game for two. Players take turns to draw one line between two neighbouring dots. Whoever draws the fourth side of a box claims it and draws again. When every box is closed, the player with more boxes wins. Here you play the computer at three levels, or a friend on one phone.
Rules and help
Tap between two neighbouring dots to draw the first line.
Use the arrow keys to move between lines and Enter or Space to draw one.
Your record against the computer appears here after your first game.
Print a blank sheet
Grids of 5 × 5 boxes to play on paper, with numbers when the dice variant is on.
- Built and source-checked by Muhammad Abdullah Awais
- Last checked
- 10 sources
- Methodology
Play dots and boxes online against a computer opponent at three levels, or as a two-player game handed round one phone. This dots and boxes game runs in the browser with no account, and the rules, the board and who starts can be changed before every game.
How to play: lines, boxes and another turn
The board is a grid of dots, and each move is one horizontal or vertical line between two adjacent dots, never a diagonal. A box is the square between four dots. The player who draws its fourth side closes it, the box takes that player's colour and initial, and the same player draws again. Taking a box is never compulsory, so a player may leave it and draw somewhere else.
Playing on screen works as it does on paper. A tap or click next to the gap between two dots draws that line, while a tap in the middle of a box picks nothing. Against the computer you draw in blue and the computer in orange. One line can be the fourth side of two boxes at once, and it still earns a single extra turn. The opening board of 5 by 5 boxes has 36 dots and 60 lines, and every one of them is drawn before the game ends. When one player holds more than half the boxes, the game says the result is decided and play continues until the last box is closed.
Who starts is a setting with three choices: you, the computer, or each in turn from game to game. When you start, your first tap draws the first line. When the computer starts, or when the boxes carry numbers, a Start button begins the game instead.
The folded panel Rules and help changes the rules before a game begins. They stay fixed while it runs, and New game unlocks them again.
- Closing a box means drawing another line is ticked by default, which is the usual rule. Unticked, the turn passes after every line, a variant some players prefer.
- Outer edge already drawn draws the frame of the board before the first line, another variant played on paper.
- Numbers in the boxes turns on the classroom version with two dice, described with the printable sheets below.
- Mark the lines that hand over a box shows every line that would give a box its third side as a dashed red line.
Against the computer: easy, medium and hard
The computer opponent plays at three difficulty levels. Each follows fixed habits designed for this site, since no published standard defines a level for this game.
- Easy closes a box it can close three times in four (75%). Otherwise it looks for a line that hands nothing over only half the time (50%) and draws any line the rest, so it often gives boxes away.
- Medium closes every box it can and never draws a third side while a safe move is left. When every line gives something away, it gives the fewest boxes. It never declines boxes, so it never keeps control of the chains at the end.
- Hard plays like medium early on. Once 12 or fewer safe lines are left, it searches the rest of the game exactly, within about half a second a move. It counts chains and declines boxes when that pays.
In tests run for this site on 3 by 3 and 4 by 4 boxes, hard beats medium in most games. It is not unbeatable. On big boards early in a game it relies on rules of thumb, and only the endgame is searched exactly.
Three buttons sit under the board. Undo takes back your last line together with the computer's reply, though not once the game has ended. Hint draws the line the hard level would choose as a dashed blue line. New game clears the board.
Your record against the computer counts games won, drawn and lost for each level and board size, with your widest win and the last 10 games. It is kept in this browser's local storage and never sent anywhere, and Clear my record deletes it.
Two players on one phone: pass and play
In the two-player game, both players share one phone, tablet or computer and hand it over when the turn passes, a style called pass and play. The board, the rules and the options work as they do against the computer.
Each player may type a name of up to 14 characters. Closed boxes then show each player's initial: one letter, two letters when both names begin with the same one, and 1 and 2 if those still match. Names are never stored and never go into the page's link.
The first move goes to player 1, player 2, or the two alternately, game by game. Undo takes back the last line, whoever drew it. Two-player games stay out of the record against the computer.
No second device is needed. As with the who am I game, everything happens on the one screen passed round the table, and the game sends nothing over the network while it is played.
Choosing a board: boxes, dots and lines
A game starts on 5 by 5 boxes, which is 6 by 6 dots and 60 lines, and any board from 2 by 2 to 8 by 8 boxes can be set.
| Board (boxes) | Dots | Lines | Boxes | Draw possible |
|---|---|---|---|---|
| 2 × 2 | 9 | 12 | 4 | Yes |
| 3 × 3 | 16 | 24 | 9 | No |
| 4 × 4 | 25 | 40 | 16 | Yes |
| 4 × 5 | 30 | 49 | 20 | Yes |
| 5 × 5 | 36 | 60 | 25 | No |
| 6 × 6 | 49 | 84 | 36 | Yes |
| 8 × 8 | 81 | 144 | 64 | Yes |
Sizes here count boxes, as the settings do, while players on paper often count dots. Boxes across and Boxes down are set separately, which gives 49 board sizes.
A draw needs an even total of boxes. The default board has 25, so one player always wins, while the 16 boxes of a 4 by 4 board can end 8 to 8. Daniel Allcock of the University of Texas names 5 by 5 as the typical board and notes that boards odd in both directions rule out a tie.
Computers have solved only small boards. Joseph Barker and Richard Korf showed in 2012 that 3 by 3 boxes is a win for the second player by 3 boxes with best play. Their largest, 4 by 5 boxes, is a tie with best play and took a search of 10 days on one computer. The result of 5 by 5 with best play is not known, so nobody can yet say which side wins it.
What is the trick to dots and boxes?
The first trick is to avoid drawing the third side of a box, because the next player closes it and moves again. A line that gives no box its third side is a safe line, and early in a game both players draw such lines.
Ticking Mark the lines that hand over a box in Rules and help dashes in red every line that would add a third side. That way the board itself shows which moves give boxes away. Medium and hard never draw one of those while any other choice remains.
Harmless moves run out. On a crowded board every remaining line gives the other player at least one box, and the open boxes have joined into chains and loops. From then on the game turns on who must open them, as the section on chains and loops explains.
Chains, loops and the double-cross
A chain is a row of boxes joined so that taking one opens the next, and a chain of 3 or more boxes is a long chain. A short chain holds one or two boxes. A loop is a chain that closes on itself, with at least 4 boxes.
Julian West, writing for the Mathematical Sciences Research Institute, explains why 3 is the line: the last two boxes of a long chain can always be declined. The player taking the chain takes all but those two and then draws the line at the far end of the chain. That is the double-dealing move, and in a loop it leaves the last four boxes.
The other player then takes the pair with one line, a double-cross, and must open the next chain. A player who keeps declining like this keeps control of the game. West describes that player as having control, and Allcock calls them the controller.
The hard level's own search gives exact results for three small endgames, in each of which the player to move must open something.
- Two chains of 3 boxes: whoever opens one loses 2 to 4. The other player takes one box, declines the last two and later takes the whole second chain. Taking all three at once would end 3 to 3.
- A chain of 3 and a single box: giving away the single box first wins 3 to 1, while opening the chain first loses.
- A loop of 4 and a chain of 3: opening the loop first loses only 3 to 4, and opening the chain first loses by more.
Giving boxes away on purpose is a sacrifice. The hard level makes them: it may give away a box or two to change who must open the first chain worth declining. It also hands over a pair of boxes by their middle line, so the pair cannot be declined.
Such endgames are still studied. Kevin Buzzard and Michael Ciere of Imperial College London wrote a paper on playing simple loony endgames optimally. In those positions, every move into a chain or loop lets the other player choose whether to decline.
How many long chains does the first player want?
On a board of 5 by 5 boxes, the first player wants an even number of long chains. Thomas Ferguson of UCLA states the long chain rule for any board. When the board is even in both directions, the starter wants an odd count, and otherwise an even one. Loops do not count.
West gives the same rule another way: the starter wants the dots plus those chains to add up to an even number. A 5 by 5 board has 36 dots, an even number, which leads to the same answer.
It is the rule Elwyn Berlekamp's book teaches. The Dots-and-Boxes Game: Sophisticated Child's Play appeared in 2000, after the game had a chapter of Winning Ways in 1982. The rule works because of the double-dealing move: whoever must open the first chain of three or more usually hands every later one to a player in control. The hard level plays for this count in the endgame, which is when its sacrifices begin.
From the École polytechnique to the pipopipette
Édouard Lucas described the game in print first in 1883, in Récréations mathématiques, tome II, as "le jeu de l'École Polytechnique". Lucas wrote that students of the École polytechnique had invented it a few years earlier, so he credits them rather than himself.
In his account it was played on squared paper. A closed square was marked with the player's initial, the player who closed it played on, and the winner was the first to hold more than half the squares.
On 5 May 1889 Lucas published it as "La Pipopipette, nouveau jeu de combinaisons". It was a boxed game of 36 pegs and 60 bars making 25 squares, dedicated to his former pupils. That is the same board this game starts on. "Pipo" was the students' short name for Polytechnique, and the text is reprinted in L'Arithmétique amusante (1895), Note III.
British searchers also type dots and squares, or simply boxes. Berlekamp's book also gives a chapter to a disguise called strings and coins. Each box is a coin, each line a string and the edge is the ground, so cutting a coin's last string pockets it.
Programs play it too. In 2005 BBC News reported that Deep Beige, written by a Nottingham student, had won gold for dots and boxes at the 10th Computer Olympiad.
Printable sheets, dot paper and the numbers variant
Print a blank sheet puts 1, 2, 4 or 6 empty grids of the chosen board on one printable sheet, for play with pencils away from the screen.
NRICH, the University of Cambridge's maths enrichment site, sets the game for ages 7 to 11 as "Put Yourself in a Box". Its version needs two coloured pencils and dot paper, an initial goes in each closed box, and the player who closed it takes another turn.
Numbers in the boxes turns the board into a classroom version with dice. When the game starts, each box is dealt the result of its own throw of two dice, so common results fill more boxes than rare ones. Before every line the player throws two dice and adds or multiplies them, as chosen, and the computer throws for itself.
Only a side of an open box showing that result may be drawn, and a side shared by two boxes counts if either shows it. With no such side free, the turn passes. Closing a box earns another throw and another line, and every box counts one point whatever its number.
Adding gives 11 results from 2 to 12, and and 7 is the commonest at 6 throws in 36 (16.7%). Multiplying gives 18 results from 1 to 36. 6 and 12 come up 4 ways each, while 1, 9, 16, 25 and 36 come up once in 36.
This dice version is the site's own, because classroom sheets differ: some subtract, and some use dice that go up to ten. Printed sheets with numbers on get fresh numbers for every grid. The dice are thrown with the browser's cryptographic random generator only after the game starts, as in the Christmas dice game.
Frequently asked questions
Who goes first, and does it matter?
Here it is a setting: you, the computer, or the two alternating from one game to the next, and the same choices for two players. Whether starting helps depends on the board and on how the chains form. By the long chain rule, the starter wants an odd or an even count of chains of three or more, set by the board, and the other player the opposite.
Can a game end in a draw?
Only when the board holds an even count of boxes. A 5 by 5 board has 25 boxes, so someone always wins. On 4 by 4 boxes, 16 in all, a game can end 8 to 8, and the result says so.
Why do you get another turn after closing a box?
Every source cited on this page has the rule, from Lucas onwards. Barker and Korf put it exactly: after closing a box a player must draw another line, but is not required to close a box they could close. Unticking Closing a box means drawing another line plays the variant where the turn passes after every line.
Can you always win on a 3 by 3 board?
Not when moving first. Barker and Korf showed in 2012 that 3 by 3 boxes is a win by 3 boxes for whoever moves second, given best play. Against a player who errs, either side can win, and even the hard level only searches exactly near the end.
What is a double-cross?
A double-cross is one line that closes two boxes at once. It happens when a player declines the last two boxes of a chain: the other player takes both with the middle line and then has to open the next chain.
Can I play against a friend online?
Only on the same device. The two-player game passes one phone or computer between the players, and there are no online rooms for players on different devices. A shared link opens the same set-up, including the board and the rules, but never the moves or the names.
Why do I keep losing against the computer?
Medium and hard never draw a third side while a harmless move is left, so they rarely give a box away early. Hard also counts chains and declines boxes once 12 or fewer safe lines remain. Easy gives boxes away often, the dashed red marks show lines that give a box away, and Hint shows the line hard would draw.
Is dots and boxes good for children?
NRICH at the University of Cambridge uses it in primary maths, with dot paper and two coloured pencils. Playing it means counting sides and boxes and planning a move ahead. The numbers variant adds sums or products of two dice, 2 to 12 when adding and 1 to 36 when multiplying.
Sources
The figures and rules on this page were checked against these publications on .
- Put Yourself in a Box(opens in a new tab)
NRICH, University of Cambridge
- Playing simple loony dots-and-boxes endgames optimally(opens in a new tab)
Kevin Buzzard and Michael Ciere, Imperial College London (arXiv)
- Récréations mathématiques, tome II (1883): Le jeu de l'École Polytechnique, pp. 90 to 92(opens in a new tab)
Édouard Lucas, Gauthier-Villars (Internet Archive)
- L'Arithmétique amusante (1895), Note III: La Pipopipette (1889), pp. 203 to 209(opens in a new tab)
Édouard Lucas, Gauthier-Villars (Internet Archive)
- Solving Dots-And-Boxes (AAAI 2012)(opens in a new tab)
Joseph K. Barker and Richard E. Korf, University of California, Los Angeles
- Championship-Level Play of Dots-and-Boxes (Games of No Chance, 1996)(opens in a new tab)
Julian West, Mathematical Sciences Research Institute
- The Dots-and-Boxes Game: Sophisticated Child's Play(opens in a new tab)
Elwyn Berlekamp, A K Peters (Routledge)
- Some Strategy for Dots and Boxes(opens in a new tab)
Thomas S. Ferguson, University of California, Los Angeles
- Best play in Dots and Boxes endgames(opens in a new tab)
Daniel Allcock, University of Texas at Austin (arXiv)
Related tools
- Christmas dice gameRoll for wrapped presents on one phone: a six takes from the pile, then a hidden clock runs the round of swaps and steals. Edit and share the house rules.
- Click speed testCount how fast you click with a mouse, a touch screen or the keyboard over 1 to 100 seconds, with the gaps between presses and a sourced rating.
- Colour memory gameA colour shows for a few seconds, then hides. Rebuild it from memory with hue, saturation and brightness sliders, for up to 10 points a colour.
- Flag quizA country flag quiz with all 195 UN states: pick from 4 names, type the country or find its flag, by region, alone or with up to 4 players.
- Love calculatorTest two names with the playground LOVES count, TRUE LOVE or FLAMES and see every row of the adding. Same names, same result, and nothing is stored.
- Who am I? The forehead guessing gameThe forehead guessing game on one phone: 10 British decks, tilt or tap to score, a round timer, teams, your own words and printable cards.