PlayNook

Math & Logic · Pencil Game

Play Dots and Boxes Online — 2 Player or Computer

Draw a line, close a box, go again. The rules take twenty seconds and the strategy takes years — because the winning move is usually the one that gives boxes away.

The rules take twenty seconds to learn and the strategy takes years, because the strongest move in dots and boxes is usually the one that hands your opponent free boxes on purpose. That is not a paradox — it is arithmetic, and this page shows the arithmetic.

How to play dots and boxes

Take turns drawing one line between two neighbouring dots. Close the fourth side of a box and you own it — and you draw again. When the grid is full, whoever owns more boxes wins.

The rule that turns it into a game

Claiming a box does not end your turn. If your next line closes another box you go again, and again, and again. That is why one turn can swallow an entire run of boxes, and why handing over a single box usually means handing over everything attached to it.

Never the third side

A three by three dots and boxes grid with two sides of the centre box drawn. The two remaining sides of that box are marked in red as the lines that would give it away.
Two sides drawn on the middle box. Of the 22 lines still free, exactly two are poisoned — and the other 20 are safe.

Drawing the third side of a box gives it to your opponent. Because they then move again, they also get whatever the box was connected to. Every beginner learns this within three games, usually with some indignation.

Dots and boxes strategy

Once both players avoid the third side, something odd happens: the safe moves start running out. That is not a failure of the game, it is the game.

Chains, and why the whole thing is really about them

A five by five dots and boxes grid where no safe line remains. The boxes are coloured into five groups: four chains of length five, four, six and six, and one loop of four. Small rings mark the two points where each chain opens to the outside.
A real position from this engine, reached by playing only safe lines until none was left. Rings mark where a chain opens; the loop has none, because a loop is sealed all the way round.

Play safe lines until there are none, and the board falls apart into chains and loops. A chain is a run of boxes open at both ends; a loop closes on itself. Whoever is forced to open the first long chain loses it, and then usually has to open the next one too.

So the real contest is not about taking boxes. It is about who runs out of safe moves first — and that is decided long before the first box changes hands.

The double-cross: giving boxes away to win

The same three by three position shown twice. On the left a red line takes the offered box and the result is five boxes down; on the right a blue line elsewhere leaves the box alone and the result is five boxes up.
Not an illustration — this position was found by searching the solved three by three game for the sharpest case. Taking the box loses by five; refusing it wins by five.

When your opponent opens a chain, take all of it except the last two boxes, and leave those two behind. They must take them, and then they must open the next chain. It costs two boxes and buys the rest of the board.

This is the move that separates people who know the game from people who have merely played it a lot.

Who wins dots and boxes with perfect play?

We solved the small boards outright — not by searching cleverly, but by evaluating every position there is. A grid of c × r boxes has 2cr + c + r lines, and each line is either drawn or not, so the whole game fits in that many bits.

BoardBoxesDotsLinesPositionsResult with perfect play
1 × 114416second player, 1 : 0
2 × 1267128drawn, 1 : 1
3 × 138101,024second player, 2 : 1
2 × 249124,096first player, 3 : 1
3 × 261217131,072second player, 4 : 2
4 × 2815224,194,304first player, 5 : 3
3 × 39162416,777,216second player, 6 : 3

Read down the dots column. On every board we could solve, the first player wins when the number of dots is odd and never when it is even. Both first-player wins have an odd dot count; every even one is a second-player win or a draw.

That is a pattern across seven small boards, not a proof — and it is worth saying plainly, because the temptation to call it a law is exactly how wrong rules of thumb get into circulation. What it does match is the old folk strategy of counting dots and long chains before you start, which is a genuinely good habit whether or not the tidy version holds on bigger grids.

How often is taking a box actually a mistake?

The solved game answers this exactly. Across every position of the three by three board in which a box is there for the taking:

BoardPositions with a box on offerRefusing it is betterBiggest swing
2 × 22,6540
3 × 2103,0446724 boxes
4 × 23,649,46021,0128 boxes
3 × 315,061,118177,28010 boxes

Two things fall out of that. The bigger the board, the more often greed is wrong — and on a nine-box grid the mistake can cost ten boxes, which is more than the board holds, because it swings from losing 2 : 7 to winning 7 : 2.

The second is stranger. In every one of those 177,280 positions, refusing does not merely do better — it mirrors. Taking loses by exactly as much as refusing wins: −1 against +1, −2 against +2, all the way to −5 against +5. There is no case anywhere on the board where taking still wins and refusing merely wins by more. Control of the endgame is not a matter of degree; you either have it or you have handed it over.

How strong is the computer?

Three levels, measured rather than asserted — 50 games per pairing on the four by four board, each pairing played twice with the sides swapped:

PairingStronger side winsDraws
medium vs easy82 %6
hard vs easy100 %0
hard vs medium76 %6

The levels differ in how much slack they allow themselves, not in how far ahead they look. Hard solves the last twenty lines exactly, which means every double-cross in the endgame is found rather than guessed — on the three by three grid that covers all but the first four moves. Easy never solves anything and takes whatever is offered, which is exactly why it can be beaten.

Play it on paper

This is a pencil game first and a browser game second. There are printable dots and boxes grids here in three sizes with a score line, plus a sheet of four small grids for quick games, and the whole family of them is in games you only need paper for.

If you like this one

  • Nim — the other game on this site whose whole strategy is a piece of arithmetic you can carry in your head
  • MENACE — a machine that learns noughts and crosses out of matchboxes, with the learning shown as it happens
  • Towers of Hanoi — also invented by Édouard Lucas, and also far deeper than it looks
  • Four in a Row — another grid game that is solved, and where knowing the solution changes how you open

Frequently asked questions

+ How do you play dots and boxes?

Players take turns drawing one line between two neighbouring dots. Whoever draws the fourth side of a box claims it, writes their initial in it, and must then draw again — which is how a single turn can take a whole run of boxes. When every line has been drawn the game is over and whoever owns the most boxes wins.

+ What is the strategy for dots and boxes?

Never draw the third side of a box unless you have no choice, because that hands it over and your opponent then moves again. Sooner or later every safe line is gone and somebody must open a run of boxes; whoever is forced to open first loses that run. Strong play is about running the board out of safe moves on your opponent's turn rather than yours, which is why the count of long chains decides most games before anybody has taken a single box.

+ What is a double-cross in dots and boxes?

Taking all but the last two boxes of a run and deliberately leaving those two behind. It costs you two boxes, but it forces your opponent to open the next run instead of you, and the next run is usually worth far more than two. We solved the three by three board completely, and in every single position where refusing a box beats taking it, the two options are exact mirrors: taking loses by precisely as much as refusing wins.

+ Who wins dots and boxes with perfect play?

It depends on the grid, and we computed it rather than guessed. On the three by three board — sixteen dots — the second player wins six boxes to three. On two by two, nine dots, the first player wins three to one. Across every board we could solve exactly, the first player won when the number of dots was odd and never when it was even.

+ Is dots and boxes solved?

Only on small grids. A board with c columns and r rows of boxes has 2cr + c + r lines, and the number of positions is two to that power. Three by three has twenty-four lines and sixteen million positions, which a computer chews through in a few seconds. The five by five board on this page has sixty lines, so around a billion billion positions — nobody has solved that, and nobody is about to.

+ Can two people play on the same device?

Yes. Choose 'Two players, this device' beside the board and pass it back and forth. Nothing to install, no account, and each player's boxes are marked in their own colour so it is always clear who owns what.

+ Which grid size should I choose?

Three by three for a quick game or for showing somebody the rules — and it is the one board here where the computer plays the whole endgame perfectly. Four by four is the usual size and long enough for chains to matter. Five by five makes a proper game of it, where the endgame is a real puzzle rather than a scramble.

+ Where does dots and boxes come from?

The French mathematician Édouard Lucas published it in 1889 as la pipopipette. Lucas is the same man who invented the Tower of Hanoi, and the family resemblance is real: both look like children's games and both turn out to have serious mathematics inside them.

More games like this

Nim — screenshot of the browser gameMath & Logic
Binary1-2 Players

Nim

Take as many marks as you like from one row. Whoever takes the last one wins — or loses, if you agree that first. One line of binary decides every position, and the table on this page shows it live.

  • Play a friend online with a table code, or the computer
  • The nim-sum table runs live beside the board
  • Normal and misère rules, with the ending that catches everyone
Play Nim
Four in a Row — screenshot of the browser gameBoard Game
Connection Game1-2 Players

Four in a Row

Drop a disc into a column and it falls to the lowest free space. Make four of your own in a line — across, up or diagonally — before your opponent does.

  • Four ways to play, including Pop Out — pull a disc out from the bottom
  • Play a friend online — share a code and chat
  • A computer opponent that understands threat parity, not just depth
Play Four in a Row
MENACE — screenshot of the browser gameMath & Logic
Machine Learning1 Player

MENACE

A machine built from 304 matchboxes that learns noughts and crosses by throwing away the beads for moves that lost. It starts knowing nothing. Play it and watch it change.

  • The 1961 original, rule for rule — beads, matchboxes and all
  • Watch the box it opens and the beads it gains and loses
  • Train it against a human, a random player or perfect play
Play MENACE
Towers of Hanoi — screenshot of the browser gameMath & Logic
Recursion1 Player

Towers of Hanoi

The puzzle where the answer is known before you start: 2ⁿ−1 moves, never fewer. The question is whether you can find them — and the counter says the instant you cannot.

  • Three to ten discs, with the target 2ⁿ−1 always in view
  • A counter that tells you the moment you leave the shortest path
  • Watch it solve itself, slowly, and see the recursion
Play Towers of Hanoi