Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Allotment rules: a tested `allotment/plot.js` that plants a season of crops on a grid and scores neighbours from plain data #170
Check · Review · Land · Live done — Landed and live in production.
I added the Allotment rules in allotment/plot.js and its tests in allotment/plot.test.mjs. The 12 tests pass with bun test allotment. I did not run the full suite.
shipped production is serving it deploy ab54f53
Rules-only pull, matching how Lock Keeper (#154) and Hoopla landed their rules before their pages. It adds no route, write or dependency, so the security and terminal items do not apply yet. I could not check out the pull branch here, so I read the diff and did not run the tests or open the preview. I traced the arithmetic in the win/lose test by hand (30, 31, 28, 27) and it holds. The behaviours the issue lists (seeded hand, refusals that return the same state, neighbour scoring, diagonals and no wrap, end of season, the 28 win line) each have a test. The module is small and has no dead code.
Two things I would do next:
- In the page pull, call
bestOfonce per seed, not on everystart. It runs 8 hill-climbs of full-grid swaps and is the one place that could break the 50 ms budget on a phone. Show the player theCROPS[c].textrules on screen. Make the beds real buttons with a visible focus ring, at least 44px square at 360px, witharia-labeltext like "row 2, column 3, empty". Announcestate.linein anaria-liveregion. Say what a refused plant means in words, using thewhycode. - Credit the companion-planting tradition the crops draw on in the page copy, as the other games do for theirs. Add the town entry and the catalogue test row in that same pull, so the game is reachable in two taps.
I added the Allotment rules in
allotment/plot.jsand its tests inallotment/plot.test.mjs. The 12 tests pass withbun test allotment. I did not run the full suite.docs/VISION.mdandAGENTS.mddon't exist in this clone, andscripts/gate.tsandscripts/fast.tsaren't present either, so none of those ran.bun x tsc --noEmitprinted only its usage text; the repository has no tsconfig, so it checked nothing.What the rules do
-
start(seed)makes an empty 5×5 grid, 12 turns and a seeded hand of 12 packets. The same seed always gives the same hand. - It also carriesbest,targetand a status line.plant(state, x, y):- It plants the next packet in an empty bed. - It refuses a filled bed, a cell off the grid (including non-integers and NaN) and any plant once the season is over. - A refusal returns the same state object and a reason.
- Beans: +3 per touching sweetcorn. - Sweetcorn: −1 per touching sweetcorn. - Carrots: −2 per touching onion. - Onion: +2 per touching lettuce. - Lettuce: +2 per touching carrots.
score(state): totals the grid from those rules alone.result(state)then returns{score, best, won, line}. A score of 28 or more wins, and below 28 loses. The tests check 28 wins and 27 loses.Choices to check
bestOf(seed)finds it with a deterministic hill-climb from 8 seeded starts. It is a floor on the true best, not a proof. Seeds 1–8 all reach at least 36, so the target of 28 is reachable on every one of them.Not done
shell.js,index.html,town.jsorrounds.mjs.Try it
bun test allotmentCloses #157