Add Checkers, Backgammon, Mastermind, and Pirates and Bulgars

The four games that were listed but not written. Nothing in the
catalogue is marked "coming soon" any more.

Checkers is English draughts on the thirty-two dark squares, numbered
the way the game is written down. Captures are compulsory and a multiple
jump is one move object, so a player cannot stop halfway through one —
true by construction rather than by a rule that has to be enforced
somewhere. The move generator matches the published perft counts at one
to four ply (7, 49, 302, 1469), which fold in compulsory capture,
crowning and the men's forward-only rule all at once.

Backgammon's hard rule is not how a checker moves but that a player must
use as much of the roll as they can, and that cannot be checked one move
at a time: a move can be illegal precisely because playing it strands
the other die. So the generator works backwards from whole turns —
memoised depth-first over the remaining dice — and offers only the first
steps of the longest plays. Recomputing it after each checker is what
makes the rule true by construction. Every die comes from the table's
seed and a count of rolls made, which is in the state rather than beside
it so a game is reproducible from what crosses the wire. There is no
doubling cube; the rules document says so plainly.

Mastermind is played as a duel — both players are set a code and both
are breaking one — because the pencil-and-paper game gives the codemaker
nothing to do. It ends at the foot of a round, never mid-round, or going
first would be worth half a guess. It is the one game here with anything
to hide, so viewFor does real work: the host sends each device only its
own code, and a device that was never given a code refuses to score a
guess against it rather than quietly answering "nothing".

Pirates and Bulgars is Sackson's theming of Asalto, and the rules
document is explicit about which parts are attested and which had to be
chosen — the book could not be obtained. Two hunters who take by
jumping against twenty-four who cannot take at all, on a thirty-three
point cross whose drawn lines come from the same adjacency table the
moves come from, so the board and the rules cannot disagree.

130 unit tests across the four engines, all run locally as well as in
CI: game/ has no Android in it, which is what makes that possible.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Pr6B8xDDtJJcb6WJMw7Ud
This commit is contained in:
Claude
2026-08-07 07:58:12 +00:00
parent 23286090f1
commit 284f9f3f95
29 changed files with 6299 additions and 20 deletions
+79
View File
@@ -0,0 +1,79 @@
# Mastermind
A hidden code of coloured pegs, and a fixed number of guesses to break it.
## Played as a duel
The pencil-and-paper game is one person setting a code and another breaking it,
which makes a poor two-handed game: one player would sit and watch.
Here **both players are set a code and both are breaking one**, a guess each in
turn. Whoever cracks theirs first wins.
That symmetry is why the game ends at the foot of a round rather than the moment
somebody gets it. If the player who went first breaks the code on their sixth
guess, the player who replied still gets a sixth guess of their own — and
equalling it is a draw. Ending it any earlier would make going first worth half
a guess.
## The answer
Each guess is answered with pegs:
- a **dark** peg for a colour in the right place;
- a **light** peg for a colour that is in the code but somewhere else.
**A colour is never counted twice.** Three reds guessed against a code with one
red is worth exactly one peg, however they are arranged. The pegs say how many,
never which, and they are deliberately not lined up under the code they answer —
a tidy row would invite reading a position into them that is not there.
## Options
| | |
| --- | --- |
| **Colours** | 6 or 8 |
| **Pegs** | 3, 4 or 5 |
| **Guesses each** | 8, 10 or 12 |
| **Repeated colours** | on by default; off makes every peg a different colour |
| **Opponent** | Casual, Club or Strong |
The setup screen shows how many codes are possible, which is the honest measure
of how hard a game will be: 1,296 for the standard four pegs and six colours,
32,768 for five pegs and eight.
## Ending
- One player breaks it and the other does not — that player wins.
- Both break it in the same round — a draw.
- Neither breaks it before the guesses run out — a draw.
## Keeping the codes secret
This is the only game here with anything to hide, and it is the only one whose
`viewFor` does real work. The host holds both codes and sends each device **only
its own**: the code you are trying to break is never on your device in the first
place, so there is nothing to find by digging through what arrived over the
network.
A guess is scored by the host, which is the only machine that can score it. A
device asked to score a guess against a code it was never given refuses rather
than quietly answering "nothing" — tested, because that failure would look like
a very hard code rather than like a bug.
Both codes are revealed when the game ends. There is nothing left to protect,
and a code breaker wants to see what they were up against.
## What the computer does
There is no tree to search — a guess cannot be answered badly, and the opponent
makes no reply — so the whole game is in choosing what to try next.
- **Casual** guesses anything it has not tried, ruled out or not.
- **Club** never guesses a code the answers have already eliminated. That one
rule is most of the strength, and it cracks a standard code in about five.
- **Strong** is Knuth's idea one ply deep: among the codes still standing, it
plays the one whose *worst* possible answer leaves the fewest candidates
behind, so it cannot be handed a reply that tells it little. Both lists are
sampled when they are large — the full calculation on a fresh game is over a
million scorings for a choice a sample makes just as well.