Pie in the Sky: dips in orbit hurt instead of emptying the sky
A crust carries a share of its traffic from 40% coverage, growing to all of it at 60% (pieCarry/pieCap), instead of nothing until 60%. Pies wear out over the last 30% of their life (pieAlive), deterministic, so a launch month no longer deorbits on one day. Storms take 2-10% and food fights 5-10% of a crust (PIE_HIT), down from up to 40% and 20%. Orbit customers lose at most PIE_PATIENCE happiness a day without service, about a month to cancel.
This commit is contained in:
parent
48d2cedbee
commit
d7d5d21372
21 changed files with 135 additions and 51 deletions
|
|
@ -550,11 +550,17 @@ const orbit = (las = true, n = 'CRUSTS.short.full') => { const g = load();
|
|||
g.sky = (id) => g.ev(`Object.keys(R.ef).some(k=>k.startsWith('pie:')&&R.ef[k].eg['l2:${id}']>0)`);
|
||||
return g; };
|
||||
|
||||
test('O2: a half-baked crust carries nothing; orbit never carries more than the dishes', () => {
|
||||
const g = orbit(true, 'Math.floor(CRUSTS.short.full*0.59)');
|
||||
test('O2: a crust carries nothing under 40% and a growing share up to 60%; orbit never carries more than the dishes', () => {
|
||||
const g = orbit(true, 'Math.floor(CRUSTS.short.full*0.39)');
|
||||
g.c('h', 'lon', 'nyc'); g.c('p', 'pcn', null, 'pizza', 50);
|
||||
assert.equal(g.sky('h'), false, 'O2: a half-baked crust carried a circuit');
|
||||
assert.equal(g.ev('R.pie.sf.p'), 0, 'O2: a half-baked crust served a terminal');
|
||||
assert.equal(g.sky('h'), false, 'O2: a crust under 40% carried a circuit');
|
||||
assert.equal(g.ev('R.pie.sf.p'), 0, 'O2: a crust under 40% served a terminal');
|
||||
// from 40% to 60% the share it carries grows from nothing to all of its pies' capacity: a slope, not a cliff
|
||||
const cap = (p) => g.ev(`S.pie.crusts.short.cohorts=[{n:Math.round(CRUSTS.short.full*${p}),day:S.day,las:true}];compute();(R.pie.crust.find(c=>c.id==='short')||{cap:0}).cap`);
|
||||
const caps = [0.4, 0.45, 0.5, 0.55, 0.6, 0.8].map(cap), G = g.ev('CRUSTS.short.g');
|
||||
assert.ok(caps[0] < G * 0.01, `O2: at 40% it carries ${caps[0]} G`);
|
||||
for (let i = 1; i < caps.length; i++) assert.ok(caps[i] > caps[i - 1], `O2: more pies, more traffic (${caps.join(', ')})`);
|
||||
assert.ok(Math.abs(caps[4] - G * 0.6) < G * 0.01 && Math.abs(caps[5] - G * 0.8) < G * 0.01, 'O2: baked from 60%, all of its coverage carries');
|
||||
g.ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:true}];for(let i=0;i<20;i++)S.biz.push({id:'b'+i,type:'boat',city:'pcn',city2:null,bw:800,rate:1,reqs:[],route:'normal',name:'b'+i,mood:100,since:0,sites:null});compute()");
|
||||
for (const d of JSON.parse(g.ev('JSON.stringify(pieDishes())'))) assert.ok(g.ev(`R.pie.used.${d.city}`) <= d.g + 1e-6, `O2: the ${d.city} dish carries ${g.ev(`R.pie.used.${d.city}`)} G on ${d.g} G of antennas`);
|
||||
assert.deepEqual(g.errors, []);
|
||||
|
|
|
|||
|
|
@ -144,12 +144,18 @@ test('O5: launches only fail with chaos on, and never in the first 90 days', ()
|
|||
assert.equal(ev("pieLive('short')"), 20, 'chaos none: nothing fails');
|
||||
});
|
||||
|
||||
test('cohorts decay past their life, and a crust is half-baked under 60%', () => {
|
||||
test('cohorts wear out over the end of their life, and a crust carries a share from 40%, all of it from 60%', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev("S.pie.crusts.short.cohorts.push({n:900,day:S.day,las:false})");
|
||||
ev("S.pie.crusts.short.cohorts.push({n:600,day:S.day,las:false})");
|
||||
assert.equal(ev("pieUp('short')"), false, `${ev("pct(pieCov('short'))")} carries nothing`);
|
||||
ev("S.pie.crusts.short.cohorts[0].n=Math.round(CRUSTS.short.full*0.5)");
|
||||
assert.equal(ev("pieBaked('short')"), false, `${ev("pct(pieCov('short'))")} is half-baked`);
|
||||
assert.equal(ev("pieUp('short')"), true, 'but over 40% it carries something');
|
||||
assert.ok(Math.abs(ev("pieCarry('short')") - 0.5) < 0.01, 'half way from 40% to 60%: half of it');
|
||||
assert.ok(Math.abs(ev("pieCap('short')") - ev('CRUSTS.short.g*0.25')) < ev('CRUSTS.short.g') * 0.01, 'half its capacity at half coverage');
|
||||
ev("S.pie.crusts.short.cohorts[0].n=900");
|
||||
ev("S.pie.crusts.short.cohorts.push({n:60,day:S.day,las:true})");
|
||||
assert.equal(ev("pieBaked('short')&&pieUp('short')"), true, '60% bakes it');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(pieHubs())')), ['short']);
|
||||
|
|
@ -161,7 +167,15 @@ test('cohorts decay past their life, and a crust is half-baked under 60%', () =>
|
|||
assert.equal(g.crusts.find((c) => c.id === 'short').n, 960);
|
||||
assert.equal(g.crusts.find((c) => c.id === 'short').las, 60);
|
||||
assert.equal(g.pads[0].city, 'sin');
|
||||
ev("S.day+=CRUSTS.short.life;pieDay(S.day)");
|
||||
// wear: in full until the last PIE_WEAR of their life, then a few fewer every day, gone at its end
|
||||
const life = ev('CRUSTS.short.life'), w = Math.round(life * ev('PIE_WEAR'));
|
||||
const at = (d) => ev(`S.day=S.pie.crusts.short.cohorts[0].day+${d};pieLive('short')`);
|
||||
assert.equal(at(life - w), 960, 'in full until they start to wear');
|
||||
const mid = at(life - w / 2), late = at(life - 10);
|
||||
assert.ok(Math.abs(mid - 480) <= 1, `half worn out half way (${mid})`);
|
||||
assert.ok(late > 0 && late < mid && late <= 960 * 10 / w + 1, `a few left near the end (${late})`);
|
||||
for (let d = life - w; d < life; d += 7) assert.ok(at(d) - at(d + 7) <= Math.ceil(960 * 7 / w) + 1, `no cliff at day ${d}`);
|
||||
ev("S.day=S.pie.crusts.short.cohorts[0].day+CRUSTS.short.life;pieDay(S.day)");
|
||||
assert.equal(ev("pieLive('short')"), 0, 'old pies deorbit');
|
||||
assert.equal(ev('S.pie.crusts.short.cohorts.length'), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@ test('a seeded year in orbit is the same every time, and things do happen', () =
|
|||
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', () => {
|
||||
test('solar storm: a crust loses 2 to 10% 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.ok(o.f >= 0.02 && o.f <= 0.1, `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)}');
|
||||
|
|
@ -178,7 +178,7 @@ test('sanitize drops orbit incidents that make no sense, and old saves are untou
|
|||
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');
|
||||
assert.ok(ev("S.inc.filter(i=>i.type==='piestorm').every(i=>i.f<=0.1&&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);
|
||||
|
|
@ -186,3 +186,17 @@ test('sanitize drops orbit incidents that make no sense, and old saves are untou
|
|||
ev('for(let i=0;i<30;i++)dayTick()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('no single incident takes more than a tenth of a crust', () => {
|
||||
const { ev, errors } = load();
|
||||
sky(ev);
|
||||
ev("window.__n0={};for(const id in CRUSTS)__n0[id]=pieLive(id);Math.random=()=>0.9999;pieIncFire('food')");
|
||||
const i = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='piefood'))")), n0 = ev(`__n0['${i.ref}']`), after = ev(`pieLive('${i.ref}')`);
|
||||
assert.ok(n0 - after > 0 && (n0 - after) / n0 <= ev('PIE_HIT') + 0.005, `a food fight took ${n0 - after} of ${n0}`);
|
||||
ev("S.inc=[];Math.random=()=>0.9999;pieIncFire('storm')");
|
||||
const s = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='piestorm'))")), m0 = ev(`pieLive('${s.ref}')`);
|
||||
ev('for(let d=0;d<7;d++){S.day++;pieIncDay(S.day)}');
|
||||
const lost = 1 - ev(`pieLive('${s.ref}')`) / m0;
|
||||
assert.ok(s.f <= 0.1 && lost <= 0.1 + 0.005, `the worst storm took ${lost}`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -52,15 +52,23 @@ test('O4: short routes never use orbit, and neither does bulk or plain IP traffi
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('O2: a half-baked crust carries nothing, and orbit never carries more than the dishes hold', () => {
|
||||
test('O2: a crust carries nothing under 40%, a share up to 60%, and orbit never carries more than the dishes hold', () => {
|
||||
const { ev, errors } = load();
|
||||
world(ev, { n: 'Math.floor(CRUSTS.short.full*0.59)' });
|
||||
world(ev, { n: 'Math.floor(CRUSTS.short.full*0.39)' });
|
||||
circuit(ev, 'hft1', 'lon', 'nyc');
|
||||
term(ev, 'pz', 'pcn');
|
||||
assert.deepEqual(ev('JSON.stringify(pieHubs())'), '[]');
|
||||
assert.equal(skyOf(ev, 'hft1'), false);
|
||||
assert.equal(ev("R.pie.sf.pz"), 0, 'a home on Pitcairn gets nothing from a half-baked crust');
|
||||
assert.equal(ev('R.pie.rev'), 0);
|
||||
// half-baked at 50%: a quarter of the crust's Gbps (half its pies, half of those carrying) and a quarter of the market
|
||||
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full/2,day:S.day,las:true}];compute()");
|
||||
assert.deepEqual(ev('JSON.stringify(pieHubs())'), '["short"]', 'over 40% it is a hub');
|
||||
assert.ok(ev('R.pie.sf.pz') > 0.9, 'and serves the home on Pitcairn');
|
||||
const c = JSON.parse(ev("JSON.stringify(R.pie.crust.find(c=>c.id==='short'))"));
|
||||
assert.equal(c.st, 'part');
|
||||
assert.ok(Math.abs(c.cap - ev('CRUSTS.short.g') / 4) < 1, `carries ${c.cap} of ${ev('CRUSTS.short.g')} G at 50%`);
|
||||
assert.ok(Math.abs(ev('pieMarket()') - ev('CRUSTS.short.g*PIE_SELL/4')) < 1, 'the market shrinks with it');
|
||||
// baked: now load it far past the dishes
|
||||
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:true}];for(let i=0;i<20;i++)S.biz.push({id:'big'+i,type:'boat',city:'pcn',city2:null,bw:800,rate:1,reqs:[],route:'normal',name:'b'+i,mood:100,since:0,sites:null});compute()");
|
||||
const dishG = ev('pieDishes().reduce((a,d)=>a+d.g,0)');
|
||||
|
|
@ -171,3 +179,21 @@ test('orbit earnings go into the book, day by day', () => {
|
|||
assert.ok(Math.abs(ev('S.pie.book.earned') - mo) / mo < 0.05, `${ev('S.pie.book.earned')} ≈ ${mo}`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('orbit customers sit out a bad month: at most PIE_PATIENCE happiness a day, then they cancel', () => {
|
||||
const { ev, errors } = load();
|
||||
world(ev);
|
||||
term(ev, 'pz', 'pcn');
|
||||
ev("S.biz.find(b=>b.id==='pz').since=-100");
|
||||
assert.ok(ev('R.pie.sf.pz') > 0.9, 'served');
|
||||
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full*0.3,day:S.day,las:true}];compute()");
|
||||
assert.equal(ev('R.pie.sf.pz'), 0, 'the sky has a gap');
|
||||
ev('for(let i=0;i<10;i++)dayTick()');
|
||||
const m = ev("(S.biz.find(b=>b.id==='pz')||{mood:-1}).mood");
|
||||
assert.ok(m >= 100 - 10 * ev('PIE_PATIENCE') - 1e-9 && m < 100, `ten bad days: grumpy (${m}), not gone`);
|
||||
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:true}];compute();for(let i=0;i<5;i++)dayTick()");
|
||||
assert.ok(ev("S.biz.find(b=>b.id==='pz').mood") > m, 'the sky back: happier again');
|
||||
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full*0.3,day:S.day,las:true}];compute();for(let i=0;i<40;i++)dayTick()");
|
||||
assert.equal(ev("S.biz.some(b=>b.id==='pz')"), false, 'a month and more of nothing: cancelled');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -103,15 +103,19 @@ const checks = (dom) => Object.fromEntries([...doc(dom).querySelectorAll('#modal
|
|||
test('an empty sky says why: a half-baked crust', () => {
|
||||
const { dom, ev, errors } = load();
|
||||
ev('window.innerWidth=360');
|
||||
world(ev, { n: 'Math.floor(CRUSTS.short.full*0.41)' });
|
||||
world(ev, { n: 'Math.floor(CRUSTS.short.full*0.39)' });
|
||||
term(ev, 'pz', 'dub');
|
||||
ev("ACT.pieTab({t:'traffic'})");
|
||||
const txt = doc(dom).querySelector('#modalCard').textContent;
|
||||
assert.match(txt, /Why is my sky empty\?/);
|
||||
assert.equal(checks(dom).baked, 'off');
|
||||
assert.match(txt, /Shortcrust \(550 km\) is 41% baked; it carries traffic from 60%/);
|
||||
assert.match(txt, /Shortcrust \(550 km\) is 39% baked; it carries traffic from 40%/);
|
||||
assert.equal(checks(dom).customers, 'on');
|
||||
ev('closeModal()');
|
||||
try {
|
||||
ev("S.pie.crusts.short.cohorts[0].n=CRUSTS.short.full/2;compute();ACT.pieTab({t:'traffic'})");
|
||||
assert.match(doc(dom).querySelector('#modalCard').textContent, /is 50% baked: half-baked, it carries 50% of its traffic, all of it from 60%/);
|
||||
} finally { ev('closeModal()'); }
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue