Play Dots and Boxes against a computer at three levels, or against a friend on the same screen. Three board sizes, undo, keyboard play, and a session tally.
A You 0
B Computer 0
Turn Your turn (A)
Lines left 0
This session -
Your wins here 0
Tap or click the gap between two dots to draw a line. Close the fourth side of a box to claim it with your letter, then draw again. On a keyboard, arrow keys move between lines (Home and End jump along a row), Enter or Space draws. Undo takes back your last turn, including the computer's reply and any chain it took. Every line has a tap area at least 28 px thick; on a small phone the 5 x 5 board has small boxes, so use 4 x 4 or 3 x 3 if taps miss.
At every level the computer takes a box when it can. Easy otherwise draws a random line. Medium avoids drawing the third side of a box while a line that gives nothing away exists, and when every line gives something away it picks the one that hands you the fewest boxes. Hard plays like Medium until 16 or fewer lines are left. From there it solves the rest of the game exactly, trying every order of the remaining lines (about a second at most), which is how it finds the double-dealing move: declining the last two boxes of a chain so that you must open the next one. Before that point it opens the smallest chain first and declines the last two boxes of a chain when keeping control is worth more than those two boxes. Hard is strong at the end of a game and only rule-based before it, so it can be beaten.
As-is, no warranty. These apps are free under their listed license and run entirely in your browser. Use at your own risk — don't blame me if your PC catches fire, your dog runs away, or the math turns out wrong. Verify anything that actually matters. None of this is professional financial, medical, legal, or engineering advice.
The board is a grid of dots. Players take turns drawing one line between two neighbouring dots. When a line completes the fourth side of a box, that player claims the box, which is marked with their letter (A or B), and must draw again. When every line is drawn, whoever holds more boxes wins. The 3 x 3 and 5 x 5 boards have an odd number of boxes (9 and 25), so they cannot end in a tie; the 4 x 4 board has 16 and can.
Choose a Board size: 3 x 3 boxes (4 x 4 dots, 24 lines), 4 x 4 boxes (5 x 5 dots, 40 lines) or 5 x 5 boxes (6 x 6 dots, 60 lines). Pick an Opponent: the computer, or Two players on the same screen. Against the computer, choose a Difficulty and whether you play first (A) or second (B). A is always the player who moves first, with blue lines; B has amber lines. A box you close is filled in your colour and ringed, with your letter in the middle. Changing any setting starts a new game.
The board sits on a soft violet and teal panel with violet dots. A box shows the letter of whoever claimed it, not only a colour, so the two sides can be told apart without relying on colour. The result is also written out in words below the board.
A board of n x n boxes has n x n boxes and 2 x n x (n + 1) lines: n x (n + 1) horizontal and the same number vertical. The whole rule set is one small function: draw a line, count the boxes it completes (a single line can complete two), give those boxes to the mover, and hand over the turn only if none were completed. The test suite checks the line and box counts for all three sizes, that a game of only legal lines always ends after exactly the total number of lines, and that the two scores always add up to the number of boxes.
| Level | What it does |
|---|---|
| Easy | Takes a box when it can, otherwise draws a random line |
| Medium | Takes a box when it can; otherwise draws a line that does not give a box away; if every line does, the one that gives away the fewest |
| Hard | Medium, plus end-game chain control |
A line is safe when no box beside it already has two sides drawn, because drawing it would make a third side and let the other player complete the box. Medium plays a safe line whenever one exists, and the tests check that on hundreds of positions.
Near the end of a game the safe lines run out and every move opens something. The boxes with two sides drawn then form chains (runs of boxes you can take one after another) and loops (rings of boxes). The engine finds them by linking boxes that have two sides drawn and share an undrawn line.
Hard uses that in two ways:
The exact solver is checked against a plain recursive search with no memo table on random positions with up to seven lines left, and the two always agree. On a fixed set of seeded games, Hard beat Easy in 30 of 30 in the last run, from either seat and on the 3 x 3, 4 x 4 and 5 x 5 boards; the test requires at least 24 of 30 (80%). The search stops after one second, and the test allows a Hard move with 16 lines left up to two and a half seconds to leave room for slow machines.
Computer moves are spaced about 350 ms apart so a chain of boxes can be followed, and happen at once if your system asks for reduced motion. The search runs on the page itself; no background thread is used.
Nothing is uploaded and there is no account. The number of games you have won against the computer, for each board size and level, is saved in your browser’s local storage as small whole numbers inside a small JSON object under one key. Only a finished win against the computer counts, and only if you did not use undo in that game. Ties, losses and two-player games are not saved. The session tally and the current game are kept in memory only, so they reset when you leave the page. The address records only the board size, opponent, level and seat. Clearing site data removes the saved wins.
Everything runs locally in your browser.
For informational purposes only. Not financial, medical, or legal advice. You are solely responsible for how you use these tools.