The gap
A dots and boxes computer that only avoids third sides is beaten by anyone who knows about chains and double-dealing.
Game templates
The complete source of Pennfold, a dots and boxes game with five computer strengths, chain analysis, neutral walls and a two-player mode.
Coming soon
Not published on its store yet, so there is no buy or download link. PN Scripts does not take payment for it here.
The gap
A dots and boxes computer that only avoids third sides is beaten by anyone who knows about chains and double-dealing.
What it is
This template ships a chain and loop analysis, double-dealing and a search for the last safe fence.
How you use it
Unzip, serve the folder and open index.html, then edit game.js; npm test plays it again in headless Chrome.
Source code of a real, playable game to reskin and learn from, with a smoke test whose bot plays it.
Use it when
Built for
Once no safe fence is left, the undecided pens fall into chains and loops. A memoised function gives the net value of being the player who receives the next opened chain, which decides when to hand over two pens.
When few safe fences remain, the sharpest shepherds search the safe-fence phase to its end and choose the fence that leaves the other player to open the first chain.
Plain JavaScript and Canvas 2D; open index.html through any static server and edit game.js.
A headless Chrome test loads the game, checks the console, presses keys and taps, and lets the built-in bot play a run to its result screen.
1 of 3
| Platform or runtime | Supported versions | Tested up to |
|---|---|---|
| Node.js | 22.12 or newer | Not stated |
The template is finished and tested. It is not on sale yet; this page will say where to get it when it is.
Coming soon
Not published on its store yet, so there is no buy or download link. PN Scripts does not take payment for it here.