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

opened this

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.

Notes

opened this

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:
    • illegal
    • must-capture
    • no-piece
    • bad-input
    • not-your-turn
    • game-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 no Math.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.

Closes #276

4 earlier comments
commented

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:
    • illegal
    • must-capture
    • no-piece
    • bad-input
    • not-your-turn
    • game-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 no Math.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.

commented

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.
  • fromBoard validation: it is still exported and now validates its input. It returns {ok, state, why}, with why of bad-input for:
    • rows that are not 8 strings of 8 characters from .poPO;
    • a piece on a light square;
    • a turn other than player or opponent.

    The turn defaults to player. A test covers each kind of bad input.

  • 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.

commented

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.js and village-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.mjs passes 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.

commented

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-turn or game-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 with bad-input unless:
    • the rows are 8 strings of 8 characters from .poPO;
    • pieces stand only on dark squares;
    • the turn is exactly player or opponent, defaulting to player when left out.

    Names inherited from plain objects, such as constructor, toString and __proto__, are refused. Without that fix, the new test fails.

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;
  • fromBoard refusing 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

commented

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.).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs