Add Best Effort, a soft mode, and quiet notifications
A fourth Normal preset, gentler than Change Freeze: calm chaos (so no DDoS and no chaos monkey), quick builds and no market, plus four new rules that only it softens: sea cuts mend on their own clock without cable ships, no conference season, a five-year Ministry of Tubes rescue loan instead of game over, and customers who sour half as fast. The new rules are written into S.rules only when they differ from the classic game, so older networks' rules stay byte for byte what they were. Quiet notifications is a new setting for every mode, on by default in Best Effort: toasts the day itself raises pop up only for trouble and milestones, the rest goes to the NOC log; what a click says still shows. Best Effort badges count as Freeze-dried. The preset picker is four wide, two by two on a phone in portrait.
This commit is contained in:
parent
de4a750cdd
commit
09f205e458
21 changed files with 228 additions and 28 deletions
130
tests/best-effort.test.js
Normal file
130
tests/best-effort.test.js
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
// Best Effort (☕): the gentlest Normal preset. Change Freeze's quiet (rare outages, no DDoS, no chaos monkey, quick
|
||||
// builds, no market) plus no cable ships, no conferences, patient customers, a rescue loan instead of game over and
|
||||
// quiet notifications by default.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = (ev, preset) => ev(`beginGame('Soft Serve','mrs',{mode:'normal',preset:'${preset}'});if(UI.pendGame)ACT.pitchSkip();closeModal();S.cash=1e8;for(const g of GOALS)S.done[g.id]=0`);
|
||||
const J = (ev, code) => JSON.parse(ev(`JSON.stringify(${code})`));
|
||||
|
||||
test('Best Effort is a Normal preset with its own rules, kept through save and load', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, 'soft');
|
||||
assert.equal(ev('rulePreset()'), 'soft');
|
||||
assert.deepEqual(J(ev, "['chaos','lead','market','sea','confs','broke','moods'].map(rule)"), ['calm', 'quick', false, 'timer', false, 'rescue', 'patient']);
|
||||
assert.equal(ev('ddosOff()'), true, 'no DDoS');
|
||||
assert.equal(ev('mkElig()'), false, 'no chaos monkey');
|
||||
ev("S.rules.confs=true;S.rules.sea='ships';const t=JSON.stringify(packSave(S));S=migrate(JSON.parse(t))");
|
||||
assert.deepEqual(J(ev, "[rulePreset(),rule('confs'),rule('sea')]"), ['soft', false, 'timer'], 'an edited save gets its preset back');
|
||||
// Every other preset keeps the classic game's ships, conferences, game over and moods.
|
||||
for (const p of ['freeze', 'oncall', 'bgp']) {
|
||||
start(ev, p);
|
||||
assert.deepEqual(J(ev, "['sea','confs','broke','moods'].map(rule)"), ['ships', true, 'lose', 'normal'], p);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('Best Effort: a subsea cut mends on its own clock, with no cable ship', () => {
|
||||
for (const [p, ships] of [['soft', false], ['freeze', true]]) {
|
||||
const { ev, errors } = load();
|
||||
start(ev, p);
|
||||
ev("ACT.buildPop({city:'bcn'});S.links=[{id:'med',a:'bcn',b:'mrs',kind:'wave',sub:true,tier:0,km:365,cable:'medusa',cut:0,mo:1000}];S.inc=[];S.fleet={};compute();fireFailure('cut')");
|
||||
const i = J(ev, "S.inc.find(i=>i.type==='cut')");
|
||||
assert.ok(i, p);
|
||||
assert.equal(i.ship != null || !!i.seaq, ships, `${p}: a ship sails out only with ships`);
|
||||
assert.equal(Object.keys(J(ev, 'S.fleet')).length > 0, ships, p);
|
||||
if (!ships) {
|
||||
assert.ok(i.until > ev('S.day') && i.until - ev('S.day') <= 17, 'mends in 10 to 17 days, like a cut on land');
|
||||
for (let k = 0; k < 18; k++) ev('dayTick()');
|
||||
assert.equal(ev("S.inc.some(i=>i.type==='cut')"), false, 'and is mended');
|
||||
}
|
||||
assert.deepEqual(errors, [], p);
|
||||
}
|
||||
});
|
||||
|
||||
test('Best Effort: no conference season', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, 'soft');
|
||||
assert.deepEqual(J(ev, 'upcomingConfs(400)'), []);
|
||||
for (let k = 0; k < 400; k++) ev('S.nextFail=S.nextEvent=1e9;dayTick()');
|
||||
assert.equal(ev('!!S.conf||!!(S.stats.confs)'), false);
|
||||
assert.equal(ev('confSection()'), '');
|
||||
assert.equal(ev("S.log.some(e=>/NANOG|APRICOT|PTC/.test(JSON.stringify(e)))"), false, 'no invitations');
|
||||
start(ev, 'freeze');
|
||||
assert.ok(J(ev, 'upcomingConfs(400)').length > 0, 'Change Freeze still has them');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('Best Effort: customers sour half as fast', () => {
|
||||
const drop = {};
|
||||
for (const p of ['soft', 'freeze']) {
|
||||
const { ev, errors } = load();
|
||||
start(ev, p);
|
||||
ev("ACT.launchBB({city:'mrs'});ACT.buyTransit({city:'mrs',net:'cog',tier:1});S.biz=[{id:'b',name:'B',type:'dia',city:'mrs',bw:1,rate:100,mood:80,since:0}];S.day=100;compute()");
|
||||
// Every path down: the customer gets nothing for a day.
|
||||
ev("S.transit.forEach(t=>t.down=S.day+5);S.nextFail=S.nextEvent=1e9;dayTick()");
|
||||
drop[p] = 80 - ev("S.biz[0].mood");
|
||||
assert.deepEqual(errors, [], p);
|
||||
}
|
||||
assert.ok(drop.freeze > 0);
|
||||
assert.ok(Math.abs(drop.soft - drop.freeze / 2) < 1e-9, `half: ${drop.soft} vs ${drop.freeze}`);
|
||||
});
|
||||
|
||||
test('Best Effort: deep in the red, a rescue loan instead of game over', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, 'soft');
|
||||
ev("ACT.launchBB({city:'mrs'});compute();S.cash=-250000;S.nextFail=S.nextEvent=1e9;dayTick()");
|
||||
assert.equal(ev('!!S.lost'), false);
|
||||
assert.ok(ev('S.cash') > 0, 'back in the black');
|
||||
const l = J(ev, "S.loans.find(l=>l.bank==='gov')");
|
||||
assert.ok(l && l.covs.length === 0 && l.term === 60 && l.pay > 0, 'a five-year state loan, no conditions');
|
||||
assert.match(ev("document.getElementById('toasts').textContent"), /Ministry of Tubes stepped in/);
|
||||
start(ev, 'freeze');
|
||||
ev("ACT.launchBB({city:'mrs'});compute();S.cash=-250000;S.nextFail=S.nextEvent=1e9;dayTick()");
|
||||
assert.equal(ev('!!S.lost'), true, 'the other presets still end the game');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('quiet notifications: on by default in Best Effort, a setting everywhere, and the NOC log keeps everything', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const shown = () => ev("document.getElementById('toasts').textContent");
|
||||
ev("localStorage.removeItem('sot-prefs');PREFS={}");
|
||||
start(ev, 'soft');
|
||||
assert.equal(ev('quietOn()'), true);
|
||||
ev("document.getElementById('toasts').innerHTML='';UI.tick=true;toast('Quiet news','good');toast('Bad news','bad');toast('A milestone','goal');UI.tick=false");
|
||||
assert.doesNotMatch(shown(), /Quiet news/, 'good news from the day stays in the log');
|
||||
assert.match(shown(), /Bad news/);
|
||||
assert.match(shown(), /A milestone/);
|
||||
assert.equal(ev("S.log.some(e=>/Quiet news/.test(JSON.stringify(e)))"), true, 'the NOC log has it');
|
||||
ev("toast('You clicked','good')");
|
||||
assert.match(shown(), /You clicked/, 'what a click says still shows');
|
||||
start(ev, 'oncall');
|
||||
assert.equal(ev('quietOn()'), false, 'off elsewhere by default');
|
||||
// The setting, at 360 px.
|
||||
dom.window.innerWidth = 360;
|
||||
ev('UI.setOpen=true;openModal(settingsHtml())');
|
||||
const doc = dom.window.document;
|
||||
assert.match(doc.getElementById('modalCard').textContent, /Quiet notifications/);
|
||||
doc.querySelector('#modalCard [data-act="prefSet"][data-args*="quiet:1"]').click();
|
||||
assert.equal(ev('quietOn()'), true, 'chosen on, on in every mode');
|
||||
start(ev, 'soft');
|
||||
ev("ACT.prefSet({v:'quiet:0'})");
|
||||
assert.equal(ev('quietOn()'), false, 'chosen off, off even in Best Effort');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the title screen offers Best Effort first, and it earns Freeze-dried badges', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document;
|
||||
ev('window.innerWidth=360;showTitle()');
|
||||
const ps = [...doc.querySelectorAll('#modal .preset')].map((b) => b.dataset.preset);
|
||||
assert.deepEqual(ps, ['soft', 'freeze', 'oncall', 'bgp']);
|
||||
doc.querySelector('.preset[data-preset=soft]').click();
|
||||
assert.match(doc.getElementById('presetWhat').textContent, /No SLA, no pager/);
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
|
||||
assert.equal(ev('rulePreset()'), 'soft');
|
||||
assert.match(ev("document.getElementById('hAsn').textContent"), /Best Effort/);
|
||||
assert.equal(ev('badgeVar()'), 'freeze');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -206,33 +206,38 @@ test('N7: presence is real: PoPs are cities, exchange ports only where the netwo
|
|||
// ---------- Modes and rules ----------
|
||||
|
||||
test('M1: On-call is the classic game: the default rules, and what old saves load as', () => {
|
||||
assert.deepEqual(J("(({preset,mods,...r})=>r)(makeRules('oncall'))"), J("(({mods,...r})=>r)(RULE_DEF)"), 'M1: On-call is RULE_DEF');
|
||||
assert.deepEqual(J("(({preset,mods,...r})=>r)(makeRules('oncall'))"), J("(({mods,...r})=>{for(const k of RULE_LATE)delete r[k];return r;})(RULE_DEF)"), 'M1: On-call is RULE_DEF');
|
||||
assert.deepEqual(J("(()=>{const o=S.rules;S.rules=makeRules('oncall');const v=Object.keys(RULE_OK).map(rule);S.rules=o;return v;})()"), J("Object.keys(RULE_OK).map(k=>RULE_DEF[k])"), 'M1: and plays as RULE_DEF');
|
||||
assert.equal(ev("(()=>{const o=S.rules;delete S.rules;const p=rulePreset();S.rules=o;return p;})()"), 'oncall', 'M1: no rules means On-call');
|
||||
// the seeded On-call games are the rest of the suite (tests/game.test.js, tests/rules.test.js); they must stay green
|
||||
});
|
||||
|
||||
test('M2: presets are ordered: Change Freeze never harsher than On-call, BGP at 3 a.m. never gentler', () => {
|
||||
const P = J('PRESETS'), C = J('CHAOS'), lead = { quick: 0, real: 1 };
|
||||
assert.ok(C[P.freeze.chaos].m <= C[P.oncall.chaos].m && C[P.oncall.chaos].m <= C[P.bgp.chaos].m, 'M2: chaos');
|
||||
assert.ok(lead[P.freeze.lead] <= lead[P.oncall.lead] && lead[P.oncall.lead] <= lead[P.bgp.lead], 'M2: lead times');
|
||||
assert.ok(!P.freeze.market || P.oncall.market, 'M2: market');
|
||||
test('M2: presets are ordered: Best Effort never harsher than Change Freeze, Change Freeze never harsher than On-call, BGP at 3 a.m. never gentler', () => {
|
||||
const P = J('PRESETS'), C = J('CHAOS'), D = J('RULE_DEF'), lead = { quick: 0, real: 1 }, v = (p, k) => P[p][k] !== undefined ? P[p][k] : D[k];
|
||||
assert.ok(C[P.soft.chaos].m <= C[P.freeze.chaos].m && C[P.freeze.chaos].m <= C[P.oncall.chaos].m && C[P.oncall.chaos].m <= C[P.bgp.chaos].m, 'M2: chaos');
|
||||
assert.ok(lead[P.soft.lead] <= lead[P.freeze.lead] && lead[P.freeze.lead] <= lead[P.oncall.lead] && lead[P.oncall.lead] <= lead[P.bgp.lead], 'M2: lead times');
|
||||
assert.ok((!P.soft.market || P.freeze.market) && (!P.freeze.market || P.oncall.market), 'M2: market');
|
||||
// The softenings only Best Effort has: every other Normal preset keeps the classic game's.
|
||||
for (const k of ['sea', 'confs', 'broke', 'moods']) for (const p of ['freeze', 'oncall', 'bgp']) assert.equal(v(p, k), D[k], `M2: ${p} keeps ${k}`);
|
||||
assert.deepEqual(['sea', 'confs', 'broke', 'moods'].map((k) => v('soft', k)), ['timer', false, 'rescue', 'patient'], 'M2: Best Effort softens them all');
|
||||
assert.ok(P.bgp.market && P.bgp.money === 'normal' && P.bgp.gates === 'ladder', 'M2: BGP keeps every hardship');
|
||||
// seeded: the same network for a year under each preset
|
||||
const n = {};
|
||||
for (const p of ['freeze', 'oncall', 'bgp']) {
|
||||
for (const p of ['soft', 'freeze', 'oncall', 'bgp']) {
|
||||
const g = load();
|
||||
g.ev(`beginGame('Order','fra',${JSON.stringify({ mode: 'normal', preset: p })});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});__reseed(4242);for(let i=0;i<360;i++)dayTick()`);
|
||||
n[p] = g.ev('S.inc.length+S.stats.survived+(S.stats.incidents||0)');
|
||||
assert.deepEqual(g.errors, []);
|
||||
}
|
||||
assert.ok(n.freeze <= n.oncall && n.oncall <= n.bgp, `M2: incidents in a year: freeze ${n.freeze}, on-call ${n.oncall}, bgp ${n.bgp}`);
|
||||
assert.ok(n.soft <= n.freeze && n.freeze <= n.oncall && n.oncall <= n.bgp, `M2: incidents in a year: soft ${n.soft}, freeze ${n.freeze}, on-call ${n.oncall}, bgp ${n.bgp}`);
|
||||
});
|
||||
|
||||
test('M3: every subsystem that can annoy the player reads a rule', () => {
|
||||
// [function, what it must read]
|
||||
const reads = [['dayPost', 'chaosMul()'], ['fireEvent', "rule('market')"], ['ddosTick', 'ddosOff()'],
|
||||
['soldOut', "rule('market')"], ['hwMul', "rule('market')"], ['leadDays', "rule('lead')"], ['pniLead', 'leadDays'],
|
||||
['dfBuildDays', 'leadDays'], ['dayPre', "rule('clock')"], ['snub', "rule('market')"]];
|
||||
['dfBuildDays', 'leadDays'], ['dayPre', "rule('clock')"], ['snub', "rule('market')"], ['fireFailure', 'shipsOn()'],
|
||||
['upcomingConfs', 'confsOn()'], ['dayPost', "rule('broke')"], ['dayPost', "rule('moods')"], ['toast', 'quietOn()']];
|
||||
fail('M3', reads.filter(([f, r]) => !ev(`typeof ${f}==='function'&&${f}.toString().includes(${JSON.stringify(r)})`)).map(([f, r]) => `${f}() does not read ${r}`), 'gate it on the ruleset (src/game/40-progress/30-rules.js)');
|
||||
// and in play: no chaos and no market means a quiet year
|
||||
const g = load();
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ test('rules survive save and load, and junk is repaired', () => {
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the title screen: four doors, three Normal presets, a chaos picker for Sandbox, at 360 px', () => {
|
||||
test('the title screen: four doors, four Normal presets, a chaos picker for Sandbox, at 360 px', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document;
|
||||
ev('window.innerWidth=360;showTitle()');
|
||||
assert.equal(doc.querySelectorAll('#modal .door').length, 4);
|
||||
assert.equal(doc.querySelectorAll('#modal .preset').length, 3);
|
||||
assert.equal(doc.querySelectorAll('#modal .preset').length, 4);
|
||||
assert.equal(doc.querySelectorAll('#modal .chs').length, 4);
|
||||
assert.equal(doc.getElementById('doorSandbox').hidden, true);
|
||||
assert.ok(doc.querySelector('.preset[data-preset=oncall].on'), 'On-call is the default');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue