Generating puzzle levels with a solver (Leave a Pebble)
puzzlelevel-generationbfssolverprocedural-generationplaytesting
How the 40 levels of Leave a Pebble (justinahampton.com/fun/freetime/pebble/) were found by search and proven by a solver rather than designed by hand. The pipeline generalizes to any small deterministic puzzle.
The game, briefly
An ice-slide puzzle: the penguin slides until something stops it and leaves a pebble on the square it pushed off from (the new mechanic; the ice-slide base is an old family). Win by stopping on every fish. Squares: rock, pebble, sea (a slide that would end in it is refused), snowman (stops you once, needs a run-up), deep snow (stops you on entry). Par is the proven minimum number of slides.
Pick the mechanic by measurement
Five candidate mechanics were prototyped and measured with the solver before choosing one: how many random boards are solvable, how long their shortest solutions are, how many dead ends they have.
Pipeline
- Rules + BFS solver in a DOM-free module (
pebble.js) shared by the game and the lab. The state includes the pebbles laid so far, so BFS over (position, pebble set, fish eaten) gives the shortest solution and par. - Search: hill-climbing with restarts over random boards, scoring traps, solution uniqueness and length. 277 million boards scored in 202 search jobs, run in parallel on 15 cores.
- Refine: strip objects that are not needed, turn unused edges into sea, dedupe.
- "Need" test: does a level really need its special squares? Four snowman levels used snowmen as plain rocks; they were replaced with levels that are unsolvable unless a snowman is broken.
- Curate into a source file (
levels.src.json) and build the shippedlevels.js(generated, never hand-edited), ordering each chapter by a difficulty measure, with a pinned teaching level first and manual nudges. - Harness: every stored solution replayed, every par re-proven by a fresh BFS, all 40 levels won in the real page with injected swipes, keys and taps.
Fairness: the liveRatio lesson
The first set maximized traps and uniqueness. A blind play-test called the long sea levels "trial and undo": their only winnable line was the solution (the ratio of live, still-winnable moves to required moves was 1). Long levels now come from a "fair" search mode or need a liveRatio of at least 2, so there is room to wander without losing. Some hazard levels intentionally fail the strict "need" test because testers liked them.
Player-facing details that fell out of the solver
- Hints = the next slide of a shortest solution from the current position; when the position is lost, say so instead of hinting.
- Following hints from the start always achieves par (harness-checked).
- Starting boards carry rocks only, so every pebble on screen is the player's own doing.
- Progress in localStorage; stars at par; the first three unsolved levels are open.
Tooling notes
No Node on the desktop; the lab runs under gjs -m (GNOME JavaScript). A batch script must not be edited while it runs, since bash re-reads it. Raw candidate pools (~100 MB) are gitignored.
Caveat
The play-tests were by AI subagents with a text tool; whether the set is fun and well ordered for a human is unverified.