Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Jam Jars rules: a tested `jam-jars/shelf.js` where you pour layers of fruit between jars until each holds one fruit, within par pours, from plain data, in a two-file pull with a test file that runs in under a second #274
Check · Review · Land · Live done — Landed and live in production.
This adds the Jam Jars rules and their tests, as a two-file pull: jam-jars/shelf.js and jam-jars/shelf.test.mjs. There is no page and no catalogue entry yet. bun test jam-jars/shelf.test.mjs passes: 17 tests, 74 expectations, 489 ms of test time and 0.50 s wall clock.
shipped production is serving it deploy ab54f53
This adds the Jam Jars rules and their tests, as a two-file pull: jam-jars/shelf.js and jam-jars/shelf.test.mjs. There is no page and no catalogue entry yet.
bun test jam-jars/shelf.test.mjs passes: 17 tests, 74 expectations, 489 ms of test time and 0.50 s wall clock. I ran no other tests, and bun x tsc --noEmit printed only its usage text. The repository has no scripts/gate.ts, so I ran no gate.
What it does
- State:
shelf.jstakes and returns plain data, with no DOM, timers or randomness. - Levels:
start(level)loads one of four hand-made levels. Jars are lists of fruit from bottom to top. A level fixes the jar capacity and the par. - Pouring:
pour(state, from, to)moves the top run of matching layers, as many as fit.
- It refuses an empty from, a full to, the same jar twice, a different fruit on top of to, or a bad jar number. A refused pour returns the same state with a reason.
- Every accepted pour counts one move.
- Undo:
undoreverses the last pour of the level and costs a move. - Solving: a level is solved when every jar is empty or full of one fruit. It scores 100, plus 50 at or under par, and the next level begins.
- Winning: after the last level the state becomes
won, with a line giving total pours against total par. - Restart:
restartreplays the current level and keeps the score and totals from earlier levels. There is no loss.
Tests
- A breadth-first search in the test proves every level is solvable. It also checks each stated par is the fewest possible pours, so par is 5, 7, 7 and 10.
- The other tests cover each refusal, run movement, partial fit, move counting, undo, par bonus, next level, restart, and the win line.
- One test plays all four levels through by search and reaches the win.
Left out
- Undo and totals: undo only reaches back within a level, and an undo's move counts in that level's pours and in the totals.
- Check log: I could not see the forge check's log from here. If it fails only on "took longer than 600s" or a CPU limit, that is a limit and not the rules.
🤖 Generated with Claude Code
Approved. The rules module is plain data in and out, with no DOM. Each refusal returns the same state with a reason. The test file searches every level for its fewest-pours solution, so par is proven, and it covers each rule in the issue. The pull states 489 ms for the test file. This pull has no page, so the preview shows nothing of it, which fits a two-file rules pull. I did not run the tests myself.
Two things I would do next:
- Build the page: server-render the jars and give every jar a real button, at least 44px, with an accessible name such as "Jar 2, top: 2 figs". The selected jar must not be shown by colour alone. Word the refusal reasons (empty, full, same-jar, mismatch, bad-jar, over, nothing) as sentences for a person. That means the page needs a reason-to-text map, which the rules module does not provide.
- Add the catalogue entry, with credit for the pour-sort puzzle genre it follows (Ball Sort, Water Sort and similar). The shelf.js header should carry that credit too.
This adds the Jam Jars rules and their tests, as a two-file pull:
jam-jars/shelf.jsandjam-jars/shelf.test.mjs. There is no page and no catalogue entry yet.bun test jam-jars/shelf.test.mjspasses: 17 tests, 74 expectations, 489 ms of test time and 0.50 s wall clock. I ran no other tests, andbun x tsc --noEmitprinted only its usage text. The repository has noscripts/gate.ts, so I ran no gate.What it does
shelf.jstakes and returns plain data, with no DOM, timers or randomness.start(level)loads one of four hand-made levels. Jars are lists of fruit from bottom to top. A level fixes the jar capacity and the par.pour(state, from, to)moves the top run of matching layers, as many as fit.- It refuses an empty
from, a fullto, the same jar twice, a different fruit on top ofto, or a bad jar number. A refused pour returns the same state with a reason. - Every accepted pour counts one move.undoreverses the last pour of the level and costs a move.won, with a line giving total pours against total par.restartreplays the current level and keeps the score and totals from earlier levels. There is no loss.Tests
Left out
🤖 Generated with Claude Code
Closes #257