Dots and Boxes Best Move Calculator

Draw in the lines from your game and this solver finds the best line to play next and the final score if both sides play perfectly from here. Late in a game, when every line gives something away, it tells you which chain to open and when to take every box or give the last two back.

Built by Brian Hamilton

Board size (boxes)

Each line you draw is played as a move: the turn passes unless it completes a box, which goes to the player who drew it. Tap a drawn line to remove it, or a claimed box to change its owner.

Whose turn is it?
Thinking time on 4×4 and 5×5

Draw the lines that have been played, set whose turn it is, then press Find best move.

How to use the calculator, and the rules it follows

Players take turns drawing one line between two neighbouring dots. Draw the fourth side of a box and you claim it and draw again. When every line is drawn, the player with more boxes wins.

  • Board size counts boxes, not dots: 3×3 boxes is a grid of 4×4 dots.
  • Enter a position by tapping the gaps between dots. The calculator applies the extra-turn rule as you go and gives each finished box to whoever drew it. If you entered the lines in a different order from the real game, tap a box to change its owner and set whose turn it is with the buttons.
  • Find best move marks the best line on the board with a dashed green line and a tick, and lists every line with the final score it leads to. Play best move draws it for you and analyses the next position.
  • Lines are named by their two dots: columns a, b, c… from the left and rows 1, 2, 3… from the top, so b2–c2 is a horizontal line on the second row of dots.
  • Copy link saves the position, including box owners and whose turn it is, in a link you can share or come back to.

Take one box, then give the last two back

The most valuable thing this calculator does is stop you taking boxes. In the position below, Red has just opened the three-box chain along the top and Blue has taken the first box. Two boxes are still there for the taking. Taking them looks free. It is not.

Blue to move: decline the last two boxes of the chainA 3 by 3 board. Blue has taken the top-left box. The two boxes to its right each need one more line, and the six boxes below form one long chain. Taking the two boxes with the line c1 to c2 loses 3 to 6; drawing the line d1 to d2 instead gives them to Red, who must then open the long chain, and Blue wins 7 to 2.
Blue to move, one box up. Taking the last two boxes with c1–c2 (marked ✗) wins the battle and loses the war, 3–6. Drawing d1–d2 instead (marked ✓) hands those two boxes to Red, and Blue wins 7–2.

Whoever takes the last box of a chain has to draw again, and on this board every line left opens the six-box chain at the bottom. So if Blue takes all three boxes, Blue must then give Red six: 3–6. If Blue draws the far end of the chain instead, Red can take both boxes with one line, but then it is Red who has to open the long chain, and Blue takes all six: 7–2. Two boxes given away buys six.

That move, refusing the last two boxes of a chain so that your opponent has to move next, is called a double-dealing move, and the single line that takes both boxes afterwards is a double-cross. Load this position with the Give two back button above and the calculator puts d1–d2 alone at the top, at 7–2. Every other line on the board loses for Blue.

The rule of thumb: when your opponent opens a chain of three or more, take all but the last two, then decline them, as long as there is another long chain still to come. On the last chain of the game, take everything.

Count the chains before the safe lines run out

The trick only works for the player who is offered the first long chain. So the real fight happens earlier, while there are still safe lines that put no box on three sides. Whoever runs out of safe lines first has to open a chain, and from then on the other player can keep control with double-dealing moves until the board is gone.

Red to move with no safe line left: a chain of three and a chain of sixA 3 by 3 board with 13 lines drawn and no box taken. The top row is a chain of three boxes and the remaining six boxes form one chain. Each box is labelled with the length of its chain. Whatever line Red draws opens a chain, and with best play Red loses 2 to 7.
The same game one move earlier, Red to move. No safe line is left: the board is one chain of three and one chain of six. Every one of Red’s eleven possible lines loses 2–7.

Elwyn Berlekamp, who wrote the standard book on the game, turned this into the long chain rule. A long chain is three or more boxes. The player who moved first wants the number of dots on the board plus the number of long chains to come out even; the second player wants it odd. Loops do not count as long chains.

What each board size asks of the first player under the long chain rule.
Board (boxes)DotsFirst player wants
3×316an even number of long chains
4×425an odd number of long chains
5×536an even number of long chains

The position above fits: 13 lines have been drawn with no box taken, so Blue moved first, and 16 dots plus two long chains is even. Blue gets control. The rule tells you what to aim for while the safe lines last. The calculator tells you whether you got there, because once the safe lines run low it searches the rest of the game exactly.

Open a two-box chain down the middle

When you are the one who has to give something away, give the smallest chain first, and if it is two boxes long, choose the line carefully. A two-box chain has three lines you can draw to open it, and they are not equal.

Blue to move: open the two-box chain with its middle lineA 3 by 3 board with chains of two, three and four boxes, each box labelled with the length of its chain. The two-box chain runs down the left side. Its middle line, a3 to b3, wins 5 to 4. Its two end lines, a2 to a3 and a4 to b4, lose 4 to 5.
Blue to move, with chains of two, three and four. Opening the two-box chain with its middle line, a3–b3 (✓), wins 5–4. Opening it from either end (✗) loses 4–5.

Drawn down the middle, the line leaves two separate boxes, each on three sides. Red can take them but has no way to refuse them: there is no single line that hands both back and ends Red’s turn, the way d1–d2 did in the first diagram. So Red takes two and has to open a chain. Opened from an end, the same two boxes can be declined with a double-dealing move, and Red uses it to keep control: Blue gets the two boxes but then has to open the next chain. One box separates the two results, and it comes entirely from which of three lines Blue drew.

Every opening line on the 3×3 board is equally good

The 3×3 board is small enough to settle completely. It has 24 lines, so 16,777,216 possible sets of drawn lines, and every one of them can be scored. That full check, which shares no code with the calculator’s search, agrees with it exactly: with perfect play the second player wins 6–3, and it makes no difference which of the 24 lines the first player starts with. Press Find best move on the empty 3×3 board and every line comes back with the same score.

Bigger boards are much harder. The largest board solved from the start is 4×5 boxes, which Barker and Korf showed in 2012 is a tie with perfect play; their search ran for nine days. This calculator does not try to solve the empty 4×4 or 5×5 board in a few seconds. It solves the position you give it, and the later in the game that position is, the faster it gets.

When the answer is exact

The 3×3 board is always searched to the end; the empty board, the hardest case, takes between one and five seconds on a desktop PC, depending on what else it is doing. On the bigger boards, how soon the calculator can see to the end depends on how many lines are already drawn. These figures come from positions reached the way real games go, with both players drawing safe lines while they last, eight positions at each point, on a desktop PC. A phone is slower.

How often the best move is found exactly within each time setting, by board size and lines already drawn.
BoardLines drawnStandard (4 s)Deep (15 s)
3×3any, including nonealways: searched to the end with no time limit
4×48 of 400 of 80 of 8
4×412 or more8 of 88 of 8
5×520 of 600 of 80 of 8
5×524 or more8 of 88 of 8

When the search finishes, the answer is exact: no scoring table and no guesswork, just every continuation followed to the last box, with mirror images of the same position searched once. When it cannot finish in time, the calculator says so instead of guessing, and you can see it happen by pressing Find best move on an empty 5×5 board. It still tells you what is certain: which lines are safe, and how many boxes each of the others gives away. Early in a game that is usually the decision that matters. If it finds the value of the position but not every move’s score, it shows the best lines and marks the rest as worse without a final score.

Boxes or dots: naming the board

Players describe the same board two ways. A “4 by 4” game might mean four boxes on a side or four dots on a side, which is only nine boxes. This calculator counts boxes, as does the game on this site, so 3×3 here is the 4×4-dot grid found in many puzzle books.

The game itself goes by many names. In English you will meet Boxes, Squares, Lines and Boxes and Dots and Lines. The French mathematician Édouard Lucas published it in 1889 as la pipopipette.

Play a full game

The calculator works on one position at a time. To play a whole game, the free Dots and Boxes game has boards up to 6×10, up to four players and three levels of computer opponent. The theory behind chains is a cousin of the one behind Nim, whose calculator proves every answer it gives. There are also best move calculators for Gomoku, Checkers and 4 in a Row, and the rest are on the calculators page.