gizmobench

Dots and Boxes

Take turns drawing a line between two neighbouring dots; whoever draws the fourth side of a box owns it and earns another turn, and one line between two three-sided boxes takes both. Choose any grid from 2 to 8 boxes across and down, then play a friend on the same device or the computer as A or B. The computer takes offered boxes while safe lines remain, avoids giving boxes away, and near the end counts chains and loops to decide when handing over the last two boxes of a chain keeps control, all inside a fixed step and time budget. Every line is a button you can reach with the arrow keys, Undo takes back your last line along with the computer's reply, and Save game keeps one game in this browser.

gamenext: 3 × 3

h or v, then row and column counted from 0: h,0,0 is the top line of the top-left box, v,0,0 its left line.

The computer takes boxes while safe lines remain, avoids giving boxes away, and near the end counts chains and loops to decide when handing over two boxes keeps control. Each of its lines is limited to 60,000 counting steps and 150 ms. It is a practice opponent, not a perfect one.

board0 of 24 lines

A (you): 0B (computer): 0A (you) to move

A (you) to move: claim any dashed line. Closing the fourth side of a box scores it and earns another turn.

Click or tap a dashed line to claim it. From the keyboard, Tab to the board, move between lines with the arrow keys, Home and End, and press Enter or Space to claim.

3 × 3 boxes, 0 of 24 lines claimed, A 0, B 0. No box is owned yet. A (you) to move.

Score
A 0 · B 0
Turn
A (you)
Lines claimed
0 of 24
Boxes left
9
Game record as text

Worked cases

Each loads a real two-player position in place of the current game; claim the suggested line on the board or with Claim line.

  • Shared last line2 × 2, the six outer lines of the top two boxes claimed, A to move
    v,0,1 completes both top boxes: A scores 2 and moves again
  • Used line3 × 3 with h,0,0 claimed by A, B to move
    claiming h,0,0 again is refused; board and turn unchanged
  • Last line2 × 2 with 11 of 12 lines claimed, A 1, B 1, B to move
    v,1,1 completes both bottom boxes: B wins 3 to 1, total 4 = 2 × 2

Common questions

How do you play dots and boxes?
Players take turns claiming one line between two neighbouring dots. Drawing the fourth side of a box wins it and earns another turn. A single line between two boxes that already have three sides each wins both at once. The game ends when every line is drawn, so the two scores always add up to the number of boxes, 9 on a 3 × 3 grid. The player with more boxes wins; a tie is possible when the grid has an even number of boxes.
How does the computer play, and can it be beaten?
While safe lines remain, it takes any box it is offered and otherwise plays a line that gives no box away, choosing among equal lines with its seed. Once every line gives boxes away, it counts the chains and loops left and opens the one its count rates cheapest, opening a two-box chain in the middle. While some box still has three or four open sides, so the rest does not split into separate chains and loops, it instead plays the line that gives away the fewest boxes at once. At the end of a chain it may hand over the last two boxes (four in a loop) so that you must open the next chain, when the rest is worth more. Each line is limited to 60,000 counting steps and 150 ms; if the count runs out it falls back to a simpler choice. It plans nothing further in the middle game, so it can be beaten, for example by making it open the first long chain.
What does the computer seed do?
The seed decides the computer's choice between lines it rates equally. Leave the field blank and New game picks a random seed; the seed in use is shown under the field. With the same seed, grid, seats and the same lines from you, the computer replies the same way, so a game can be replayed; the one exception is a very slow device that stops a count at the 150 ms limit. Games between two people do not use it.
Can I play with a keyboard or on a phone?
Every line is a button named by its code and position, such as h,0,0, the top of box row 1, column 1. Tab to the board, move between lines with the arrow keys (Up and Down step between rows of horizontal and vertical lines), jump to a row's ends with Home and End, and claim with Enter or Space. You can also type a code into Selected line and press Claim line. On a touch screen each line owns a diamond-shaped area at least 44 pixels across, and a board wider than the screen scrolls sideways inside its frame. The text under the board lists the score and every owned box.
How do Undo, saving and the game record work?
With two players, Undo takes back the last line, any boxes it completed, and gives that player the turn again. Against the computer, Undo removes the computer's lines since your last line and that line as well. Undo, New game or Pause computer while the computer is thinking cancels its pending line. Save game stores the current game in this browser in a single slot that each save replaces; Resume saved game brings it back and replays every line to check it. Nothing is saved automatically. Copy record and Download .txt give a text record with a picture of the board and every line in order.

Completing a box earns one point and another turn; an edge may complete two boxes. Original implementation/art. Computer uses bounded chain-aware heuristics and makes no optimal-play claim.