Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Shunting Yard rules: a tested `shunting-yard/yard.js` that sorts numbered wagons through sidings from plain data #171
Check · Review · Land · Live done — Landed and live in production.
I added the Shunting Yard rules in shunting-yard/yard.js and tests in shunting-yard/yard.test.mjs. The new test file passes (12 tests). I didn't run bun scripts/gate.ts, and the repository has no scripts/fast.ts.
shipped production is serving it deploy ab54f53
Rules only, as issue #162 asks. It touches only shunting-yard/yard.js and its test, with no shell, town or rounds changes, and it follows the lock-keeper and allotment rules pattern. It has no I/O, network, storage or DOM, and the seed and level are clamped at the boundary, so I found nothing to flag on security. Each rule in the issue has a test: determinism, the solver per level, each refusal with the same state object returned, the move count, level advance, and the win and loss lines. The state is plain data and there is no dead code. The README and catalogue wiring are rightly left for the page pull.
The win line is judged on total moves against the summed targets, where the issue says per level. The pull discloses this and it is a sound reading, so I did not block on it. I could not run the tests here because this clone has the base commit, not the head, so I relied on the pull being green.
For the page pull, not this one: the rules never detect a stuck yard, for example when both sidings are full of blockers. The status stays playing with no legal winning move, so the page will need a restart or a stuck check.
I added the Shunting Yard rules in
shunting-yard/yard.jsand tests inshunting-yard/yard.test.mjs. The new test file passes (12 tests). I didn't runbun scripts/gate.ts, and the repository has noscripts/fast.ts.bun x tsc --noEmitprinted only its usage text, so I can't say the type check is clean. Nothing outside the folder is touched.Rules
start(seed, level): the wagons are shuffled from the seed, so the same seed and level always give the same yard. A shuffle is kept only if a solver finishes it within that level's target, so every yard can be solved.solve(state)is that solver and returns the shortest list of[from, to]moves.move(state, from, to): it takes the end wagon of one track to the end of another. It refuses a move from an empty track, onto a full siding, or onto the departure track out of order. Each accepted move counts one, and a refused move returns the same state object with awhy.Choices
To try it, run
bun test shunting-yard.Closes #162