v0.4.7 — the switching game: track order, the cut on your own card, and four rules

Eight play reports and one design that had been written up and not built. The
through-line is switching: what a card can hold, which end of a train a cut comes
off, which way a train meets cars standing on the line, and what the board and the
log say about all of it.

TRACK ORDER FOR STANDING CARS, AND THE CUT ON YOUR OWN CARD

Two reports turned out to be one root cause. `TrackCard.standing` claimed "in track
order (§A.3)" and had no defined orientation at all, while `CrewTray.consist` does
(nose first, relative to facing) — so every transfer between them was a conversion
nothing performed. §A.3 says what it should be: cars occupy the track "in the same
order they originally held, left-to-right". Left-to-right is west-to-east, and that
is now the defined orientation of `standing` and of an industry track through
`carsOn`. It is the board's orientation, not the train's, so it does not change when
a different train touches the card.

  - Setting out is batch-invariant. Four cars at once, four singles and two pairs
    parked three different orders, one of them physically impossible. Successive
    cuts off the same end stack up towards the engine, so the insertion point is the
    train's own place in the row.
  - Approaching a cut from either end now mirrors. `couples` is built nearest-first
    along the direction of travel and reverses onto the nose, so the farthest car met
    ends up nose-most — which is what makes a run-around worth its Move.
  - A train no longer drives through its own cut. The walk began at the neighbour of
    the start square and never read the start card, so a crew could set cars out and
    pull straight away from them. Coupling is mandatory (§A.4) and your own square is
    no exception; the cut counts against the four-car limit. Setting out off the end
    you are not leaving by still works.

`CrewTray.standingWest` records where a train stands among the cars on its card — a
train may set out off both ends on one square, so which side a cut is on is not
recoverable from the array alone.

On the board, the cut is drawn split at the train — west cars left, east cars right,
engine in the gap — and each car's tooltip says whether it stands ahead of or behind
the engine. The history says which end a cut came off, and a move's button separates
"takes your own boxcar back off this card" from cars found standing on the line.

Decided: taking your own cut back on the square you are standing on is UNDOING the
drop. It is exempt from trains 3/4's per-location freight budget, X13's "drop but not
pick up" and X22's "empties only", and it refunds the budget the drop spent.
Otherwise a legal-looking drop becomes silently one-way.

Measured, 200 paired seeds, developer bot: -0.55 revenue (t = -3.63), freight revenue
1.11 -> 0.56. That cost is the bot's, not the rule's — its trains run engine-first,
so at a stub industry it sets a car out between itself and the only way out, and the
correct play is §A.5's facing-point move, which is the cross-turn planning TODO.md
already records as out of reach of any bot. Filtering self-recoupling moves out of its
options took recoupling from 625 of 1,029 set-outs to 101 of 677, and all 101 that
remain are that case. Read the number as a bot measurement, not a balance one.

THE SUPERINTENDENT'S RULING NAMES THE TRAINS IT IS ABOUT

Reported: the Superintendent could not tell which train he was clearing. The heading
asks the question now — "may Train 6 follow Train 4 onto the same Mainline card?" —
and the trains moved to the FRONT of each button, because the button splits its label
at the first em-dash and showed only the head.

AN INDUSTRY TRACK HOLDS FOUR CARS, LIKE EVERY OTHER CARD

Reported at undo 188: "we wanted to drop two cars, but were only allowed to drop one."
An industry track was built as long as its box count, so a one-box industry had room
for one car. Box count is how much WORK an industry can hold, not how much RAIL it
has. Ordinary track was the other exception, unbounded; both are gone and every card
holds four.

THE FREIGHT AGENT MAY STAGE A LOAD BEFORE THE CAR IS THERE

§6.3 asks nothing of the industry track — the empty car belongs to §9.3's Load the
car, which is the Laborer's action. The gate now lives only there, so cargo can wait
on the dock while the car to ship it in is still being switched in. Nothing can jam:
a load in a green box is waiting, not stuck.

THE TRUCK DOCK UNLOADS, AND BRINGS NOBODY

+1 inbound, no Laborer. It printed +1 outbound and +1 Laborer, which made it a
longer-host-list copy of Forklifts. Beside Packing Sheds it now does nothing at all,
and the hand tooltip says so before it is played.

Also in this release, from the days before: Mainline card tooltips computed from the
crossing rule; an Extra starts from the Division Point its number sends it to; a
modifier's suppressed grant comes back when a Whistle Post is upgraded; the Oil
Refinery and the Grocer's Warehouse ship as well as receive, per the card reference;
and the dormant defences name the attack they answer. `.claude/` is now gitignored —
it holds Claude Code's worktrees, i.e. a second checkout of this repository.

570 tests, typecheck clean. The three published replays were re-recorded twice —
legality changed, so bot play changed. Full detail in CHANGELOG.md.
This commit is contained in:
Jesse
2026-08-19 12:12:30 -04:00
parent 08339effba
commit 9f3b92d08e
44 changed files with 9739 additions and 4130 deletions
+48 -7
View File
@@ -146,15 +146,22 @@ describe('the revenue chain works end to end (regression)', () => {
// REGRESSION. Cars dropped at a facility went into the card's `standing` list, while §9.3's
// loading rule looked at `industryTrack`. Across 50 games ZERO cars were ever spotted and
// freight revenue was structurally zero. Win rate went 0% -> ~35% when these were unified.
//
// TWENTY SEEDS, NOT EIGHT. The claim is "structurally zero", and eight games was far too thin a
// sample to stand for it: across the original eight, exactly ONE car was ever left spotted, so
// the test passed on a single coin-flip. It went red on a change that measurably IMPROVED
// spotting — once an industry track stopped being as short as its box count, the bot began
// leaving whole cuts (2-5 cars) instead of single cars, which lands on fewer seeds but delivers
// more cars in total (22 vs 19 over forty games). Widened so it fails for the reason it names.
let spotted = 0;
for (const seed of [1, 2, 3, 4, 5, 6, 7, 8]) {
for (const seed of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) {
const s = createGame({ id: 'g', seed, config: { ...config, length: 'standard' }, playerNames: ['bot'] });
playGame(s, developerBot, pump);
for (const card of s.officeAreas.get(0)!.grid.values()) {
if (card.facility?.kind === 'freight') spotted += card.facility.industryTrack.cars.length;
}
}
assert.ok(spotted > 0, 'no car ever reached an industry track across eight games');
assert.ok(spotted > 0, 'no car ever reached an industry track across twenty games');
});
it('instantiates a real Facility when a freight card is placed', () => {
@@ -315,11 +322,19 @@ describe('end-of-game statistics', () => {
});
it('reports no anomalies — every rule in the engine is reachable', () => {
/**
* 200 GAMES, not 60. This is a reachability canary, and the rarest thing it watches for is Red
* Flags: measured at 200 games it fires in 4 of them, about 2%, so a 60-game sample expects 1.2
* and reports "unreachable" on the luck of the draw — which is the opposite of what a canary is
* for. Coupling is the next rarest at 39 in 200. Both are genuinely reachable; the sample was
* simply too small to say so, and it got smaller in effect when v0.4.7 took seven cards out of
* the deck and moved which seeds reach which districts.
*/
// THE POINT OF THIS MODULE. Every serious bug so far was an unreachable rule: a pipeline with
// no entry point, a facility that could not be worked, a car that could not be spotted. If an
// expected event stops firing, something has become unreachable again.
const report = simulate({
games: 60, length: 'standard', mode: 'solitaire', players: ['bot'], policy: developerBot,
games: 200, length: 'standard', mode: 'solitaire', players: ['bot'], policy: developerBot,
});
/**
* ONE NAMED EXEMPTION, not a blanket one.
@@ -451,8 +466,22 @@ describe('switching accomplishes something (regression)', () => {
* drift, and it is logged in `TODO.md` with the rest of it rather than quietly absorbed here.
*/
assert.ok(work > 1.2, `only ${work.toFixed(2)} productive acts a game — the crew is doing nothing`);
/**
* RAISED 9 -> 11, and the crew is doing MORE work rather than less.
*
* Measured at 400 games after v0.4.7: 18 Moves and 1.84 productive acts, a ratio of 9.9 — where
* the work figure was 1.48 when the floor above was written. Both halves grew and the numerator
* grew faster, which is traffic rather than aimlessness, and there are two new sources of it:
* Extras now start at the Division Point their NUMBER sends them to, so westbound Extras exist
* at all (measured 32 west / 29 east across 60 deals, against every single one launching
* eastbound from the West Division Point before); and the Grocer's Warehouse ships as well as
* receives, so there is more switching worth doing.
*
* A crew that shuttles for its own sake would show this ratio climbing while `work` stood still.
* Logged in TODO.md with the rest of the bot drift rather than quietly absorbed.
*/
assert.ok(
moves / work < 9,
moves / work < 11,
`${(moves / work).toFixed(1)} Moves per drop or coupling suggests aimless shuttling ` +
`(${moves.toFixed(0)} Moves, ${work.toFixed(2)} productive acts)`,
);
@@ -734,7 +763,7 @@ describe('the bot does not throw away its own freight (regression)', () => {
outboundBox: [], inboundBox: [], capacity: { outbound: 1, inbound: 0 },
// Stranded on WORK with no spotted car to receive it — the definition of a jam.
menAtWork: [null, null, { type: 'hopper', dir: 'out' }],
industryTrack: { length: 2, cars: [] },
industryTrack: { cars: [] },
laborers: 1, porters: 0, usedThisStage: { laborers: 0, porters: 0 },
},
} as never);
@@ -1040,8 +1069,20 @@ describe('the freight figures count both halves (regression)', () => {
// the precondition that makes the comparison mean anything. Three deals is a thin thread to hang
// that on: an unload needs an inbound industry built, reachable, and a loaded car spotted at it,
// and whether the bot manages all three on a given deal is luck, not the thing under test.
// Measured across these twelve: 34 unloads earned, on 12 of 40 deals sampled more widely.
for (const seed of [1000, 8919, 16838, 24757, 32676, 40595, 48514, 56433, 64352, 72271, 80190, 88109]) {
/**
* FORTY DEALS, up from twelve, and the reason is a rules correction rather than flakiness.
*
* The Grocer's Warehouse is a BOTH-direction facility now — `card-reference.md` always said so —
* where the engine had it inbound-only. So the bot can ship from it as well as receive, and it
* often does: deals producing at least one completed unload went from 12 in 40 to 6 in 40, while
* unloads themselves are unharmed (30 completed across the 40 measured after the change).
*
* The subject here is the INSTRUMENT — does `freightUnload` count Revenue earned rather than
* unloads started — and `unloads > 0` is only the precondition that makes the comparison mean
* anything. Widening the sample restores the precondition without weakening the assertion.
*/
for (let i = 0; i < 40; i++) {
const seed = 1000 + i * 7919;
const s = createGame({
id: `fu-${seed}`, seed,
config: { ...config, length: 'standard' },