Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Fence Posts rules: a tested `fence-posts/field.js` where you and a farmer take turns fencing between posts and claim each pen you close, from plain data, in a two-file pull with a test file that runs in under a second #317
Check · Review · Land · Live done — Landed and live in production.
I added the Fence Posts rules in fence-posts/field.js with fence-posts/field.test.mjs, and nothing outside that folder changed. bun test fence-posts/field.test.mjs passes: 17 tests, 278 expectations, 72 ms in the runner. The file loads no page, renderer or server.
shipped production is serving it deploy ab54f53
I added the Fence Posts rules in fence-posts/field.js with fence-posts/field.test.mjs, and nothing outside that folder changed. bun test fence-posts/field.test.mjs passes: 17 tests, 278 expectations, 72 ms in the runner. The file loads no page, renderer or server.
I did not run scripts/gate.ts because the repo has no such script. bun x tsc --noEmit printed only its usage text, because there is no tsconfig to check against, so type checking did not run.
What changed
- Field:
start(seed)makes a 4×4 grid of pens (5×5 posts, 40 lengths of fence). You move first, and each pen gets 1–5 sheep from the seed. The only randomness is a seeded mulberry32 stream, with noMath.randomand no timers. - Edges: a length is written
h:r:c(between posts (r,c) and (r,c+1)) orv:r:c(between posts (r,c) and (r+1,c)).fences(state)lists the unbuilt ones. - Building:
build(state, edge, player = 'you')refuses a built edge, an off-grid or malformed edge, a move out of turn, an unknown player, or a finished game. A refusal returns the same state object and a reason. Closing one or two pens claims them for the builder, who moves again. Otherwise the turn passes. - Farmer's rule:
reply(state)plays until the turn passes back. It closes any pen it can. Otherwise it picks a length that gives no pen a third side. Otherwise it gives away the fewest pens. Ties are broken by one seeded draw, and a single candidate draws nothing. - End of game: when all 40 lengths are built, more sheep wins and a tie in sheep goes to more pens. I added a
tiedstatus for a tie in both, since the issue didn't say what happens then. The line reads likeYou win: 21 sheep to 14, 9 pens to 7. - Tests: they cover the same seed giving the same field and replies, each refusal reason, a single and a double close, the extra move, the turn passing, each farmer rule step with the tie-break, whole games to 40 lengths, and the win, loss, sheep tie-break and draw lines.
Left out
- No page, no catalogue entry and no
shell.jschanges, as the issue asked. - The farmer's rule 1 closes whichever closing length the seed picks. It does not prefer one that closes two pens.
To try it
bun test fence-posts/field.test.mjs
Or const F = require('./fence-posts/field.js'), then F.reply(F.build(F.start(1), 'h:0:0').state).
🤖 Generated with Claude Code
Clean rules module. I read every changed line. It has no I/O, no DOM, no Math.random and no timers. Input is validated by a strict edge regex plus bounds, and refusals return the same state object with a reason. The farmer rule matches the issue: close, then safe, then fewest, with one seeded draw per tie. The tests cover each rule and the pull states the measured time (72 ms). The pull adds no page, so there is nothing for a door, header or CSRF check to apply to.
I added the Fence Posts rules in
fence-posts/field.jswithfence-posts/field.test.mjs, and nothing outside that folder changed.bun test fence-posts/field.test.mjspasses: 17 tests, 278 expectations, 72 ms in the runner. The file loads no page, renderer or server.I did not run
scripts/gate.tsbecause the repo has no such script.bun x tsc --noEmitprinted only its usage text, because there is no tsconfig to check against, so type checking did not run.What changed
start(seed)makes a 4×4 grid of pens (5×5 posts, 40 lengths of fence). You move first, and each pen gets 1–5 sheep from the seed. The only randomness is a seeded mulberry32 stream, with noMath.randomand no timers.h:r:c(between posts (r,c) and (r,c+1)) orv:r:c(between posts (r,c) and (r+1,c)).fences(state)lists the unbuilt ones.build(state, edge, player = 'you')refuses a built edge, an off-grid or malformed edge, a move out of turn, an unknown player, or a finished game. A refusal returns the same state object and a reason. Closing one or two pens claims them for the builder, who moves again. Otherwise the turn passes.reply(state)plays until the turn passes back. It closes any pen it can. Otherwise it picks a length that gives no pen a third side. Otherwise it gives away the fewest pens. Ties are broken by one seeded draw, and a single candidate draws nothing.tiedstatus for a tie in both, since the issue didn't say what happens then. The line reads likeYou win: 21 sheep to 14, 9 pens to 7.Left out
shell.jschanges, as the issue asked.To try it
Or
const F = require('./fence-posts/field.js'), thenF.reply(F.build(F.start(1), 'h:0:0').state).🤖 Generated with Claude Code
Closes #303