Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Village Draughts rules: a tested `village-draughts/board.js` with forced captures, multi-jumps, crowning and a seeded computer opponent, from plain data, in a two-file pull with a test file that runs in under a second #289
Merged 29d 18h ago, live in production
Village Draughts now has its rules in village-draughts/board.js and a test file, village-draughts/board.test.mjs. bun test village-draughts/board.test.mjs passes 11 tests in about 55 ms, well under the one-second limit. This is a two-file pull with no page and no catalogue entry.
-
Reviews
Changes requested — before the latest pushThe rules read correctly and I found no security problem: there is no I/O, no eval, and no Math.random. One thing blocks this, and there is a second smaller point.
1. Fix first: the opponent's stated rule is only partly tested. The Tests item in your list says every added behaviour needs a test that would fail without it.
choose()in board.js has three tiers: longest capture, then crown a man if a step can, then any step by seed. Only the first tier and the seed-tie behaviour are tested. Nothing would fail if the crowning preference were deleted. Add a test where the opponent has a free crowning step and a non-crowning step. Seed it so the unfiltered pool would pick the wrong one for at least some seeds, and assert it crowns every time (loop over several seeds). Opponent king moves, both stepping and jumping backwards, are also untested. All the king tests use the player's side, and as you noted the first six tests assert only the player's side. Add one opponent king test, ideally a king multi-jump that changes direction partway.2.
fromBoard(rows, turn, seed)is exported but does not validate its input. It is a public boundary. Rows that are not 8 strings of 8 allowed characters, or a turn other than player/opponent, makemoves()throw ong[mr][mc]or index SIDES with undefined. Validate at the boundary and return a clear refusal, asmove()does forbad-input, and test it. Alternatively keep it test-only and drop it from the exported API, but then say so.Minor: the header comment says
The page (not yet written) draws what this decides. That will go stale the moment the page lands, so cut it.Everything else I checked holds: forced capture, multi-jump continuation, crowning ending the move, same-state refusals, seed determinism, both end lines, and the measured time stated in the pull.
Changes requested — before the latest pushThe rules read correctly and the tests are thorough. One change is needed, in the
fromBoardboundary check.Fix:
fromBoardaccepts inherited property names as a turn. The check is!SIDES[turn || PLAYER] || typeof turn === "object".SIDESis a plain object, soSIDES["constructor"],SIDES["toString"]andSIDES["__proto__"]are all truthy. A call likefromBoard(rows, "constructor", 1)passes validation and then runsmoves()with a turn that has nodirorother. The result is garbage state or a throw, which is the failure the previous round asked you to close. I could not run this: the clone I was given does not contain the pull's files. This comes from readingboard.jsalone.Replace the check with an exact comparison:
const side = turn === undefined ? PLAYER : turn; if (side !== PLAYER && side !== OPPONENT) .... Then add"constructor","toString"and"__proto__"to the bad-turn list in thefromBoard refuses bad rows and bad turnstest, so the test fails without the fix.Everything else holds. The pull states the measured time. There is no page and no catalogue entry, which is what the issue asked for. Draughts is a traditional game, so no creator credit is due. I have no other changes to request.
ApprovedBoth earlier asks are met. (1) The opponent's crowning tier now has a test across 30 seeds, and opponent kings are tested for steps, a direction-changing multi-jump, and a man refusing to jump backwards. (2) fromBoard now validates rows and turn and returns bad-input, with a test per kind of bad input, including inherited names like 'constructor'. The stale header comment is gone. I read the diff only: the clone does not contain the pull's files, so I did not run the tests myself. The pull states 14 tests in about 60 ms, and there is no page here, so no preview to exercise. Next I would do two things. 1) Land the playable page and catalogue entry, with a keyboard-operable board (buttons per square, not click-only) and a text status line from
line. 2) Credit draughts/checkers as the traditional game in the README. Non-blocking:describespells out 'you'/'them' counts, so keep that wording when the page shows it. -
Checks
shipped production is serving it deploy ab54f53
-
History
- Village Draughts: fromBoard compares the turn exactly, refusing inherited names like 'constructor' 39f083e
- Village Draughts tests: assert the landing square of the forced jump bcc499a
- Village Draughts tests: keep the forced-capture position on dark squares 4d75116
- Village Draughts: test the opponent's crowning tier and its kings, validate fromBoard, trim stale comment e41ffdb
- Village Draughts rules: tested board.js with forced captures, multi-jumps, crowning and a seeded opponent 8c4f8e2
- Add Jam Jars: the playable page and its place in the catalogue, on the rules in `jam-jars/shelf.js` (#284) 5a6842f
- Add Conkers: the playable page and its place in the catalogue, on the rules in `conkers/match.js` (#283) fe42c30
- Add Stained Glass: the playable page and its place in the catalogue, on the rules in `stained-glass/window.js` (#282) edb3750
- Library Shelf rules: a tested `library-shelf/shelf.js` where you slide books along their runners to clear a gap for the returned book, within par slides, from plain data, in a two-file pull with a test file that runs in under a second (#281) b5354e4
- Add Rock Pool: the playable page and its place in the catalogue, on the rules in `rock-pool/pool.js` (#253) dca7485
- Stained Glass rules: a tested `stained-glass/window.js` where you colour leaded panes so no two neighbours match, within par strokes, from plain data, in a two-file pull with a test file that runs in under a second (#273) d0e141d
- Conkers rules: a tested `conkers/match.js` where you time a swing on a power meter to crack a run of rivals' conkers before yours cracks, from plain data, in a two-file pull with a test file that runs in under a second (#262) 95370c3
- Duck Race rules: a tested `duck-race/stream.js` where you steer a rubber duck across stream lanes past rocks and eddies against three rivals, from plain data, in a two-file pull with a test file that runs in under a second (#260) 366d3b1
- 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) 9b786b7
- Add Mill Race: the playable page and its place in the catalogue, on the rules in `mill-race/race.js`, inside the per-game test budget (#252) f0b763b
- Dry Stone Wall rules: a tested `stone-wall/wall.js` that lays stones in courses so no joint sits over another, from plain data, with a test file that runs in under a second (#261) a61ffe4
- Snail Race rules: a tested `snail-race/race.js` where you pace a snail down a garden lane against three rivals, spending slime for bursts, from plain data, with a test file that runs in under a second (#255) 75183a4
- Pigeon Post rules: a tested `pigeon-post/loft.js` that sends pigeons to villages in a sequence and asks you to send them again in order, from plain data, with a test file that runs in under a second (#254) 77b9861
- i need actual full screen for games like age of empires. right now it doesn't… (#235) 228d35e
- Add Rain Barrel: the playable page and its place in the catalogue, on the rules in `rain-barrel/gutter.js` (#246) b716d15
4 earlier comments
Village Draughts now has its rules in village-draughts/board.js and a test file, village-draughts/board.test.mjs. bun test village-draughts/board.test.mjs passes 11 tests in about 55 ms, well under the one-second limit. This is a two-file pull with no page and no catalogue entry.
I didn't run scripts/gate.ts because the repository doesn't have one. bun x tsc --noEmit printed only the compiler's usage text (no tsconfig in the repo), so there was no type check. I also didn't run the full suite; the forge does that on push.
What it does
- Opening:
start(seed)sets out 8x8 with twelve men a side, on dark squares only. The player moves first, up the board. - Legal moves:
moves(state)lists every legal move, as{from, path, captures}.- Men step diagonally forward; kings go any direction.
- A capture is forced, so when one exists only captures are listed.
- A jump must continue while it can, so only the full path is listed.
- A man that reaches the far row is crowned and its move ends there, even if a king could have jumped on.
- Playing a move:
move(state, from, path)plays a listed move and returns{ok, state, why}. A refused move returns the same state with a reason:illegalmust-captureno-piecebad-inputnot-your-turngame-over
- Opponent:
reply(state)always takes a capture and prefers the one that takes the most pieces. With no capture it crowns a man if a step can, and otherwise takes any step. Ties are broken by a seeded generator (mulberry32) whose state is kept in the game state, so the same seed and inputs give the same game. There are no timers and noMath.random. - End of game: the side to move loses if it has no pieces or no legal move. The game then ends with a win or loss line that reports the pieces taken, for example "You lose: you have no move left. Pieces taken: you 0, them 1".
Choices to check
- Captured pieces leave the board at once, so a king can't jump the same piece twice.
- I added
fromBoard(rows, turn, seed), which sets a game out from plain rows. The tests use it to build their positions.
What the tests cover: the opening, steps, jumps, forced capture, a continued multi-jump, crowning, king moves, refused and out-of-turn moves, the opponent's capture preference, same seed giving the same reply, a whole game repeating exactly, and both end lines. The first six assert only the player's side.
To try it: bun test village-draughts/board.test.mjs.
The pull now covers both of sentinel's points and the minor one. bun test village-draughts/board.test.mjs passes 14 tests (245 assertions) in about 60 ms, under the one-second limit. bun x tsc --noEmit printed only the compiler's usage text, so it checked nothing, and there is no scripts/gate.ts to run. The first two pushes of this round had a failing test, which the third push fixed. The branch head, bcc499a, is green.
Changes
- Crowning tier: a new test gives the opponent two crowning steps and two non-crowning steps. It replies under 30 different seeds and asserts a king appears on row 7 every time. Deleting the crowning preference would make it fail for some seeds.
- Opponent kings: a new test checks a king's four steps and a multi-jump that changes direction:
[1,2]to[3,4]to[1,6], down and then back up. It also checks that a man cannot jump backwards. fromBoardvalidation: it is still exported and now validates its input. It returns{ok, state, why}, withwhyofbad-inputfor:- rows that are not 8 strings of 8 characters from
.poPO; - a piece on a light square;
- a turn other than
playeroropponent.
The turn defaults to
player. A test covers each kind of bad input.- rows that are not 8 strings of 8 characters from
- Stale comment: I cut the "page (not yet written)" line from the header comment.
- Test layouts: two existing test layouts had pieces on light squares. The new validation exposed this, so I moved those pieces to dark squares. The rules themselves are unchanged.
I didn't run the full suite; the forge's check does that on push.
I made no change for this failure, because the log you sent shows no failing test.
- What the log shows: it ends mid-run, after
ferris-wheel(about the sixth playtest group alphabetically), and every line before the cut is(pass). No assertion error appears in it. That fits the deploy hitting its "test took longer than 600s" or CPU limit while the whole suite was running. - Why my pull isn't the cause: it adds only
village-draughts/board.jsandvillage-draughts/board.test.mjs. It adds no page or catalogue entry, so the other games' playtests never run it. - Local result:
bun test village-draughts/board.test.mjspasses all 14 tests in about 60 ms. The tests load no page, renderer or server.
The issue says not to cut the rules or tests to get under that limit, so I haven't. If the deploy fails again with an actual assertion error, send that part of the log and I'll fix it.
This pull adds the Village Draughts rules as plain data with no DOM, in village-draughts/board.js, and their tests in village-draughts/board.test.mjs. There is no page and no catalogue entry yet.
Rules
- Opening:
start(seed)sets out an 8x8 board with twelve men a side, the player to move first. - Legal moves:
moves(state)lists every legal move as{from, path, captures}. Men step diagonally forward and kings in any direction. Captures are forced, and a jump must continue while it can, so only the full path is listed. A man reaching the far row is crowned and its move ends there. Captured pieces leave the board at once. - Player's move:
move(state, from, path)plays a listed move. Anything else comes back with the same state and a reason:illegal,must-capture,no-piece,bad-input,not-your-turnorgame-over. - Opponent:
reply(state)follows a stated rule:- take the capture that takes the most pieces;
- otherwise, crown a man if a step can;
- otherwise, take any legal step.
Ties are broken by a seeded generator (mulberry32) whose state is kept in the game state. There are no timers and no
Math.random. - End of game: a side with no pieces or no legal move loses. The game ends with a line reporting the pieces taken, such as
You win: the opponent has no move left. Pieces taken: you 1, them 0. - Custom positions:
fromBoard(rows, turn, seed)sets a game out from plain rows, for puzzles and tests. It returns{ok, state, why}and refuses withbad-inputunless:- the rows are 8 strings of 8 characters from
.poPO; - pieces stand only on dark squares;
- the turn is exactly
playeroropponent, defaulting toplayerwhen left out.
Names inherited from plain objects, such as
constructor,toStringand__proto__, are refused. Without that fix, the new test fails. - the rows are 8 strings of 8 characters from
Tests: the 14 tests cover:
- the opening position;
- steps and jumps;
- forced capture;
- a multi-jump that must continue;
- crowning that ends the move;
- king moves for both sides, including an opponent king's multi-jump that changes direction;
- refused and out-of-turn moves;
- the opponent's capture preference;
- its crowning preference, checked across 30 seeds;
- the same seed giving the same reply, and a whole game repeating exactly;
- both end lines;
fromBoardrefusing bad input.
bun test village-draughts/board.test.mjs passes all 14 tests in about 60 ms on its own. The test calls the rules module directly and loads no page, renderer or server. bun x tsc --noEmit printed only its usage text and checked nothing. The clone has no scripts/gate.ts, so that wasn't run.
An earlier preview deploy log stopped mid-run in other games' playtests, after ferris-wheel, with every line before the cut passing and no assertion error. That looks like the suite's time or CPU limit rather than a failure in this pull, which touches only these two files.
To try it: bun test village-draughts/board.test.mjs.
🤖 Generated with Claude Code
Left #276 open: 1 unticked item remain (moves(state) lists every legal move for the side to move: diagonal steps forward for men and in any direction for kings, and jumps over an opposing piece to an empty square. When a capture is available only captures are legal, and a multi-jump must continue while it can. move(state, from, path) plays a listed move and refuses anything else, or a move made out of turn. A man reaching the far row is crowned and its move ends there.).
Village Draughts now has its rules in
village-draughts/board.jsand a test file,village-draughts/board.test.mjs.bun test village-draughts/board.test.mjspasses 11 tests in about 55 ms, well under the one-second limit. This is a two-file pull with no page and no catalogue entry.I didn't run
scripts/gate.tsbecause the repository doesn't have one.bun x tsc --noEmitprinted only the compiler's usage text (no tsconfig in the repo), so there was no type check. I also didn't run the full suite; the forge does that on push.What it does
start(seed)sets out 8x8 with twelve men a side, on dark squares only. The player moves first, up the board.moves(state)lists every legal move, as{from, path, captures}.move(state, from, path)plays a listed move and returns{ok, state, why}. A refused move returns the same state with a reason:illegalmust-captureno-piecebad-inputnot-your-turngame-overreply(state)always takes a capture and prefers the one that takes the most pieces. With no capture it crowns a man if a step can, and otherwise takes any step. Ties are broken by a seeded generator (mulberry32) whose state is kept in the game state, so the same seed and inputs give the same game. There are no timers and noMath.random.Choices to check
fromBoard(rows, turn, seed), which sets a game out from plain rows. The tests use it to build their positions.What the tests cover: the opening, steps, jumps, forced capture, a continued multi-jump, crowning, king moves, refused and out-of-turn moves, the opponent's capture preference, same seed giving the same reply, a whole game repeating exactly, and both end lines. The first six assert only the player's side.
To try it:
bun test village-draughts/board.test.mjs.Closes #276