Add the Corporate Ladder pack, and two engine features it needed
Seventeen events across the mailroom: ordinary days, Marlene Hobb and Trevor Pike, a misrouted envelope that can be delivered or kept, and a hard-times branch that fires on negative money and always leaves an ungated way out. Writing real content turned up two things the engine could not express. Per-turn upkeep (`pack.upkeep`): the MVP spec wants recurring income and costs, but effects only run when a player chooses something, and baking wages into every option would be tedious and easy to get wrong. Upkeep entries carry their own conditions, which turned out to be enough for the loan service charge to be a three-step function that escalates with the size of the debt — no multiply operation, no engine change. Upkeep changes are recorded separately from choice changes so the UI can distinguish them. Per-character starting relationships: Trevor starts below the pack default on `likes_you` because he arrived two weeks earlier and has priced that in. Characterisation as data rather than as an opening cutscene. Nobody starts feared, either — `fears_you` defaults to 10, since a midpoint default would mean every new hire arrives already intimidating. The content suite plays 60 seeded runs and asserts every event fires and every option is taken at least once. That caught real dead content: Trevor's favour chain sat behind a gate no plausible player could reach, taking two events and a hard-times escape route with it, and debt could pass 5,500 while the service charge stayed flat, so the failure spiral flattened out instead of tightening. Both fixed in the data — the gate softened and given another route up, the loan capped and its charge tiered. The validator also gained a real fix: it counted an event with a cooldown as a stage's fallback, but a cooldown can exclude it, so a stage could still run dry. 86 tests. Reasoning in docs/DECISIONS.md §11-13, including the seeding trap that makes a correlated chooser look exactly like a content bug. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VMSFHyVPitUoosW5wyEADj
This commit is contained in:
co-authored by
Claude Opus 5
parent
cc59b81155
commit
1d4ac0fdbd
@@ -0,0 +1,136 @@
|
||||
// Tests for the shipped Corporate Ladder pack.
|
||||
//
|
||||
// These are content tests, not engine tests: they assert that the pack is
|
||||
// playable, that none of it is dead, and that its economy behaves. Engine
|
||||
// behaviour is covered against the fixture pack instead, so tuning the game
|
||||
// cannot break the engine suite and vice versa.
|
||||
//
|
||||
// One trap, learned the hard way: the chooser's RNG must be seeded
|
||||
// *differently* from the game's. Both draw one number per turn from the same
|
||||
// generator, so sharing a seed correlates the choice index with the event
|
||||
// draw and silently makes whole option combinations unreachable — which looks
|
||||
// exactly like a content bug.
|
||||
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { corporateLadder as pack } from '../content/corporateladder/index.js';
|
||||
import { validatePack } from '../src/engine/validate.js';
|
||||
import { startGame, currentTurn, takeTurn } from '../src/engine/game.js';
|
||||
import { createRng } from '../src/engine/rng.js';
|
||||
|
||||
/** Play `turns` turns with independently-seeded random choices. */
|
||||
function randomRun(runSeed, turns, visit = () => {}) {
|
||||
const rng = createRng(`chooser-${runSeed}`);
|
||||
let state = startGame(pack, { seed: `run-${runSeed}` });
|
||||
for (let t = 0; t < turns; t++) {
|
||||
const turn = currentTurn(pack, state);
|
||||
const available = turn.options.filter((o) => o.available);
|
||||
assert.ok(available.length > 0, `no available option on event "${turn.event.id}"`);
|
||||
const choice = rng.pick(available).option.id;
|
||||
visit(turn, state, choice);
|
||||
state = takeTurn(pack, state, choice).state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
test('the pack is valid, with no warnings', () => {
|
||||
const result = validatePack(pack);
|
||||
assert.deepEqual(result.errors, []);
|
||||
assert.deepEqual(result.warnings, []);
|
||||
});
|
||||
|
||||
test('no content is dead: every event fires and every option can be taken', () => {
|
||||
const firedEvents = new Set();
|
||||
const takenOptions = new Set();
|
||||
for (let seed = 0; seed < 60; seed++) {
|
||||
randomRun(seed, 200, (turn, _state, choice) => {
|
||||
firedEvents.add(turn.event.id);
|
||||
takenOptions.add(`${turn.event.id}.${choice}`);
|
||||
});
|
||||
}
|
||||
|
||||
const allEvents = pack.events.map((e) => e.id);
|
||||
const allOptions = pack.events.flatMap((e) => e.options.map((o) => `${e.id}.${o.id}`));
|
||||
assert.deepEqual(allEvents.filter((e) => !firedEvents.has(e)), [], 'events that can never fire');
|
||||
assert.deepEqual(allOptions.filter((o) => !takenOptions.has(o)), [], 'options that can never be taken');
|
||||
});
|
||||
|
||||
test('every turn always offers something to do, however badly the run is going', () => {
|
||||
// randomRun asserts this on every turn; 40 long runs is the coverage.
|
||||
for (let seed = 100; seed < 140; seed++) randomRun(seed, 150);
|
||||
});
|
||||
|
||||
test('the economy bleeds, so doing nothing about money eventually bites', () => {
|
||||
const turns = [];
|
||||
for (let seed = 0; seed < 30; seed++) {
|
||||
let firstHardTimes = null;
|
||||
randomRun(seed, 120, (turn, state) => {
|
||||
if (turn.event.id === 'rent_bounced' && firstHardTimes === null) firstHardTimes = state.turn;
|
||||
});
|
||||
assert.ok(firstHardTimes, `run ${seed} never hit hard times in 120 turns`);
|
||||
turns.push(firstHardTimes);
|
||||
}
|
||||
turns.sort((a, b) => a - b);
|
||||
const median = turns[Math.floor(turns.length / 2)];
|
||||
assert.ok(median > 10 && median < 45, `hard times should land mid-run, median was turn ${median}`);
|
||||
});
|
||||
|
||||
test('hard times is survivable without any relationship or skill', () => {
|
||||
const event = pack.events.find((e) => e.id === 'rent_bounced');
|
||||
const ungated = event.options.filter((o) => !o.requires);
|
||||
assert.ok(ungated.length > 0, 'a player with nothing must still have a way out');
|
||||
});
|
||||
|
||||
test('the run recovers from hard times rather than sticking there', () => {
|
||||
let sawNegative = false;
|
||||
let recovered = false;
|
||||
randomRun(7, 200, (_turn, state) => {
|
||||
if (state.money < 0) sawNegative = true;
|
||||
else if (sawNegative) recovered = true;
|
||||
});
|
||||
assert.ok(sawNegative && recovered, 'money should go negative and come back');
|
||||
});
|
||||
|
||||
test('debt cannot spiral without limit: lending stops and the charge escalates', () => {
|
||||
let peakDebt = 0;
|
||||
for (let seed = 0; seed < 40; seed++) {
|
||||
randomRun(seed, 200, (_turn, state) => { peakDebt = Math.max(peakDebt, state.debt); });
|
||||
}
|
||||
// The loan is gated at debt < 2000 and lends 500, so 2500 plus stalled
|
||||
// interest is the ceiling. Well above that means the gate has stopped working.
|
||||
assert.ok(peakDebt <= 3000, `debt reached ${peakDebt}; the borrowing ceiling is not holding`);
|
||||
|
||||
const charges = pack.upkeep.filter((u) => u.label?.startsWith('Loan service charge'));
|
||||
assert.ok(charges.length >= 3, 'the service charge should step up as debt grows');
|
||||
});
|
||||
|
||||
test('a deliberate player can reach relationship-gated content in a reasonable run', () => {
|
||||
// The Trevor chain is the deepest gate in the pack. A player cultivating him
|
||||
// should get there well inside a normal session, not at turn 100.
|
||||
const regard = (o) => (o.option.effects ?? [])
|
||||
.filter((e) => e.path === 'relationships.trevor.likes_you')
|
||||
.reduce((sum, e) => sum + e.value, 0);
|
||||
|
||||
let state = startGame(pack, { seed: 'befriend-trevor' });
|
||||
let reached = null;
|
||||
for (let t = 0; t < 60 && reached === null; t++) {
|
||||
const turn = currentTurn(pack, state);
|
||||
if (turn.event.id === 'trevor_favor') { reached = state.turn; break; }
|
||||
const best = turn.options.filter((o) => o.available).sort((a, b) => regard(b) - regard(a))[0];
|
||||
state = takeTurn(pack, state, best.option.id).state;
|
||||
}
|
||||
assert.ok(reached && reached < 45, `Trevor's chain opened at turn ${reached ?? 'never'}`);
|
||||
});
|
||||
|
||||
test('a played run replays identically from its seed', () => {
|
||||
const a = randomRun(42, 80);
|
||||
const b = randomRun(42, 80);
|
||||
assert.deepEqual(a, b);
|
||||
});
|
||||
|
||||
test('the retrospective has something to read back', () => {
|
||||
const state = randomRun(3, 60);
|
||||
assert.ok(state.notable.length > 0, 'notable moments should accumulate');
|
||||
assert.equal(state.history.length, 60, 'every turn is recorded');
|
||||
assert.ok(state.history.every((h) => Array.isArray(h.upkeep)), 'upkeep is recorded per turn');
|
||||
});
|
||||
Reference in New Issue
Block a user