Building a solver-checked puzzle for the browser
Devlog · November 2026
Why we check every dock
A sorting puzzle has one way to fail that players feel immediately: a level that cannot be won. You make a reasonable move, then another, and somewhere along the way the dock becomes a dead end without any warning. For the browser version of Baylight we decided that no dock would ship unless a program had first found a winning sequence for it. That is what we mean by solver-verified.
The browser docks are small on purpose: two levels, one with a locked lane and one with a pallet. Small does not mean unchecked, and a short puzzle is a bad place to hide a broken level.
What a state is
To search a game, you first need to say exactly what a position is. In Baylight a state is a handful of facts: how far along the belt we are, what each bay holds (a colour and a count from zero to three), how many bays are still locked, how many trucks have shipped, and what is parked on the pallet. Nothing else matters. The belt order is fixed for a dock, so the position on the belt tells us every parcel still to come.
Two different move orders can reach the very same state. For example, parking one parcel and then filling a bay can end up identical to the other order when no ship happens in between. A good search notices this and does not explore the same state twice. To do that, we turn each state into a short text key and remember the keys we have already seen.
Breadth-first search in plain words
Imagine standing at the start of a dock with a notebook. You write down every legal move from here: put the front parcel in a bay that matches or is empty, or park it on the pallet if there is room. Each move leads to a new state. You add those states to the end of a waiting list.
Then you take the first state from the front of the list, write down its moves, and add the results to the end. You keep doing that. Because the list is first in, first out, you finish every state that is one move away before touching any that is two moves away, and so on. That order is what breadth-first means.
Two things follow. First, if any winning sequence exists, the search will eventually reach it, because it does not give up on a branch halfway. Second, the first winning state it reaches is one that needs the fewest moves, which gives a short sequence to replay. When the waiting list runs dry without a win, the starting position cannot be won.
The game has a useful rhythm that keeps the search small: every move uses exactly one parcel from the belt, so the search never goes around in circles. Add the memory of seen states and the search stays tiny for docks of this size.
One detail matters for the readability of results. When there are several options, our search tries matching bays first, then empty bays, then the pallet. That does not change whether a dock can be won; it changes which of several equally good answers we show, and it favours the natural play of stacking like with like.
How the buttons use it
The Step Solver Move button runs the same search from whatever position is on the screen, not only from the start. It finds a winning path, plays only the first move of it, and stops. Press it again and it searches again from the new position. This is why it still helps after you have made your own mistakes: it never trusts an old answer. If the position cannot be won, the search finds nothing and the page tells you it is a dead end, and Undo or Reset gets you out.
The Replay Full Sequence button is different. It plays a stored list of moves from the start of the dock, one move at a time, with a short pause between moves, or all at once if the visitor has asked their device for reduced motion. The stored list is what the search found ahead of time, so the replay does not need to search at all.
Keeping web and app rules in sync
The browser version is a second implementation of rules that already exist in the game. Two copies of rules drift apart unless you tie them together. We do this with fixtures. A small script runs the game's own rule engine, solves both docks, and writes out a data file with each level and its winning moves, including the state after every move. The web page's level data and replay lists come from that file.
Our automated tests then replay the stored moves against the game's rules and compare the results state for state. If the web page's rules ever disagree with the game, even in a corner such as a parcel leaving the pallet at the wrong time, the test fails before the page goes out. The same tests also check that every stored sequence ends with an empty dock.
What we learned
- Write the state down first. Once we could list exactly what a position is, the search almost wrote itself, and so did the test.
- Deduplicate states. Remembering what you have seen is the difference between an instant answer and a slow page.
- Search from the current position. A hint that only works from the start is not a hint.
- Generate, do not retype. Level data copied by hand drifts. Level data exported from the game does not.
- Say when it cannot be won. A clear dead-end message is kinder than a silent failure.
If you spot a dock that behaves differently from what we describe here, tell us at aviisr@aviisrgames.com. You can play both docks on the browser dock page.