v0.7.3 — a game that asks before it ends, and a results screen worth reading
Two issues off the tracker, and they are halves of one thing: the end of a game. Neither ships on the 0.4.9 line — Jesse's call, that line may be complete and these are not fixes people mid-playtest need. EXTENDED PLAY (#11). The official result is settled at the original game length and never changes: in a five-Day game extended to eight, the winner is whoever led at the end of Day 5. Extending grants exactly one Day and the question is put again at the end of it — solitaire the player decides alone, multiplayer it is unanimous and one refusal ends it there. Only days-based endings offer it; a §3.4 collision breach is final, during an extended Day exactly as during the scheduled game. It could not be a client-side change. `check` refused every intent once `status` left `active`; the server never loads a `finished` game back into memory; and a save is `{ seed, config, history }` replayed through the engine, so a "continue" the history does not record did not happen. Hence a fourth status, `awaitingExtension`, and a `game.extend` intent. `config.days` never moves — `extraDays` counts the borrowed Days and `official` freezes the outcome, the standings and the statistics at the first ending. THE RESULTS SCREEN (#16). `GAME OVER — revenueFloor` was `outcome.reason`, an internal enum interpolated into the page at the one moment the game has the player's whole attention. Every reason now has a sentence with the game's own numbers in it. Around it: the result and winner, standings, the rules the game was dealt under, a per-player breakdown, and the railroad — trains through the Division and how many worked en route, loads made up and broken, passengers, cars switched, trains destroyed. It shares the Day-end dialog's blocks rather than reimplementing them, and stays reopenable so continuing does not cost you the results. Statistics are folded, not recorded: `state.tally` counts what the event stream says happened, hooked at `applyIntent` and `advance` because `reduce` never sees the phase driver's events — and those are the interesting ones. Nothing in the rules reads it, and it rides the Frame, so multiplayer gets the same numbers as solitaire from one implementation. THREE BUGS FOUND IN TESTING, all of which would have shipped: - a saved game containing a vote could not be resumed (NO_ACTOR). A history is a flat Intent[] with no seat recorded; the replay derives who acted from the turn order, which cannot work for an intent every seat may send in any order. `game.extend` carries its voter, checked against the authenticated seat. - an all-bot game hung on the question for ever. `driveBots` loops on `currentActor`, null the moment the game stops, so it cannot cast a vote, and the bot-vote driver returned early with no humans to follow. - the balance harness became unbounded — `test/sim.test.ts` went from under a second to never finishing. `randomBot` took another Day about half the time, so every seeded game ran to playGame's 50,000-turn cap. Fixed in the driver, not in a policy, so it holds for bots not yet written. All three have regression tests. 832 tests pass, against 793 before this change. NOT BUILT, and a correction. #16's own comment said `trainStoodStill` "is emitted per Stage, so a run of them is exactly the sat-on-a-siding streak". It is not: reading advance.ts, it fires once per game and only for a train whose profile sets `stopEarnsPoint` — the X18 Circus — with `stopPointClaimed` preventing a second. The streak was built, rendered "1 Stage at (0,0)", and was taken out again. There is no per-Stage "this train did not move" signal in the engine, so "longest an engine sat on a siding" needs one first; TODO.md #36 records what it would take, and the Circus set-up is reported instead. Badges remain the second pass #16 asks for (TODO.md #33), and because the statistics are derived rather than recorded, that pass can add any of them retroactively to games already played and saved. Extended play has not yet been played at a real table (TODO.md #35): the multiplayer vote has only been driven through `session.intent`, never through two browsers. Closes #11 Closes #16 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EAgJSmeV8zrMh55Mj85ESb
This commit is contained in:
co-authored by
Claude Opus 5
parent
510e33bac7
commit
45580d8b61
@@ -52,6 +52,7 @@ import type {
|
||||
TrayId,
|
||||
TurnoutOrientation,
|
||||
} from './state.ts';
|
||||
import { tallyEvent } from './tally.ts';
|
||||
import { createRng } from './rng.ts';
|
||||
import {
|
||||
carsOn,
|
||||
@@ -769,6 +770,23 @@ export function passengerRefusal(
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function check(s: GameState, player: PlayerIndex, i: Intent): RejectionCode | null {
|
||||
/**
|
||||
* §3.3, EXTENDED PLAY (Gitea#11) — asked ABOVE the status guard, because the whole point of the
|
||||
* vote is that it is the one thing the rules will take from a game that has stopped.
|
||||
*
|
||||
* Out of turn like `mainline.clearance` below, and unlike it open to every seat at once: it is a
|
||||
* table decision rather than a ruling, so there is no actor to be.
|
||||
*/
|
||||
if (i.type === 'game.extend') {
|
||||
if (s.status !== 'awaitingExtension') return 'NOT_AWAITING_EXTENSION';
|
||||
// The intent NAMES its voter so that a save can be replayed (`intents.ts`), which makes it a
|
||||
// claim until it is checked against the seat the caller authenticated. One seat may not vote
|
||||
// for another.
|
||||
if (i.player !== player) return 'NOT_YOUR_TURN';
|
||||
if (s.extensionVotes[player] !== null) return 'ALREADY_VOTED';
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s.status !== 'active') return 'WRONG_PHASE';
|
||||
|
||||
// The clearance ruling is the one intent that arrives out of turn order: it interrupts the
|
||||
@@ -1532,6 +1550,27 @@ export function movesFor(
|
||||
|
||||
function execute(s: GameState, player: PlayerIndex, i: Intent): GameEvent[] {
|
||||
switch (i.type) {
|
||||
/**
|
||||
* §3.3, EXTENDED PLAY (Gitea#11) — the vote, and what it settles.
|
||||
*
|
||||
* Decided HERE rather than in `reduce` because the answer depends on the votes as they stand
|
||||
* BEFORE this one lands, and `execute` is the half that still sees that. Three outcomes:
|
||||
*
|
||||
* - a refusal ends it immediately. Unanimity means one "no" is decisive, so nobody is made to
|
||||
* wait on a player who has already said no (Jesse's call, 2026-08-28);
|
||||
* - the last outstanding "yes" grants the Day — ONE Day, and the question is put again at the
|
||||
* end of it;
|
||||
* - anything else is just a vote recorded, and the table waits.
|
||||
*/
|
||||
case 'game.extend': {
|
||||
const vote: GameEvent = { type: 'extensionVoted', player, agree: i.agree };
|
||||
if (!i.agree) return [vote, { type: 'playConcluded', declinedBy: player }];
|
||||
const after = s.extensionVotes.map((v, p) => (p === player ? true : v));
|
||||
return after.every((v) => v === true)
|
||||
? [vote, { type: 'dayExtended', day: s.config.days + s.extraDays + 1 }]
|
||||
: [vote];
|
||||
}
|
||||
|
||||
case 'localOps.choose':
|
||||
return [{ type: 'localOpsOptionChosen', player, option: i.option }];
|
||||
|
||||
@@ -1942,6 +1981,30 @@ function findTimetableSlot(s: GameState, from: number): number | null {
|
||||
|
||||
export function reduce(s: GameState, e: GameEvent): void {
|
||||
switch (e.type) {
|
||||
// -- §3.3, extended play (Gitea#11)
|
||||
case 'extensionVoted':
|
||||
s.extensionVotes[e.player] = e.agree;
|
||||
break;
|
||||
|
||||
/**
|
||||
* One more Day, and the votes are wiped: agreeing once does not agree to the rest of the game.
|
||||
*
|
||||
* `config.days` is deliberately untouched. It is what the OFFICIAL result was decided at
|
||||
* (`state.ts`'s `FinalReport`), so leaving it alone is what makes "the winner is decided at the
|
||||
* original game length" a fact about the code rather than a comment on it. `outcome` is left
|
||||
* alone too — it is the last evaluation, and it is what the results screen shows while the extra
|
||||
* Day is played.
|
||||
*/
|
||||
case 'dayExtended':
|
||||
s.extraDays += 1;
|
||||
s.extensionVotes = s.players.map(() => null);
|
||||
s.status = 'active';
|
||||
break;
|
||||
|
||||
case 'playConcluded':
|
||||
s.status = 'finished';
|
||||
break;
|
||||
|
||||
case 'localOpsOptionChosen':
|
||||
turnOf(s, e.player).option = e.option;
|
||||
break;
|
||||
@@ -3052,6 +3115,9 @@ export function applyIntent(s: GameState, player: PlayerIndex, i: Intent): Apply
|
||||
|
||||
const events = execute(s, player, i);
|
||||
for (const e of events) reduce(s, e);
|
||||
// Gitea#16 — the intent half of the fold; `advance` does the phase driver's half. See `tally.ts`
|
||||
// for why it cannot simply live inside `reduce`.
|
||||
for (const e of events) tallyEvent(s, e);
|
||||
return { ok: true, events };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user