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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy ab54f53

opened this

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. docs/VISION.md and AGENTS.md don't exist in this clone, and scripts/gate.ts and scripts/fast.ts aren't present either, so none of those ran. bun x tsc --noEmit printed only its usage text; the repository has no tsconfig, so it checked nothing.

What the rules do

  • The grid and the hand:

- 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 carries best, target and 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.

  • Crops: there are five. Each crop scores 1, plus its own rule once for each bed that shares an edge with it. Diagonals don't touch.

- 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.
  • Ending: the season ends when the 12 packets are used or the grid is full, and 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

  • "The best" isn't defined in the issue, so I took it as the best score the hand can reach. 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.
  • Neighbour rules belong to the crop that owns them. Beans beside sweetcorn score for the beans, and the sweetcorn's own rule is separate.
  • The target of 28 and the 5×5 grid are my picks.

Not done

  • No page or catalogue entry, as the issue says. I didn't touch shell.js, index.html, town.js or rounds.mjs.

Try it bun test allotment

Closes #157

Approved

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:

  1. In the page pull, call bestOf once per seed, not on every start. 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 the CROPS[c].text rules on screen. Make the beds real buttons with a visible focus ring, at least 44px square at 360px, with aria-label text like "row 2, column 3, empty". Announce state.line in an aria-live region. Say what a refused plant means in words, using the why code.
  2. 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.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs