What it does
Each tube is a stack of colours, bottom first, with a capacity. A move takes the top colour of one tube and puts it in another that is empty, or that has the same colour on top and room for it. In the run mode, in the style of Water Sort, the whole matching top run pours, as much as fits. In the single mode, in the style of Ball Sort, one piece moves at a time. The puzzle is solved when every tube in use is full of a single colour.
You send apply({ from, to }) and get back one event saying which colour moved and how many, for your presenter to
animate the pour. An invalid move returns a reason, such as a different colour, a full tube or an empty source, and
changes nothing, so the game can wobble the tube and say why. legalActions lists every move, and undo, redo and
reset are built in.
The generator shuffles each colour into full mixed tubes plus empty spares and keeps a deal only when a solver solves it, so a player is never handed an impossible level. It measures how mixed the deal is and keeps trying until it reaches the tier's target. For hints there are three solvers: an exact search for the shortest plan on small puzzles, a guided search that is far faster on full-size deals, and the deal's own solution, used instantly while the player is still on its route.
Features
- Two pouring rules —
'run'pours the whole matching run;'single'moves one piece. - Mixed tube sizes — one capacity for every tube, or one per tube.
- Move limits — an optional
maxMoves, after which an unsolved puzzle is lost. - Part-filled levels —
requireFull: falseallows uneven colour counts, with each colour gathered as tightly as the tubes allow. - Proven seeded deals —
generateContainerSortdeals from a seed and proves each deal solvable before returning it. - Four difficulty tiers — from 3 colours in tubes of four up to 9 colours in tubes of five, each with two spare tubes.
- Hint solvers —
solvefor the shortest plan,solveGuidedfor speed,solveBestto follow the deal's own solution. - Clear refusals — every invalid move has a named reason and leaves the puzzle as it was.
- Undo, redo and reset, and a preview of any move without playing it.
Good for
- Liquid-sort puzzles, in the style of Water Sort, with pours that fill as much as fits.
- Ball-sort puzzles, in the style of Ball Sort, moving one ball at a time.
- Stacking variants such as nut-sort and hoop-stack games, on the same pour-onto-its-match rule.
- Level-based mobile puzzles that need an endless supply of solvable levels at rising difficulty.
- Hand-made levels with uneven tubes, part-filled colours and a move limit.
Make it yours
A level is a configuration: the tubes and their colours, one capacity or one per tube, whether a sorted tube must be full, a move limit and the pouring rule. Authored levels can use any of these, so a tight hand-made puzzle with a small tube and a move limit is just data.
The generator takes a difficulty tier and lets you override any of its settings: the colour keys, the tube capacity, the number of spare tubes, the pouring rule the deal is proven under, the seed, the mixing target, the number of attempts and the solver's budget. It can also build a deal by playing moves backwards from a sorted position, which can leave tubes part full.
Two very different games: a liquid-sort ladder of generated deals, from easy three-colour levels to very hard ones with nine colours in tubes of five; and a hand-made ball-sort level with four tubes, one of them shorter, one ball a move and a limit of twelve moves.
A quick look
A hard seeded deal, a move played, and a hint:
const deal = generateContainerSort({ seed: 23, difficulty: 'hard', transfer: 'run' });
const tubes = createContainerSort(deal.config, deal.solution);
const r = tubes.apply({ from: 0, to: 4 });
if (r.valid) pour(r.events[0]!); // { type: 'transferred', from, to, color, count }
else wobble(r.reason); // 'different-color', 'full-destination', ...
const hint = tubes.solveBest(20000).actions[0];
Works with
shelf-sort— for moving single goods between shelf slots into any free space.boarding-queue— for colour matching that boards passengers onto vehicles.tween— to animate the pours and moves the events describe.
Good to know
- Hidden colours, locked or frozen tubes, ice and extra-tube boosters are not built in; model them in the game or author the starting position.
- The exact solver grows very quickly on full-size deals; use
solveBestorsolveGuidedfor hints, with a small budget inside a frame. A search that runs out of budget never means the puzzle is impossible. - How mixed a deal is measures its fragmentation, not how hard a person finds it.
- Levels hold 2 to 24 tubes, each of capacity 1 to 32.






