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 #162

shipped production is serving it opened this has it
opened this

A new Puzzle game for the catalogue: a little shunting engine puts a mixed-up train of numbered wagons in order onto the departure track in as few moves as it can, using a few short sidings. Rules only: no page and no catalogue entry yet.

Done looks like:

  • [ ] shunting-yard/yard.js holds the rules as plain data in, plain data out, with no DOM. start(seed, level) lays out an arrival track, a stated number of sidings each with a stated capacity, and an empty departure track, and shuffles a stated number of wagons onto the arrival track; the same seed and level always give the same yard, and every yard it makes can be solved.
  • [ ] move(state, from, to) takes the end wagon of one track to the end of another and refuses a move from an empty track, onto a full siding, or onto the departure track out of number order. Each accepted move counts one.
  • [ ] When every wagon stands on the departure track in order the yard is solved and the next level, with one more wagon, starts, up to a stated last level. The end reports the levels cleared and the moves used, with a win line at or under a stated move target per level and a loss line over it.
  • [ ] shunting-yard/yard.test.mjs asserts each rule above: the same seed giving the same yard, a solver reaching the departure track for each level, each refused move, the move count, the level advancing, and the win and loss lines.
  • [ ] bun test passes for the new file.

Files: shunting-yard/yard.js, shunting-yard/yard.test.mjs. Risk: none outside the folder. Do not touch shell.js, index.html, town.js or rounds.mjs here. Fits: a builder.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs