Pie in the Sky: incidents in orbit and geopolitical spats
Solar storms (safe mode saves most pies), food fights (debris, launches dearer for a year, Space Roomba fix), rain fade on tropical dishes, backhoes at the dish, astronomers (VisorSat or science customers sulk), the Founder's 3 a.m. posts and the chaos monkey snipping laser links. Nine spats with two answers each on a bottom sheet: landing rights refused, data stays home, spectrum squabble, kill switch, orbital land grab, jamming, launch diplomacy, not over my airspace. All gated by chaos and 90 quiet days (O5), seeded, repaired by sanitize, translated in every language.
This commit is contained in:
parent
112450d158
commit
727541a9d8
20 changed files with 1266 additions and 11 deletions
|
|
@ -555,6 +555,15 @@ test('O5: launches fail only with chaos on, never in the first 90 days after the
|
|||
assert.equal(fly(oncall, 89), 20, 'O5: quiet for 90 days');
|
||||
assert.equal(fly(oncall, 90), 0, 'O5: then chaos can take a launch');
|
||||
assert.equal(fly("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip()", 400), 20, 'O5: chaos none, nothing fails');
|
||||
// orbit incidents and spats: the same gate
|
||||
const g = load();
|
||||
g.ev("beginGame('Pie','fra',{mode:'normal',preset:'oncall',rules:{gates:'open'}});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;ACT.pieFound()");
|
||||
assert.ok(g.ev('!!S.pie.co'), 'a company to annoy');
|
||||
assert.ok(g.ev("['pieIncDay','pieSpatDayAll'].every(f=>window[f].toString().includes('pieChaos()'))&&pieChaos.toString().includes('chaosMul()')&&pieChaos.toString().includes('PIE_QUIET')"), 'O5: incidents and spats read pieChaos()');
|
||||
assert.equal(g.ev('S.day=S.pie.born+89;pieChaos()'), false, 'O5: quiet for 90 days');
|
||||
assert.equal(g.ev('S.day=S.pie.born+90;pieChaos()'), true, 'O5: then they may come');
|
||||
assert.equal(g.ev("S.rules.chaos='none';pieChaos()"), false, 'O5: never without chaos');
|
||||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
test('O7: a fresh Tier 1 cannot afford a full Shortcrust in its first year', () => {
|
||||
|
|
|
|||
188
tests/pie-incidents.test.js
Normal file
188
tests/pie-incidents.test.js
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
// Pie in the Sky incidents (docs/plans/pie-in-the-sky.md, rule O5): seeded, and each incident is forced where luck would decide.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// An On-call network in Frankfurt with a rocket company: open gates (as in sandbox) but real chaos, so incidents can fire.
|
||||
const sky = (ev, preset = 'oncall', o = {}) => {
|
||||
ev(`beginGame('Sky','fra',{mode:'normal',preset:'${preset}',rules:${JSON.stringify(Object.assign({ gates: 'open' }, o))}});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;S.nextFail=1e9;S.nextEvent=1e9;S.monkey&&(S.monkey.next=1e9)`);
|
||||
ev("for(const c of ['sin','jkt','ams','bru'])ACT.buildPop({city:c});ACT.pieFound();ACT.pieFactory();ACT.piePad({city:'sin'});for(const c of ['sin','jkt','ams','bru','fra'])ACT.pieDish({city:c});for(const cc of ['SG','ID','NL','BE','DE'])ACT.pieLic({cc})");
|
||||
ev("pieCohort('short',1200,true);pieCohort('upper',300,false);S.day=S.pie.born+120;compute()");
|
||||
};
|
||||
const close = (ev) => ev('closeModal()');
|
||||
|
||||
test('O5: quiet for 90 days after the unlock, and a quiet ruleset gives a quiet year', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev('S.day=S.pie.born;pieIncDay(S.day)');
|
||||
ev('Math.random=()=>0'); // every roll would fire
|
||||
ev('for(let d=0;d<89;d++){S.day=S.pie.born+d;pieIncDay(S.day);pieSpatDayAll(S.day)}');
|
||||
assert.equal(ev("S.inc.filter(i=>i.type.startsWith('pie')).length+Object.keys(S.pie.spat).length"), 0, 'O5: 90 quiet days');
|
||||
ev('S.day=S.pie.born+90;pieIncDay(S.day)');
|
||||
assert.ok(ev("S.inc.some(i=>i.type.startsWith('pie'))||S.stats.survived>0"), 'then chaos may bite');
|
||||
// chaos none: a whole year of dayTick with the dice always saying yes
|
||||
const q = load();
|
||||
sky(q.ev, 'oncall', { chaos: 'none' });
|
||||
q.ev('__reseed(77);for(let i=0;i<360;i++)dayTick()');
|
||||
assert.equal(q.ev("S.inc.filter(i=>i.type.startsWith('pie')).length+Object.keys(S.pie.spat).length+(S.stats.pieSpat||0)"), 0, 'M3: chaos none, nothing in orbit');
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual(q.errors, []);
|
||||
});
|
||||
|
||||
test('a seeded year in orbit is the same every time, and things do happen', () => {
|
||||
const run = () => {
|
||||
const g = load();
|
||||
sky(g.ev, 'bgp');
|
||||
g.ev('__reseed(4242);for(let i=0;i<360;i++){dayTick();for(const k in S.pie.spat)if(S.pie.spat[k].st===\'ask\')pieSpatChoose(k,1,false)}');
|
||||
assert.deepEqual(g.errors, []);
|
||||
return g.ev("JSON.stringify([S.stats.by,S.stats.pieSpat||0,Object.keys(CRUSTS).map(pieLive)])");
|
||||
};
|
||||
const a = run();
|
||||
assert.equal(a, run(), 'deterministic per seed');
|
||||
assert.match(a, /pie/, 'a year of BGP at 3 a.m. brings something to orbit');
|
||||
});
|
||||
|
||||
test('solar storm: a crust loses 5 to 40% in a week, safe mode saves most of it', () => {
|
||||
const storm = (safe) => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev(`window.__n0={};for(const id in CRUSTS)__n0[id]=pieLive(id);S.pie.safe=${safe};Math.random=()=>0.99;pieIncFire('storm')`);
|
||||
const i = ev("JSON.stringify(S.inc.find(i=>i.type==='piestorm'))");
|
||||
const o = JSON.parse(i), cr = o.ref, n0 = ev(`__n0['${cr}']`);
|
||||
assert.ok(o.f >= 0.05 && o.f <= 0.4, `loss share ${o.f}`);
|
||||
assert.equal(o.until - ev('S.day'), 7, 'a week');
|
||||
assert.ok(ev("S.log.some(e=>/press office/i.test(e.t))"), 'the press office has a line');
|
||||
ev('for(let d=0;d<7;d++){S.day++;pieIncDay(S.day)}');
|
||||
const lost = 1 - ev(`pieLive('${cr}')`) / n0;
|
||||
assert.deepEqual(errors, []);
|
||||
return [lost, o.f];
|
||||
};
|
||||
const [open, f] = storm(false), [safe] = storm(true);
|
||||
assert.ok(Math.abs(open - f) < 0.02, `about ${f} lost without safe mode (${open})`);
|
||||
assert.ok(safe < open / 2, `safe mode saves most (${safe} vs ${open})`);
|
||||
});
|
||||
|
||||
test('food fight: a slice gone, launches dearer for a year, a Space Roomba fixes it', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const before = ev("pieQuote('falcon','short').cost");
|
||||
const n0 = ev("pieLive('short')+pieLive('upper')");
|
||||
ev("Math.random=()=>0;pieIncFire('food')");
|
||||
const i = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='piefood'))"));
|
||||
assert.ok(i, 'debris');
|
||||
assert.equal(i.until - ev('S.day'), 360, 'a year');
|
||||
assert.ok(ev("pieLive('short')+pieLive('upper')") < n0, 'a slice of the crust is gone');
|
||||
ev("UI.pieIns=false;UI.pieLas=false");
|
||||
const q = ev(`pieQuote('falcon','${i.ref}').cost`), q0 = i.ref === 'short' ? before : null;
|
||||
if (q0) assert.ok(q > q0, `launches cost more (${q} > ${q0})`);
|
||||
ev(`ACT.fixInc({id:'${i.id}'})`);
|
||||
assert.equal(ev("S.inc.some(i=>i.type==='piefood')"), false, 'the Roomba cleans it up');
|
||||
if (q0) assert.equal(ev(`pieQuote('falcon','${i.ref}').cost`), q0, 'and prices are back');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('rain fade: a tropical dish runs at 30% for a few days', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const g = (c) => ev(`(pieDishes().find(x=>x.city==='${c}')||{}).g`);
|
||||
const sin = g('sin'), ams = g('ams');
|
||||
ev("Math.random=()=>0;pieIncFire('rain')");
|
||||
const c = ev("S.inc.find(i=>i.type==='pierain').ref");
|
||||
assert.ok(['sin', 'jkt'].includes(c), 'only in the tropics');
|
||||
assert.equal(g(c), Math.round(sin * 0.3 * 1000) / 1000 || sin * 0.3);
|
||||
assert.equal(g('ams'), ams, 'Amsterdam is dry');
|
||||
ev('S.day+=10;dayTick()');
|
||||
assert.equal(g(c), sin, 'the clouds move on');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('backhoe at the dish: its backhaul is down until fixed or healed', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const n = ev('pieDishes().length');
|
||||
ev("Math.random=()=>0;pieIncFire('dig')");
|
||||
const i = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='piedig'))"));
|
||||
assert.equal(ev('pieDishes().length'), n - 1, 'one dish carries nothing');
|
||||
assert.ok(i.cost > 0);
|
||||
ev(`ACT.fixInc({id:'${i.id}'})`);
|
||||
assert.equal(ev('pieDishes().length'), n, 'a rush splice brings it back');
|
||||
ev("pieIncFire('dig')");
|
||||
ev('for(let d=0;d<4;d++)dayTick()');
|
||||
assert.equal(ev('pieDishes().length'), n, 'or it heals by itself');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('astronomers: pay for VisorSat, or science customers sulk', () => {
|
||||
const run = (c) => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("S.biz.push({id:'u1',type:'edu',city:'fra',bw:20,rate:90,mood:80,since:0,name:'Uni'},{id:'d1',type:'dia',city:'fra',bw:1,rate:600,mood:80,since:0,name:'Shop'})");
|
||||
ev("Math.random=()=>0;pieIncFire('astro')");
|
||||
assert.equal(ev("S.pie.spat.astro.st"), 'ask');
|
||||
const cash = ev('S.cash');
|
||||
ev(`ACT.pieSpatOpen({id:'astro'})`);
|
||||
assert.ok(ev("!!document.querySelector('#modal [data-act=pieSpatPick]')"), 'a sheet with the choices');
|
||||
ev(`ACT.pieSpatPick({id:'astro',c:${c}})`);
|
||||
const r = { paid: cash - ev('S.cash'), edu: ev("S.biz.find(b=>b.id==='u1').mood"), dia: ev("S.biz.find(b=>b.id==='d1').mood") };
|
||||
ev('dayTick()');
|
||||
assert.equal(ev('!!S.pie.spat.astro'), false, 'over');
|
||||
close(ev);
|
||||
assert.deepEqual(errors, []);
|
||||
return r;
|
||||
};
|
||||
const pay = run(0), no = run(1);
|
||||
assert.ok(pay.paid > 0 && pay.edu === 80, 'VisorSat costs money and keeps the peace');
|
||||
assert.ok(no.paid <= 0 && no.edu === 60 && no.dia === 80, 'only science customers lose mood');
|
||||
});
|
||||
|
||||
test('the Founder posts at 3 a.m.: a mood dip or a demand spike', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("S.biz.push({id:'d1',type:'dia',city:'fra',bw:1,rate:600,mood:80,since:0,name:'Shop'})");
|
||||
ev("Math.random=()=>0.1;pieIncFire('founder')");
|
||||
assert.equal(ev("S.biz[0].mood"), 75, 'a dip');
|
||||
ev("Math.random=()=>0.9;pieIncFire('founder')");
|
||||
assert.ok(ev('S.ev.viral>S.day'), 'or a spike');
|
||||
assert.equal(ev("S.pie.founder.posts[0].k"), 'pie.fp_3am');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('F4: the chaos monkey snips a laser link while it visits, healed within a week', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
assert.ok(ev("pieLiveLas('short')") > 0);
|
||||
ev("S.monkey={on:1,start:S.day,until:S.day+100,snip:1e9,n:0,hurt:0,c:'fra',next:0};Math.random=()=>0.01");
|
||||
assert.equal(ev('mkOn()'), true);
|
||||
ev('pieIncDay(S.day)');
|
||||
const i = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='pielaser'))"));
|
||||
assert.ok(i, 'snipped');
|
||||
assert.ok(i.until - ev('S.day') <= 7, 'heals within a week');
|
||||
assert.equal(ev(`pieLiveLas('${i.ref}')`), 0, 'no lasers in that crust meanwhile');
|
||||
ev('Math.random=()=>0.99;for(let d=0;d<8;d++)dayTick()');
|
||||
assert.ok(ev(`pieLiveLas('${i.ref}')`) > 0, 'lasers back');
|
||||
// and never outside a monkey visit
|
||||
ev("S.monkey.on=0;S.inc=S.inc.filter(i=>i.type!=='pielaser');Math.random=()=>0.01;pieIncDay(S.day)");
|
||||
assert.equal(ev("S.inc.some(i=>i.type==='pielaser')"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the booster that falls over on the drone ship is the foundation\'s', () => {
|
||||
const { ev } = load();
|
||||
assert.ok(ev("pieFly.toString().includes('fp_booster')"));
|
||||
});
|
||||
|
||||
test('sanitize drops orbit incidents that make no sense, and old saves are untouched', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("Math.random=()=>0;pieIncFire('storm');pieIncFire('dig')");
|
||||
ev("S.inc.push({id:'x1',type:'piestorm',ref:'nope',until:S.day+3,msg:'',cost:0},{id:'x2',type:'pierain',ref:'atlantis',until:S.day+3,msg:'',cost:0},{id:'x3',type:'piestorm',ref:'short',start:-5,until:1e9,f:9,msg:'',cost:0})");
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
|
||||
assert.equal(ev("S.inc.filter(i=>i.type.startsWith('pie')).length"), 3);
|
||||
assert.ok(ev("S.inc.filter(i=>i.type==='piestorm').every(i=>i.f<=0.4&&i.until<=S.day+400)"), 'clamped');
|
||||
// an old save: no pie, no orbit incidents survive
|
||||
ev("const o=JSON.parse(JSON.stringify(S));delete o.pieV;delete o.pie;S=migrate(o)");
|
||||
assert.equal(ev("S.inc.some(i=>i.type.startsWith('pie'))"), false);
|
||||
assert.equal(ev('S.pie'), null);
|
||||
ev('for(let i=0;i<30;i++)dayTick()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
267
tests/pie-spats.test.js
Normal file
267
tests/pie-spats.test.js
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
// Pie in the Sky geopolitical spats (docs/plans/pie-in-the-sky.md): seeded; each spat is started directly, with Math.random
|
||||
// pinned so the country it picks is known.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// On-call with open gates: real chaos, everything buildable. Dishes in Amsterdam (NL), Brussels (BE), Singapore, Frankfurt.
|
||||
const sky = (ev, o = {}) => {
|
||||
ev(`beginGame('Sky','fra',{mode:'normal',preset:'oncall',rules:${JSON.stringify(Object.assign({ gates: 'open' }, o))}});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;S.nextFail=1e9;S.nextEvent=1e9;S.monkey&&(S.monkey.next=1e9)`);
|
||||
ev("for(const c of ['sin','ams','bru'])ACT.buildPop({city:c});ACT.pieFound();ACT.pieFactory();ACT.piePad({city:'sin'});for(const c of ['ams','bru','fra','sin'])ACT.pieDish({city:c});for(const cc of ['NL','BE','DE','SG'])ACT.pieLic({cc})");
|
||||
ev("pieCohort('short',1200,true);S.day=S.pie.born+120;compute();S.pie.stock=400");
|
||||
};
|
||||
// Start spat id against country cc (the candidate list is pinned to it).
|
||||
const start = (ev, id, cc) => ev(`{const D=PIE_SPAT_DEF['${id}'],c=D.can;${cc ? `D.can=()=>c().includes('${cc}')?['${cc}']:[];` : ''}const r=pieSpatStart('${id}');D.can=c;r}`);
|
||||
const sp = (ev, id) => JSON.parse(ev(`JSON.stringify(S.pie.spat['${id}']||null)`));
|
||||
const lic = (ev, cc) => ev(`pieLicOk('${cc}')`);
|
||||
const days = (ev, n) => ev(`for(let i=0;i<${n};i++)dayTick()`);
|
||||
|
||||
test('every spat asks with two answers on a phone-sized sheet, and the NOC lists it', () => {
|
||||
const { dom, ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("window.innerWidth=360;ACT.buildPop({city:'lon'})");
|
||||
for (const [id, cc] of [['air', 'NL'], ['astro'], ['band', 'NL'], ['grab'], ['home', 'GB'], ['jam', 'NL'], ['kill', 'DE'], ['lic', 'SG'], ['pad']]) {
|
||||
ev('S.pie.spat={};S.pie.lic={};for(const cc of [\'NL\',\'BE\',\'DE\',\'SG\'])S.pie.lic[cc]={state:\'ok\',until:S.day+360}');
|
||||
assert.equal(start(ev, id, cc), true, `${id} starts`);
|
||||
assert.ok(ev("S.log[0].t.length>10"), `${id} is announced`);
|
||||
ev(`ACT.pieSpatOpen({id:'${id}'})`);
|
||||
const b = dom.window.document.querySelectorAll('#modal [data-act=pieSpatPick]');
|
||||
assert.equal(b.length, 2, `${id}: two choices`);
|
||||
assert.ok(/press office/i.test(dom.window.document.querySelector('#modal').textContent), `${id}: a press office line`);
|
||||
assert.doesNotMatch(dom.window.document.querySelector('#modal').textContent, /pie_spat\.|undefined|NaN/, `${id}: no raw labels`);
|
||||
ev("UI.started=true;UI.left='noc';UI.leftOpen=true;renderLeft()");
|
||||
assert.ok(ev(`!!document.querySelector('[data-act=pieSpatOpen][data-args*="${id}"]')`), `${id}: on the NOC card`);
|
||||
}
|
||||
ev('closeModal()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('landing rights refused, then given back with the days you had', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const left = ev("S.pie.lic.SG.until-S.day");
|
||||
start(ev, 'lic', 'SG');
|
||||
ev("ACT.pieSpatPick({id:'lic',c:1})");
|
||||
assert.equal(ev("S.pie.lic.SG.state"), 'refused', "a 'refused' state");
|
||||
assert.equal(lic(ev, 'SG'), false);
|
||||
assert.equal(ev("pieDishes().some(x=>x.cc==='SG')"), false, 'the dish there carries nothing');
|
||||
ev("ACT.pieLic({cc:'SG'})");
|
||||
assert.equal(lic(ev, 'SG'), false, 'cannot buy your way past it');
|
||||
const until = sp(ev, 'lic').until, n = until - ev('S.day');
|
||||
assert.ok(n >= 90 && n <= 180, `refused 90 to 180 days (${n})`);
|
||||
days(ev, n + 1);
|
||||
assert.equal(lic(ev, 'SG'), true, 'back');
|
||||
assert.equal(ev("S.pie.lic.SG.until-S.day"), left - 1, 'with the days you had left');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the lobbyist shortens a refusal to 30 days', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
start(ev, 'lic', 'SG');
|
||||
const cash = ev('S.cash');
|
||||
ev("ACT.pieSpatPick({id:'lic',c:0})");
|
||||
assert.ok(ev('S.cash') < cash);
|
||||
assert.equal(sp(ev, 'lic').until - ev('S.day'), 30);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('spectrum squabble: neighbours, pick a side, the other suspends for 180 days', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
start(ev, 'band', 'NL');
|
||||
const o = sp(ev, 'band');
|
||||
assert.equal(o.cc, 'NL');
|
||||
assert.equal(o.cc2, 'BE', 'the neighbour comes from the city table');
|
||||
ev("ACT.pieSpatPick({id:'band',c:0})");
|
||||
assert.equal(lic(ev, 'NL'), true, 'the side you took keeps you');
|
||||
assert.equal(ev("S.pie.lic.BE.state"), 'sus', "a 'sus' state");
|
||||
assert.equal(sp(ev, 'band').until - ev('S.day'), 180);
|
||||
days(ev, 181);
|
||||
assert.equal(lic(ev, 'BE'), true, 'forgiven after 180 days');
|
||||
// no answer: both suspend for 90
|
||||
ev('S.pie.spat={}');
|
||||
start(ev, 'band', 'NL');
|
||||
days(ev, 21);
|
||||
assert.equal(lic(ev, 'NL') || lic(ev, 'BE'), false, 'no side: both annoyed');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('kill switch: comply costs mood there, refuse suspends 90 days', () => {
|
||||
const run = (c) => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("S.biz.push({id:'b1',type:'dia',city:'fra',bw:1,rate:600,mood:80,since:0,name:'Shop'},{id:'b2',type:'dia',city:'ams',bw:1,rate:600,mood:80,since:0,name:'Shop2'})");
|
||||
start(ev, 'kill', 'DE');
|
||||
ev(`ACT.pieSpatPick({id:'kill',c:${c}})`);
|
||||
const r = { de: ev("S.biz[0].mood"), nl: ev("S.biz[1].mood"), lic: lic(ev, 'DE'), n: (sp(ev, 'kill') || {}).until - ev('S.day') };
|
||||
assert.deepEqual(errors, []);
|
||||
return r;
|
||||
};
|
||||
const yes = run(0), no = run(1);
|
||||
assert.deepEqual([yes.de, yes.nl, yes.lic], [65, 80, true], 'comply: customers there lose 15');
|
||||
assert.deepEqual([no.de, no.lic, no.n], [80, false, 90], 'refuse: licence suspended 90 days');
|
||||
});
|
||||
|
||||
test('data stays home: a dish in the country settles it, or a fine at the end', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("ACT.buildPop({city:'lon'});S.biz.push({id:'b1',type:'dia',city:'lon',bw:1,rate:600,mood:80,since:0,name:'Shop'})");
|
||||
start(ev, 'home', 'GB');
|
||||
ev("ACT.pieSpatPick({id:'home',c:0})");
|
||||
assert.equal(ev("pieSpatHome('GB')"), true, 'British customers must land in Britain');
|
||||
ev("ACT.pieDish({city:'lon'});S.biz[0].mood=50;PIE_SPAT_DEF.home.day(S.pie.spat.home,S.day)");
|
||||
assert.equal(ev("pieSpatHome('GB')"), false, 'a dish there settles it');
|
||||
assert.equal(ev('S.biz[0].mood'), 55, 'and the customers there are pleased');
|
||||
// and when nobody builds one
|
||||
ev("S.pie.dishes=S.pie.dishes.filter(x=>x.city!=='lon');S.pie.spat={}");
|
||||
start(ev, 'home', 'GB');
|
||||
ev("ACT.pieSpatPick({id:'home',c:0})");
|
||||
const spent = ev('S.cash');
|
||||
days(ev, 91);
|
||||
assert.equal(ev('!!S.pie.spat.home'), false);
|
||||
assert.ok(ev("S.log.some(e=>/a fine of/.test(e.t))"), 'fined');
|
||||
assert.ok(ev('S.cash') < spent - 1e6);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('orbital land grab: the next launches cost more, then prices are back', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const q0 = ev("pieQuote('falcon','short').cost");
|
||||
start(ev, 'grab');
|
||||
ev("ACT.pieSpatPick({id:'grab',c:1})");
|
||||
const q1 = ev("pieQuote('falcon','short').cost");
|
||||
assert.ok(q1 > q0, `dearer (${q1} > ${q0})`);
|
||||
for (let i = 0; i < 5; i++) ev("S.pie.pads[0].next=0;ACT.pieLaunch({rk:'falcon',cr:'short'})");
|
||||
assert.equal(ev('S.pie.spat.grab.left'), 0);
|
||||
ev('dayTick()');
|
||||
assert.equal(ev('!!S.pie.spat.grab'), false, 'over after five launches');
|
||||
ev('S.pie.pads[0].next=0');
|
||||
assert.equal(ev("pieQuote('falcon','short').cost"), q0);
|
||||
// lawyers cut the surcharge
|
||||
start(ev, 'grab');
|
||||
ev("ACT.pieSpatPick({id:'grab',c:0})");
|
||||
assert.ok(ev("pieQuote('falcon','short').cost") < q1);
|
||||
ev('closeModal()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('jamming near a border: dishes there drop for some days, filters help', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const g = (c) => ev(`(pieDishes().find(x=>x.city==='${c}')||{g:0}).g`);
|
||||
const ams = g('ams'), sin = g('sin');
|
||||
start(ev, 'jam', 'NL');
|
||||
const o = sp(ev, 'jam'), n = o.until - ev('S.day');
|
||||
assert.ok(n >= 5 && n <= 10, `some days (${n})`);
|
||||
assert.equal(g('ams'), ams * 0.4);
|
||||
assert.equal(g('bru'), ams * 0.4, 'both sides of the border');
|
||||
assert.equal(g('sin'), sin, 'far away is fine');
|
||||
ev("ACT.pieSpatPick({id:'jam',c:0})");
|
||||
assert.equal(g('ams'), ams * 0.8, 'filters');
|
||||
days(ev, n + 1);
|
||||
assert.equal(g('ams'), ams, 'quiet again');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('launch diplomacy: three dishes there bring a free pad', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("for(const c of ['bom','maa','del'])ACT.buildPop({city:c})");
|
||||
start(ev, 'pad', 'IN');
|
||||
ev("ACT.pieSpatPick({id:'pad',c:0})");
|
||||
const pads = ev('S.pie.pads.length');
|
||||
for (const c of ['bom', 'maa', 'del']) ev(`ACT.pieDish({city:'${c}'})`);
|
||||
ev('dayTick()');
|
||||
assert.equal(ev('S.pie.pads.length'), pads + 1, 'a pad, free');
|
||||
assert.ok(ev("S.pie.pads.some(p=>CITY[p.city].cc==='IN')"));
|
||||
// a broken promise suspends landing rights
|
||||
ev("S.pie.spat={};S.pie.pads=S.pie.pads.filter(p=>CITY[p.city].cc!=='IN');S.pie.dishes=S.pie.dishes.filter(x=>CITY[x.city].cc!=='IN');ACT.pieLic({cc:'IN'})");
|
||||
start(ev, 'pad', 'IN');
|
||||
ev("ACT.pieSpatPick({id:'pad',c:0})");
|
||||
days(ev, 181);
|
||||
assert.equal(ev("S.pie.lic.IN.state"), 'sus');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('not over my airspace: split the network, or both suspend', () => {
|
||||
const run = (c) => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
const ams = ev("pieDishes().find(x=>x.city==='ams').g");
|
||||
start(ev, 'air', 'NL');
|
||||
ev(`ACT.pieSpatPick({id:'air',c:${c}})`);
|
||||
const r = { blk: ev("pieAirBlock('NL','BE')"), g: ev("(pieDishes().find(x=>x.city==='ams')||{g:0}).g") / ams, nl: lic(ev, 'NL'), be: lic(ev, 'BE'), n: sp(ev, 'air').until - ev('S.day') };
|
||||
days(ev, r.n + 1);
|
||||
r.after = lic(ev, 'NL') && lic(ev, 'BE') && !ev("pieAirBlock('NL','BE')");
|
||||
assert.deepEqual(errors, []);
|
||||
return r;
|
||||
};
|
||||
assert.deepEqual(run(0), { blk: true, g: 0.75, nl: true, be: true, n: 120, after: true });
|
||||
assert.deepEqual(run(1), { blk: false, g: 0, nl: false, be: false, n: 60, after: true });
|
||||
});
|
||||
|
||||
test('an unanswered spat decides itself on its deadline, deterministically', () => {
|
||||
const run = () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev, { chaos: 'spicy' });
|
||||
ev('__reseed(99);for(let i=0;i<500;i++)dayTick()');
|
||||
assert.deepEqual(errors, []);
|
||||
return ev("JSON.stringify([S.stats.pieSpat||0,S.pie.lic,Object.keys(S.pie.spat)])");
|
||||
};
|
||||
const a = run();
|
||||
assert.equal(a, run());
|
||||
assert.ok(JSON.parse(a)[0] >= 1, 'spats happen with chaos on');
|
||||
});
|
||||
|
||||
test('quiet: no spat in the first 90 days, nor ever without chaos', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev('Math.random=()=>0;S.day=S.pie.born+10;pieSpatDayAll(S.day)');
|
||||
assert.equal(ev('Object.keys(S.pie.spat).length'), 0, 'O5');
|
||||
ev('S.day=S.pie.born+100;pieSpatDayAll(S.day)');
|
||||
assert.equal(ev('Object.keys(S.pie.spat).length'), 1, 'then they come');
|
||||
const q = load();
|
||||
sky(q.ev, { chaos: 'none' });
|
||||
q.ev('Math.random=()=>0;for(let d=0;d<400;d++){S.day++;pieSpatDayAll(S.day)}');
|
||||
assert.equal(q.ev('Object.keys(S.pie.spat).length'), 0, 'chaos none');
|
||||
// a sandbox (chaos none) neither
|
||||
const s = load();
|
||||
s.ev("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip();ACT.pieFound();Math.random=()=>0;for(let d=0;d<400;d++){S.day++;pieSpatDayAll(S.day);pieIncDay(S.day)}");
|
||||
assert.equal(s.ev('Object.keys(S.pie.spat).length+S.inc.length'), 0, 'sandbox');
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual(q.errors, []);
|
||||
assert.deepEqual(s.errors, []);
|
||||
});
|
||||
|
||||
test('sanitize repairs broken spat state; old saves are unaffected', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
start(ev, 'band', 'NL');
|
||||
ev("S.pie.spat.air={st:'on',cc:'NL',cc2:'NL',until:S.day+5}"); // same country twice
|
||||
ev("S.pie.spat.kill={st:'weird',cc:'XX',until:S.day+5}"); // no such country
|
||||
ev("S.pie.spat.jam={st:'on',cc:'NL',cc2:'BE',until:1e12,ask:-4,c:7,hold:{NL:-1,ZZ:5}}");
|
||||
ev("S.pie.spat.home={st:'ask',cc:'DE',until:S.day+30,ask:S.day+20,evil:'<script>'}");
|
||||
ev("S.pie.spat.nope={st:'on'};S.pie.spat.grab=[1,2]");
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
|
||||
const s = JSON.parse(ev('JSON.stringify(S.pie.spat)'));
|
||||
assert.deepEqual(Object.keys(s).sort(), ['band', 'home', 'jam']);
|
||||
assert.ok(s.jam.until <= ev('S.day') + 720 && s.jam.c === 1 && s.jam.ask >= 0, 'clamped');
|
||||
assert.deepEqual(s.jam.hold, { NL: 0 });
|
||||
assert.equal(s.home.evil, undefined);
|
||||
days(ev, 30);
|
||||
// an old save: no pie at all, and nothing new to answer
|
||||
ev("const o=JSON.parse(JSON.stringify(S));delete o.pieV;delete o.pie;S=migrate(o);for(let i=0;i<30;i++)dayTick()");
|
||||
assert.equal(ev('S.pie'), null);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('answers and countries never name a person; countries come from the city table', () => {
|
||||
const { ev, errors } = load();
|
||||
// every country a spat can pick is on the map
|
||||
const ccs = JSON.parse(ev('JSON.stringify(Object.keys(pieCcAll()))'));
|
||||
assert.ok(ccs.includes('NL') && ccs.includes('BE'));
|
||||
assert.equal(ev("pieNb('NL')"), 'BE');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue