v0.8.2 — every district opens on a Depot, and the docs are pages now

A second-digit bump for a playtest read back against the save file. Nine questions
were asked of one three-Day game; three were bugs, three were the rules working
and undocumented, three were decisions. Every save on the test server was replayed
against this build BEFORE release, which is how the cost of each rule was known
before it was chosen rather than discovered after.

EVERY DISTRICT OPENS ON A DEPOT. A Whistle Post has one A/D track and is not a
Passenger Facility, so the opening of every game was spent unable to work a
passenger and one arrival away from a collision. Two A/D tracks and passengers
from Stage 1 now; "Players start with Whistle Posts, not Depots" is the harder
game, set when the game is created. The deck follows the choice — starting on
Depots the four Depot upgrade cards are left out, because an upgrade must be to
the next tier and a Depot card at a table of Depots is a dead draw. How much
easier it is showed up as a test failure rather than an argument: the cue-coverage
pool needed widening from 24 seeded games to 60 before it held one collision.

NO SAVE WAS STRANDED BY IT, which took care. This is the one house rule that
changes how a game is DEALT rather than how it plays, so replaying a save under
the wrong opening is a different railroad from intent one — silently, with no
error. `withSavedOpening` fills it on the replay paths ONLY. Putting it in the
resolver instead made a fresh Cutthroat game deal Whistle Posts and read as
Custom, which is how the distinction was found.

THREE BUGS, ALL REPORTED FROM ONE GAME AND ALL CONFIRMED ON ITS SAVE.

An Office held TWO TRAINS ON ONE A/D TRACK. The capacity test passed with nothing
standing, the train the Interlocking had been holding at the Limits was moved into
the free slot, and the arriving train was pushed in after it without anyone asking
again whether there was room — so the collision §8.3 calls for never happened. The
held train keeps priority; the newcomer now takes the consequence it would have
met had the held train arrived first.

THE HISTORY FROZE, permanently, and the log cap was not really the cause. Each
seat's "what have I sent you" bookmark was an INDEX into an array the game trims,
so once a seat's bookmark reached the limit the slice returned nothing for the
rest of the game — at a different moment per seat, because each holds its own.
That game's log ended at exactly the cap. Lines carry a sequence number now, which
survives trimming; proven by pushing twice the cap through a simulated seat.

§8.1 ASKED THE WRONG QUESTION TWICE. "Trains may pass" returned `clear` before the
Subdivision was looked at, so a train entering a Double Track was released however
busy the rest of it was — that, not anything about Control Points, is what let
Train 8 out with no ruling. And a train standing at an Office was invisible to the
scan, so one about to re-enter the very Subdivision being entered counted for
nothing. Capacity is the test, not presence: a Depot with a track free is not in
the way; a Whistle Post with its one track taken is.

THINGS THAT HAPPENED SILENTLY NOW SAY SO — a train held against a facing one, a
train released from the Limits (a side effect of somebody else's arrival, so it
simply appeared at the Office), and the train an Interlocking is holding, whose
explanatory tooltip has existed since #99 with NO renderer ever reading the flag.

WHERE A MOVE IS REFUSED, AND WHY. `exploreMoves` decides where the rails go and the
pick-up restrictions are enforced afterwards in `check`, so a square the rails
reached and the card forbade was reachable, un-offered, and absent from the block
list with nothing said. Those squares are blocked with the rule that blocks them
now, and the reasons are got by ASKING `check` rather than re-deriving: a second
implementation of the rules is exactly the failure the block list exists to avoid.
A train may also always recover its own caboose — X13 prints "may drop but not
pick up anything", and a train needs its caboose to be made up, so one that parted
with it could never legally leave again.

RULES DECIDED IN SEPTEMBER AND APPLIED HERE. A Modifier must sit square against its
host, no diagonals. A passenger Modifier may not be played at a Whistle Post. Both
were built, measured, held back for a fortnight so a playtest could finish, and
applied now. A Second Section costs its card: `SECOND_SECTION` was declared in
content.ts and never dealt, so the action was free and the bot ordered 26
accidental ones in a measured round. The card is dealt and spent — gating on a card
the deck never holds would have deleted the mechanic rather than fixed it.

THE DOCUMENTATION IS A SET OF PAGES, not five text files served as text/plain — a
card reference is mostly tables, and as plain text a table is rows of pipes.
Markdown is still the one copy; the build renders it, and publishes the .md beside
each page. No Markdown library: this project has no runtime dependencies and one
would be a poor first. The pages add what Markdown cannot carry without drifting —
a nav across the set, a contents list built from the headings actually rendered,
an anchor on every heading, a 70-character measure, and tables that are tables.
They print as ink on paper.

The references caught up with the rules, checked rather than assumed: two
statements had gone from stale to misleading (the Quickstart told a new player to
"get a Depot down as soon as one appears"), and four rules nobody could look up
are written down — the Office tier table, §8.1 in practice, what the Circus Train
pays for, and that a Realignment can be a card with no legal target.

Adding one card to the deck reshuffles every seeded deal, which broke five
fixtures. Each was a seed meaning "a game like this" — TODO #84, exactly — so
seeds moved and pools widened rather than assertions weakening, and the clearance
fixture pins its terrain the way `enhancements.test.ts` already does. The three
published replays were re-recorded.

Closes TODO #40, #42a, #108, #109 and #110.

1046 fast tests and 35 sim tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUizFYCMHRWhbWwXhp7WPR
This commit is contained in:
Jesse.Markowitz
2026-09-23 07:07:21 -04:00
co-authored by Claude Opus 5
parent 517238a727
commit 3befc420da
66 changed files with 6828 additions and 3324 deletions
+96 -5
View File
@@ -1101,9 +1101,20 @@ function evaluateClearance(
const node = s.division.nodes[targetIndex];
if (!node || node.kind !== 'mainline') return 'clear';
// Double Track and Uncontrolled Siding print "Trains may pass", so occupancy does not block.
/**
* "TRAINS MAY PASS" IS A PROPERTY OF ONE CARD, NOT OF THE SUBDIVISION (Jesse, 2026-09-23).
*
* This returned `clear` outright, before the subdivision was looked at — so a train entering a
* Double Track was released however busy the rest of the Subdivision was, including against a
* train coming the other way three cards deeper in. Reported from a table: Train 8 highballed
* from the Western Division Point with no ruling asked, and the reason was this line rather than
* anything about Control Points.
*
* What the card actually prints is that TWO TRAINS MAY SHARE IT. So it excuses occupants ON THIS
* CARD and nothing else, which is what `passesHere` below is for.
*/
const profile = MAINLINE_PROFILES.find((m) => m.kind === node.card);
if (profile?.trainsMayPass) return 'clear';
const passesHere = profile?.trainsMayPass === true;
/**
* §8.1 asks about the next SUBDIVISION, not the next card.
@@ -1138,9 +1149,32 @@ function evaluateClearance(
const occupants: { tray: TrayId; onCard: number }[] = [];
for (const i of subdivision) {
const n = s.division.nodes[i];
if (!n || n.kind !== 'mainline') continue;
if (behind(i)) continue;
for (const t of n.transits) if (t.tray) occupants.push({ tray: t.tray, onCard: i });
if (n?.kind === 'mainline') {
// A card that lets trains pass is not an obstruction on its own account.
if (i === targetIndex && passesHere) continue;
for (const t of n.transits) if (t.tray) occupants.push({ tray: t.tray, onCard: i });
continue;
}
/**
* A TRAIN STANDING AT AN OFFICE WITH NOWHERE TO PUT IT OCCUPIES THE SUBDIVISION TOO.
*
* Jesse's ruling, 2026-09-23, from a table where Train 19 was released from the Eastern
* Division Point towards Train 14 and nobody was asked: at the moment of the decision Train 14
* was not in `transits` at all, it was standing in a district. §8.1 was only ever reading
* trains in transit, so a train about to re-enter the very Subdivision being entered counted
* for nothing.
*
* CAPACITY IS THE TEST, not the mere presence of a train — his reasoning exactly. At a Whistle
* Post, one A/D track and a train on it means there is nowhere for the two to pass and no
* choice to be made. At a Depot or a Terminal with a track still free there is somewhere to go,
* and the train at the Office is not in the way.
*/
if (n?.kind === 'office') {
const area = areaAtSeat(s, n.seat);
if (area.adOccupancy.length < officeProfile(area.tier).adTracks) continue;
for (const held of area.adOccupancy) occupants.push({ tray: held, onCard: i });
}
}
/**
@@ -1167,6 +1201,24 @@ function evaluateClearance(
// facing trains, add +4/+8/+12 to the other train's number". Without a device there is no
// way to pass the order, so the train simply holds.
if (spendDispatchBonus(s, tray, otherTray, events) > 0) continue;
/**
* SAY SO (Jesse, 2026-09-23: "does it make sense to have something listed in history or
* somewhere else when the train is not allowed to pass?").
*
* A facing train is an absolute bar and this returned silently — the train simply did not
* depart, Stage after Stage, with nothing on screen saying why. Only the ABS Signals case
* below announced itself, and it was given a line for exactly this reason.
*
* NAMES WHAT IS IN THE WAY, because the answer to "why is nothing happening" is a specific
* train somewhere specific, not a rule number.
*/
events.push({
type: 'trainHeld',
trainNumber: tray.trainNumber ?? 0,
reason:
`Train ${otherTray.trainNumber ?? '?'} is coming the other way in the same Subdivision — ` +
'§8.1 holds a train against a facing one, and there is no Control Point between them to pass at',
});
return 'blocked';
}
@@ -1495,12 +1547,51 @@ function arriveAtOffice(
return 'moved';
}
// A train held at the Limits takes the first free A/D track before any newcomer.
/**
* A TRAIN HELD AT THE LIMITS TAKES THE FIRST FREE A/D TRACK BEFORE ANY NEWCOMER — and taking it
* FILLS IT, which is what this used to forget.
*
* Reported from a table, 2026-09-23: a Whistle Post with one A/D track held Trains 8 and 19 at
* once. The capacity test above had passed (nothing standing), this block then moved the held
* train in, and the arriving train was pushed in after it without anyone asking again whether
* there was room. So the Office ended up over capacity and the collision §8.3 calls for never
* happened.
*
* The held train has priority — it has been waiting — so the NEWCOMER takes the consequence, and
* it is the same consequence it would have met had the held train got there first: held at its
* own Limits where there is an Interlocking, and a collision where there is not.
*
* IT IS ALSO ANNOUNCED. The release used to be a silent side effect of somebody else's arrival:
* the train simply appeared at the Office, and the report was "wasn't clear what changed and why
* train 8 was suddenly released".
*/
if (area.heldAtLimits.length > 0 && area.heldAtLimits[0] !== id) {
const first = area.heldAtLimits.shift()!;
area.adOccupancy.push(first);
const held = s.trays.get(first);
if (held) held.position = { at: 'grid', seat, coord: area.officeCoord };
events.push({
type: 'trainReleasedFromLimits',
trainNumber: held?.trainNumber ?? 0,
office: officeProfile(area.tier).name,
owner: playerAtSeat(s, seat),
freedBy: tray.trainNumber ?? 0,
});
// The slot it just took is gone. Ask again for the train that is arriving now.
if (area.adOccupancy.length >= capacity) {
if (hasEnhancement('interlocking')) {
area.heldAtLimits.push(id);
events.push({
type: 'trainDiverted',
trainNumber: tray.trainNumber ?? 0,
to: 'the Limits',
reason: 'Interlocking held it clear of a full Office instead of a collision',
});
return 'moved';
}
collide(s, playerAtSeat(s, seat), [id], events, 'no free A/D track', 'the Office');
return 'moved';
}
}
area.heldAtLimits = area.heldAtLimits.filter((t) => t !== id);
+160 -17
View File
@@ -352,6 +352,35 @@ function checkTurnoutUpgrade(existing: TrackCard, proto: TrackCard): RejectionCo
return null;
}
/**
* May this Facility be built ON TOP of the card already on this square?
*
* Reported from a table: a player who has already laid a straight down a stub and then draws the
* industry they wanted has no move — the square had to have been empty when the card came up, so
* building your district in the sensible order (rail first, then what it serves) is punished.
* Turnouts have upgraded a straight since the same complaint was made about branching.
*
* A STRAIGHT ONLY, and the reason is geometry rather than taste. `protoCard` builds every Facility
* as plain east-west track, so replacing a straight is a port-for-port swap: `{e,w}` before and
* `{e,w}` after, and no neighbour can lose a join it was relying on. A curve or a turnout carries
* ports a Facility does not, so building over one COULD sever a join — those stay refused.
*
* The Running Track row is already barred by the caller (§11.2's "not on Running Track"), so this
* only ever sees stub track.
*
* Two things block it, both about the card being in use rather than its shape — the same pair that
* blocks a turnout upgrade: you cannot swap the track out from under a standing car, and an
* Interlocking or Telegraph built on it would have to be lifted with it. The replaced card leaves
* play, as a lifted card does at a table.
*/
function checkFacilityUpgrade(existing: TrackCard): RejectionCode | null {
const g = existing.geometry;
if (g.kind !== 'track' || g.geometry !== 'straight') return 'NOT_UPGRADEABLE_TRACK';
if (existing.standing.length > 0) return 'UPGRADE_OCCUPIED';
if (existing.enhancements.length > 0) return 'UPGRADE_ENHANCED';
return null;
}
/**
* The MEN | AT | WORK pipeline of a Freight Facility.
*
@@ -899,8 +928,22 @@ export function check(s: GameState, player: PlayerIndex, i: Intent): RejectionCo
* those. Handled here, alongside `dropOnly`, rather than as a blanket refusal on the intent:
* the restriction has to bite on the pick-up itself, the same reasoning as the comment above.
*/
if (rules.noSwitching) return 'PICKUP_NOT_ALLOWED';
if (rules.dropOnly) return 'PICKUP_NOT_ALLOWED';
/**
* A TRAIN MAY ALWAYS RECOVER ITS OWN CABOOSE (Jesse's ruling, 2026-09-23).
*
* `ownCutFor` above exempts only what is standing on the square the crew is on, so a
* caboose set out and then moved away from became a fresh pick-up — and X13 prints "may
* drop MTs but not pick up anything". A train needs its caboose at the far end to be made
* up (§8.2), so a dropOnly train that parted with its caboose could never legally leave
* again: it stranded itself, permanently, with nothing on screen saying so.
*
* Narrow on purpose. It is the caboose only, not "your own cars" generally: the caboose is
* the one car whose absence makes the train unable to depart, so recovering it is repairing
* a consist rather than doing fresh work.
*/
const notOwnCaboose = fresh.filter((c) => c.type !== 'caboose');
if (rules.noSwitching && notOwnCaboose.length > 0) return 'PICKUP_NOT_ALLOWED';
if (rules.dropOnly && notOwnCaboose.length > 0) return 'PICKUP_NOT_ALLOWED';
if (rules.pickUpEmptiesOnly && fresh.some(carriesLoad)) return 'EMPTIES_ONLY';
const freight = fresh.filter(isFreight).length;
if (freight > 0 && !freightBudgetLeft(s, player, tray, i.to, freight)) return 'FREIGHT_WORKED_HERE';
@@ -1224,6 +1267,18 @@ export function check(s: GameState, player: PlayerIndex, i: Intent): RejectionCo
// Only on a train that is actually due out this Stage — a second section follows a first.
if (s.timetable[s.clock.stage - 1] !== i.trainNumber) return 'NO_SUCH_TRAY';
if (s.freeTrays.length === 0) return 'NO_SUCH_TRAY';
/**
* Q9 — IT COSTS THE CARD (Jesse's ruling, 2026-09-23).
*
* This was offered free on every train due out. `SECOND_SECTION` has existed in `content.ts`
* the whole time and `setup.ts` never dealt it, so the card that gates the action did not
* exist and the action was unpriced — the bot ordered 26 accidental Second Sections in one
* measured round, every one of them from the New Train fallback taking `options[0]`.
*
* The card is dealt now (`setup.ts`) and spent here, so ordering a Second Section is a
* decision with a cost, and it can be done once per deal.
*/
if (secondSectionCard(s, player) === null) return 'NO_SUCH_CARD';
return null;
}
@@ -1430,6 +1485,13 @@ function checkPlay(
if (isLockedOut(area, card.kind.facility)) return 'FACILITY_LOCKED';
const proto = protoCard(card.kind, variant);
if (!proto) return 'NO_PLACEMENT';
/**
* An occupied square is a build-over, which has its own rule — `canPlaceAt` refuses every
* occupied square except a movable Limits sign, and a sign is not something to build an
* industry on top of.
*/
const under = area.grid.get(coordKey(placement));
if (under) return checkFacilityUpgrade(under);
return canPlaceAt(area, placement, proto) ? null : 'NOT_CONNECTED';
}
case 'modifier': {
@@ -1462,8 +1524,25 @@ function checkPlay(
if (!withinLimits(area, placement)) return 'OUTSIDE_LIMITS';
// One of a kind per Office Area, as with industries (Q4) — no district gets two Ice Houses.
if (hasModifierInArea(area, card.kind.modifier)) return 'FACILITY_LOCKED';
// §9 — a Modifier is not track. It must sit adjacent to a Facility THAT CAN HOST IT (one of
// the nine nearby spots) or it does nothing at all, so anywhere else is not a legal play.
/**
* A PASSENGER MODIFIER NEEDS A PASSENGER FACILITY, and a Whistle Post is not one (§9).
*
* Jesse's ruling, 2026-09-23. A Waiting Area, Restaurant or Hotel may not be built at an
* Office until it is a Depot or better: a Whistle Post allows neither direction, so the extra
* outbound slot is discarded on the spot and only the porter lands. A card that can be played
* to no effect is a trap however well the panel labels it.
*
* It bites far less often than it would have before the same day's other ruling, which opens
* every district on a Depot — this is now the harder game's rule.
*/
if (
modifierProfile(card.kind.modifier).hosts.includes('office') &&
!officeProfile(area.tier).isPassengerFacility
) {
return 'OFFICE_NOT_PASSENGER';
}
// §9 — a Modifier is not track. It must sit square against a Facility THAT CAN HOST IT —
// north, south, east or west — or it does nothing at all.
return adjacentFacilityCoord(area, placement, card.kind.modifier) ? null : 'NOT_CONNECTED';
}
case 'enhancement': {
@@ -1644,6 +1723,45 @@ export function movesFor(
if (!blocked.has(coordKey(b.coord))) blocked.set(coordKey(b.coord), b);
}
/**
* AND THE SQUARES THE WALK ALLOWS BUT THE TRAIN'S OWN CARD DOES NOT.
*
* Asked from a table, 2026-09-23: "where does it show that you can't make a particular move
* because of a rule that's violated… how does a user know what rule is violated and why you can't
* go there?" Nowhere, was the answer. `exploreMoves` decides where the RAILS go, and the pick-up
* restrictions — `noSwitching`, `dropOnly`, empties-only, the per-location freight budget — are
* enforced afterwards in `check`. So a square the walk reached and the card forbids was reachable,
* un-offered, and absent from this list: it simply was not there, with no reason given.
*
* ASKED THROUGH `check` RATHER THAN RE-DERIVED. A second implementation of the pick-up rules is
* exactly the failure this function's own header warns about — a reason that does not match the
* refusal is worse than no reason. `check` is the authority, so the answer comes from asking it.
*/
const WHY: Partial<Record<string, string>> = {
PICKUP_NOT_ALLOWED:
"this train's card forbids picking cars up, and coupling is mandatory — there are cars here it would have to take",
EMPTIES_ONLY: 'this train may only pick up empties, and there is a loaded car here it would have to take',
FREIGHT_WORKED_HERE: 'this train has already worked its freight allowance at this location',
TOO_MANY_CARS: 'the cars here would take the train over four',
};
for (const [key, coord] of [...to.entries()]) {
if (blocked.has(key)) continue;
/**
* BOTH DIRECTIONS BEFORE DECLARING IT BLOCKED. A square can be reachable forwards and
* backwards, and the two do not pick up the same cars — `ownCutFor` depends on which end the
* train pulls out through. If either way is legal the square stays offered.
*/
const codes = [false, true].map((reverse) =>
check(s, player, { type: 'switch.move', trayId, to: coord, reverse }),
);
if (codes.includes(null)) continue;
const why = codes.map((c) => (c === null ? undefined : WHY[c])).find((w) => w !== undefined);
if (!why) continue;
// Not reachable after all, so it must not stay in `to` claiming otherwise.
to.delete(key);
blocked.set(key, { coord, kind: 'cardRule', why });
}
return { to: [...to.values()], blocked: [...blocked.values()] };
}
@@ -2049,7 +2167,15 @@ function execute(s: GameState, player: PlayerIndex, i: Intent): GameEvent[] {
}
case 'newTrain.secondSection':
return [{ type: 'secondSectionOrdered', player, trainNumber: i.trainNumber }];
// `check` has established the card is in hand, so the id resolves.
return [
{
type: 'secondSectionOrdered',
player,
trainNumber: i.trainNumber,
cardId: secondSectionCard(s, player)!,
},
];
case 'mainline.clearance':
return [
@@ -2621,6 +2747,8 @@ export function reduce(s: GameState, e: GameEvent): void {
case 'secondSectionOrdered':
s.pendingSecondSections.push(e.trainNumber);
// The card is spent on the order, like every other card played from hand.
spendCard(s, e.player, e.cardId);
break;
case 'trainScheduled':
@@ -2946,19 +3074,26 @@ function adjacentFacilityCoord(
coord: GridCoord,
modifier?: ModifierKind,
): GridCoord | null {
// A turnout's 45° leg reaches north as readily as south (turn the card 180°), so a district grows
// on both sides of the Running Track and §9's "nine nearby spots" really is nine. The old Q7
// guard here rejected the three above outright.
/**
* NORTH, SOUTH, EAST OR WEST — NOT THE DIAGONALS (Jesse's ruling, 2026-09-23).
*
* This offered all eight surrounding squares, reading §9's "nine nearby spots" as every
* neighbour. A Modifier has to sit SQUARE against what it serves: a card on a corner touches it
* at a point, not along an edge.
*/
const hosts = modifier ? modifierProfile(modifier).hosts : null;
for (let dr = -1; dr <= 1; dr++) {
for (let dc = -1; dc <= 1; dc++) {
if (dr === 0 && dc === 0) continue;
const c = { row: coord.row + dr, col: coord.col + dc };
const f = area.grid.get(coordKey(c))?.facility;
if (!f) continue;
if (hosts && !hosts.includes(f.subtype)) continue;
return c;
}
const ORTHOGONAL = [
{ dr: -1, dc: 0 },
{ dr: 1, dc: 0 },
{ dr: 0, dc: -1 },
{ dr: 0, dc: 1 },
];
for (const { dr, dc } of ORTHOGONAL) {
const c = { row: coord.row + dr, col: coord.col + dc };
const f = area.grid.get(coordKey(c))?.facility;
if (!f) continue;
if (hosts && !hosts.includes(f.subtype)) continue;
return c;
}
return null;
}
@@ -3075,6 +3210,14 @@ function emptyCard(): TrackCard {
}
/** Removes a played card from its owner's hand and sends it to the Salvage Yard. */
/** The Second Section card in this player's hand, or null. Q9 — the action costs it. */
function secondSectionCard(s: GameState, player: PlayerIndex): CardId | null {
for (const id of s.decks.hands.get(player) ?? []) {
if (s.cards.get(id)?.kind.kind === 'secondSection') return id;
}
return null;
}
function spendCard(s: GameState, player: PlayerIndex, cardId: CardId): void {
s.decks.hands.set(player, (s.decks.hands.get(player) ?? []).filter((c) => c !== cardId));
s.decks.salvageYard.push(cardId);
+48 -1
View File
@@ -481,7 +481,7 @@ export const TIMETABLED_TRAINS: readonly TrainProfile[] = [
* COACH COUNTS ON 1/2 AND 5/6 WERE SWAPPED BY JESSE (Gitea#7, v0.4.9e playtest): the Crack Limited
* drops from three coaches to two, and The Sparrow rises from two to three. A change to the card
* faces themselves, not a transcription fix — `Trains3.pdf` and the tables that transcribe it
* still print the old numbers, so `docs/rules/as-built.md` is the place that now carries what
* still print the old numbers, so `docs/home-deck.md` and `docs/mainline-deck.md` carry what
* the cards say — GENERATED from the constants below by `scripts/build-card-reference.ts`, with
* `test/card-reference.test.ts` failing if the two disagree. This comment used to name
* `card-reference.md`, which describes the v0.4.5 deck and carries a banner saying not to use its
@@ -1224,6 +1224,8 @@ export type HouseRules = {
startingHand: StartingHand;
revenue: RevenueRules;
extraStart: ExtraStartRule;
/** Which Office every player opens on — see `StartingOffice`. */
startingOffice: StartingOffice;
/**
* §6.2 — MAY A TIMETABLED TRAIN BE THROWN AWAY? (Gitea#9, superseding Gitea#6.)
*
@@ -1244,12 +1246,22 @@ export type HouseRules = {
discardTimetabled: boolean;
};
/**
* Which Office every player starts on.
*
* `depot` is the default: a Depot is a Passenger Facility with two A/D tracks, so passengers work
* from the first Stage and a second train can stand at an Office. `whistlePost` is the harder game
* — one A/D track, no passenger work at all until somebody draws and plays an upgrade.
*/
export type StartingOffice = 'depot' | 'whistlePost';
/** What a caller may name — any subset, down to none — resolved by `houseRules()`. */
export type HouseRuleOverrides = {
startingHand?: StartingHand;
revenue?: Partial<RevenueRules>;
extraStart?: ExtraStartRule;
discardTimetabled?: boolean;
startingOffice?: StartingOffice;
};
/** The dialog's range. Zero is a real setting: it switches an economy off so the others can be read. */
@@ -1267,6 +1279,14 @@ export const DEFAULT_HOUSE_RULES: HouseRules = {
// recently gave rather than the one it replaced. This keeps main and the 0.4.9 playtest line —
// which has no setting and simply allows it — playing the same game.
discardTimetabled: true,
/**
* EVERYBODY STARTS ON A DEPOT (Jesse, 2026-09-23). A Whistle Post has one A/D track and is not a
* Passenger Facility, so the opening of every game was spent unable to work a passenger and
* unable to hold a second train — and a single A/D track is what makes an arriving train a
* collision. Starting on a Depot makes the game markedly easier; `whistlePost` is offered as the
* harder setting for a table that wants it.
*/
startingOffice: 'depot',
};
/**
@@ -1286,6 +1306,8 @@ export const LEGACY_HOUSE_RULES: HouseRules = {
// These games predate Gitea#6 as well as Gitea#9: a train card could simply be discarded. `true`
// is what they were played under, and a replay that discards a Timetabled train needs it.
discardTimetabled: true,
// Every game before 2026-09-23 opened on a Whistle Post.
startingOffice: 'whistlePost',
};
/** A whole, valid rule set from a config that may carry none, some, or out-of-range values. */
@@ -1306,9 +1328,31 @@ export function houseRules(config: { houseRules?: HouseRuleOverrides }): HouseRu
},
extraStart: given.extraStart ?? d.extraStart,
discardTimetabled: given.discardTimetabled ?? d.discardTimetabled,
startingOffice: given.startingOffice ?? d.startingOffice,
};
}
/**
* THE OPENING A SAVE THAT PREDATES THE SETTING WAS DEALT UNDER.
*
* `startingOffice` is unlike every other house rule: the others change how a game PLAYS, and
* getting one wrong stops a replay part-way where it can be seen. This one changes how the game is
* DEALT — a different Office, and a deck with four more cards in it — so a save replayed under the
* wrong opening is a different railroad from intent one, and the failure is silent.
*
* Every game saved before 2026-09-23 opened on a Whistle Post and its `houseRules` cannot say so.
* So a saved config that names house rules but not this one gets what it was played under.
*
* APPLIED ON THE REPLAY PATHS ONLY, never inside `houseRules()`. A preset, the setup form and the
* lobby all build configs that name some rules and not others, and they mean today's default —
* putting this in the resolver made a fresh Cutthroat game deal Whistle Posts and read as Custom.
*/
export function withSavedOpening<T extends { houseRules?: HouseRuleOverrides }>(config: T): T {
const given = config.houseRules;
if (!given || given.startingOffice !== undefined) return config;
return { ...config, houseRules: { ...given, startingOffice: 'whistlePost' } };
}
/** What the dialog calls each option, in the order it offers them. */
export const STARTING_HAND_LABELS: readonly { value: StartingHand; label: string }[] = [
{ value: 'threeRandom', label: 'Three random cards' },
@@ -1403,6 +1447,9 @@ export function deckComposition(): { category: string; count: number }[] {
{ category: 'mainlineModifier', count: sum(MAINLINE_MODIFIER_CARDS) },
{ category: 'maneuver', count: sum(MANEUVER_CARDS) },
{ category: 'action', count: sum(ACTION_CARDS) },
// Q9 — dealt since 2026-09-23. It was declared here and left out of `buildDeck`, which is what
// made `newTrain.secondSection` a free action rather than one that costs a card.
{ category: 'secondSection', count: SECOND_SECTION.copies },
];
}
+16 -1
View File
@@ -126,6 +126,21 @@ export type GameEvent =
* Reduces to nothing, like `switchingEnded` above: it reports a choice the state already holds.
*/
| { type: 'freightAgentIdled'; player: PlayerIndex }
/**
* A train the Interlocking was holding at the Limits has taken the A/D track that just freed.
*
* It happens as a side effect of ANOTHER train arriving and clearing the Office, so without this
* the held train simply appeared at the Office with nothing said — reported from a table as
* "wasn't clear what changed and why train 8 was suddenly released". `freedBy` names the train
* whose arrival did it, because "why now" is the whole question.
*/
| {
type: 'trainReleasedFromLimits';
trainNumber: number;
office: string;
owner: SeatIndex;
freedBy: number;
}
| { type: 'cardDrawn'; player: PlayerIndex; source: 'homeOffice' | 'department'; slot?: number; cardId: CardId }
/**
* §6.2 — the Home Office deck ran out, so the Salvage Yard and all three Department decks were
@@ -185,7 +200,7 @@ export type GameEvent =
*/
| { type: 'enhancementPlaced'; player: PlayerIndex; key: string; at?: GridCoord; node?: number }
| { type: 'extraQueued'; player: PlayerIndex; trainNumber: number }
| { type: 'secondSectionOrdered'; player: PlayerIndex; trainNumber: number }
| { type: 'secondSectionOrdered'; player: PlayerIndex; trainNumber: number; cardId: CardId }
| { type: 'trainMadeUp'; trainNumber: number; isExtra: boolean; at: string; direction: string }
| { type: 'trainHeld'; trainNumber: number; reason: string }
/** A train whose card pays for standing still (X18 Circus) collected on it. */
+5
View File
@@ -313,6 +313,11 @@ export type RejectionCode =
| 'INBOUND_BOX_FULL'
| 'NO_EMPTY_COACH_IN_YARD'
| 'NOT_A_CONTROL_POINT'
/**
* A passenger Modifier — Waiting Area, Restaurant, Hotel — played at an Office that is still a
* Whistle Post. A Whistle Post is not a Passenger Facility (§9), so it has nothing to add to.
*/
| 'OFFICE_NOT_PASSENGER'
| 'NO_EXTRA_PENDING'
/** §7 gives an Extra to the player who played the card; another seat may not place it for them. */
| 'NOT_YOUR_EXTRA'
+13 -2
View File
@@ -313,12 +313,19 @@ function localOpsCandidates(s: GameState, player: PlayerIndex): Intent[] {
*
* Deduplicated because the two lists overlap: `placements` already contains the Limits signs.
*/
/**
* A TURNOUT AND AN INDUSTRY MAY BOTH BUILD OVER TRACK ALREADY DOWN, so both are offered the
* occupied cells as well as the empty ones and `check` decides which it will take. Without this
* the rule exists in the engine and is never once presented — which is how the 18 Enhancement
* cards came to be permanently dead.
*/
const isTurnout = kind?.kind === 'track' && kind.geometry === 'turnout';
const isFacility = kind?.kind === 'freightFacility';
const targets = onMainline
? []
: kind?.kind === 'enhancement'
? attachments
: isTurnout
: isTurnout || isFacility
? dedupe([...placements, ...attachments])
: placements;
// Orientation is chosen on placement, and a printed card turns but never flips, so the widest
@@ -375,7 +382,11 @@ function newTrainCandidates(s: GameState, player: PlayerIndex): Intent[] {
}
const due = s.timetable[s.clock.stage - 1];
if (due !== null && due !== undefined) {
out.push({ type: 'newTrain.secondSection', trainNumber: due });
// Q9 — the order costs the card, so it is only a candidate while the card is in hand.
// `check` is still the authority; this keeps the menu from offering what it will refuse.
if ((s.decks.hands.get(player) ?? []).some((id) => s.cards.get(id)?.kind.kind === 'secondSection')) {
out.push({ type: 'newTrain.secondSection', trainNumber: due });
}
}
/**
* WHERE A PENDING EXTRA MAY START (§7, Jesse's ruling) — every candidate offered, with `check`
+36 -6
View File
@@ -23,11 +23,13 @@ import {
TRACK_CARDS,
ROLLING_STOCK_SUPPLY,
STAGES_PER_DAY,
SECOND_SECTION,
TIMETABLED_TRAINS,
crewTrayCount,
mainlineCardCount,
officeProfile,
} from './content.ts';
import type { StartingOffice } from './content.ts';
import type { Rng } from './rng.ts';
import { createRng } from './rng.ts';
import type {
@@ -53,7 +55,11 @@ export type SetupOptions = {
};
/** Builds the 52-card Home Office deck (§12.1). Unshuffled; caller shuffles with the seeded RNG. */
export function buildDeck(mode: GameConfig['mode'] = 'competitive', pvpCardsAllowed = false): Card[] {
export function buildDeck(
mode: GameConfig['mode'] = 'competitive',
pvpCardsAllowed = false,
startingOffice: StartingOffice = 'whistlePost',
): Card[] {
/**
* THE 22 OPPONENT-DIRECTED CARDS ARE OUT OF EVERY DECK REGARDLESS OF `pvpCardsAllowed`, for now.
*
@@ -81,7 +87,16 @@ export function buildDeck(mode: GameConfig['mode'] = 'competitive', pvpCardsAllo
for (const t of TIMETABLED_TRAINS) push({ kind: 'timetabledTrain', number: t.number });
for (const t of EXTRA_TRAINS) push({ kind: 'extraTrain', number: t.number });
/**
* OFFICE UPGRADES, MINUS THE TIER EVERYBODY ALREADY HAS.
*
* A table that starts on Depots has no use for a Depot card: `check` refuses it, because an
* upgrade must be to the NEXT tier and a Depot is not an upgrade on a Depot. Leaving them in
* would deal four dead cards into a 90-odd card deck — the same dead draw the opponent-directed
* cards are held out for. Station and Terminal are still upgrades and stay.
*/
for (const o of OFFICE_PROFILES) {
if (o.tier === startingOffice) continue;
for (let i = 0; i < o.copiesInDeck; i++) push({ kind: 'office', tier: o.tier });
}
for (const f of FREIGHT_PROFILES) {
@@ -90,6 +105,18 @@ export function buildDeck(mode: GameConfig['mode'] = 'competitive', pvpCardsAllo
for (const m of MODIFIER_PROFILES) {
for (let i = 0; i < m.copies; i++) push({ kind: 'modifier', modifier: m.kind });
}
/**
* Q9 — THE SECOND SECTION CARD, WHICH WAS DECLARED AND NEVER DEALT.
*
* `content.ts` has carried `SECOND_SECTION` (1 copy) all along and `setup.ts` never built it into
* the deck, while `newTrain.secondSection` was offered free on every train due out — so the one
* card that is supposed to gate the action did not exist and the action cost nothing. The bot ran
* 26 accidental Second Sections in one measured round because of it.
*
* Jesse's ruling, 2026-09-23: the action requires the card. Dealing it is the other half — gating
* on a card the deck never holds would delete the mechanic rather than fix it.
*/
for (let i = 0; i < SECOND_SECTION.copies; i++) push({ kind: 'secondSection' });
if (opponentCardsInDeck) {
for (const c of SPACE_USE_CARDS) {
for (let i = 0; i < c.copies; i++) push({ kind: 'spaceUse', key: c.key });
@@ -147,7 +174,7 @@ export function buildRollingStock(): RollingStock[] {
* branch from the opening Stage. The stubs are NOT turnouts: §A.1's directional rule governs
* drawn turnout cards only.
*/
function buildOfficeArea(seat: SeatIndex): OfficeArea {
function buildOfficeArea(seat: SeatIndex, tier: StartingOffice): OfficeArea {
const row = 0;
const officeCoord = { row, col: 0 };
const limitsWest = { row, col: -1 };
@@ -158,7 +185,7 @@ function buildOfficeArea(seat: SeatIndex): OfficeArea {
baseOperationalRail: true,
standing: [],
standingWest: 0,
facility: buildPassengerFacility('whistlePost'),
facility: buildPassengerFacility(tier),
modifiers: [],
enhancements: [],
};
@@ -180,7 +207,7 @@ function buildOfficeArea(seat: SeatIndex): OfficeArea {
return {
seat,
tier: 'whistlePost',
tier,
grid,
officeCoord,
runningRow: row,
@@ -285,6 +312,9 @@ export function createGame(opts: SetupOptions): GameState {
const rng = createRng(seed);
const playerCount = playerNames.length;
// Resolved once, here, because it decides BOTH the Office every area is built on and which office
// cards the deck holds — and the two must not be able to disagree.
const startingOffice = houseRules(config).startingOffice;
const players = playerNames.map((name, index) => ({ index, name, revenue: 0 }));
@@ -292,7 +322,7 @@ export function createGame(opts: SetupOptions): GameState {
// the players occupying them, and starts as the identity mapping, which is what makes the
// seat/player split behaviour-neutral. Employee Rotation would rotate this array and nothing else.
const officeAreas = new Map<SeatIndex, OfficeArea>();
for (let seat = 0; seat < playerCount; seat++) officeAreas.set(seat, buildOfficeArea(seat));
for (let seat = 0; seat < playerCount; seat++) officeAreas.set(seat, buildOfficeArea(seat, startingOffice));
// §4.4 - highest D12 takes the Eastern Division Point; §4.5 - highest begins as Superintendent.
// Both rolls are drawn even in solitaire so the RNG stream stays identical across player counts.
const divisionRolls = players.map(() => rng.d12());
@@ -339,7 +369,7 @@ export function createGame(opts: SetupOptions): GameState {
*/
const rules = houseRules(config);
const deal = OPENING_DEALS[rules.startingHand];
const deck = buildDeck(config.mode, config.pvpCardsAllowed);
const deck = buildDeck(config.mode, config.pvpCardsAllowed, rules.startingOffice);
const cards = new Map<CardId, Card>();
for (const c of deck) cards.set(c.id, c);
+2
View File
@@ -554,6 +554,8 @@ export type CardKind =
| { kind: 'timetabledTrain'; number: number }
| { kind: 'extraTrain'; number: number }
| { kind: 'office'; tier: OfficeTier }
/** Q9 — ordered on a train that is due out; a second, identical train runs right behind it. */
| { kind: 'secondSection' }
| { kind: 'freightFacility'; facility: FreightKind }
| { kind: 'modifier'; modifier: ModifierKind }
/** Handedness is printed on the card: it is the diagonal the 45° leg lies on. */
+13 -1
View File
@@ -389,7 +389,19 @@ export function reachableDestinations(
* and only the obstructions are worth listing in the "why nothing is moving" panel, where every
* turnout in the district would otherwise appear.
*/
export type MoveBlockKind = 'noJoin' | 'occupied' | 'locked' | 'tooManyCars' | 'noStopping';
export type MoveBlockKind =
| 'noJoin'
| 'occupied'
| 'locked'
| 'tooManyCars'
| 'noStopping'
/**
* The rails go there and the TRAIN'S OWN CARD does not allow it — a no-switching or drop-only
* train that would have to couple something, an empties-only train facing a loaded car, or a
* freight allowance already spent at that location. Decided by `check` rather than by the walk,
* so it is added in `movesFor` rather than emitted by `exploreMoves`.
*/
| 'cardRule';
export type MoveBlock = { coord: GridCoord; kind: MoveBlockKind; why: string };
/**