Charters: a popup at the start, and a third one, the Cable broker (#300)
A new Normal game now asks what it is building before anything else, in a popup that holds the clock and cannot be closed without an answer; the tutorial waits for it. A save still in its first month that never picked is asked on load. Sandbox, puzzles and scenarios never ask. The Cable broker builds and lights glass from day one at the prices everyone pays at the top level: dark fiber, every line system and optic, digging without the pioneer markup, own subsea cables and their upgrades, eight pairs, and every router those optics need. Everything else unlocks by level as before. Its offers lean to carriers buying waves and pairs, capacity conferences are open to it at any level, and carriers call about three times a year with a capacity deal. It runs its own ten-goal ladder and wins Glass Baron (own cables on five continents, $1M a month of capacity sales), with a badge; Tier 1 stays its own win. Classic and boutique networks may lay their own subsea cable from customer level 9 as well as after Tier 1. Rule M6 (gameplay-rules): a charter changes what you set out to do, never what things cost. Closes #300.
This commit is contained in:
parent
f303f29f22
commit
934a83588a
40 changed files with 535 additions and 97 deletions
180
tests/charters.test.js
Normal file
180
tests/charters.test.js
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
// Charters (#300): a Normal game asks what it is building before anything else, in a popup that waits for an answer:
|
||||
// Global backbone, Low-latency boutique or Cable broker. The broker builds and lights glass from day one at the usual
|
||||
// prices, runs its own goal ladder and wins Glass Baron; everything else unlocks by level as always. Classic networks
|
||||
// may lay their own subsea cable from customer level 9 as well as after the Tier 1 win.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const modal = (ev) => ev("document.getElementById('modal').hidden?'':document.getElementById('modal').className");
|
||||
function picked(k, opts) {
|
||||
const h = load({ seed: 300, ...opts });
|
||||
h.ev(`ACT.start({});ACT.charter({k:'${k}'})`);
|
||||
return h;
|
||||
}
|
||||
// A dark fiber of your own, ready and lit, between two cities with POPs.
|
||||
const df = (id, a, b, more = '') => `(()=>{for(const c of ['${a}','${b}'])S.pops[c]=S.pops[c]||{day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:RG.length-1};
|
||||
S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'roadm',ch:['tp16','tp16'],km:kmBetween('${a}','${b}'),sub:isSub('${a}','${b}'),cable:null,mo:0,trench:'${id}',cut:0,day:0,ready:0,spares:false${more}});})()`;
|
||||
|
||||
test('a new Normal game asks for its charter first, and the popup waits for an answer', () => {
|
||||
const { ev, dom, errors } = load({ seed: 300 });
|
||||
ev('window.__TUBES_CHARTER__=true;ACT.start({})');
|
||||
assert.equal(modal(ev), 'charter', 'the picker is open, and an open window holds the clock');
|
||||
const opts = [...dom.window.document.querySelectorAll('#modalCard .chopt')].map((b) => JSON.parse(b.dataset.args).k);
|
||||
assert.deepEqual(opts, ['global', 'boutique', 'broker']);
|
||||
assert.match(dom.window.document.getElementById('modalCard').textContent, /Glass Baron/, 'each charter says what it is and how it wins');
|
||||
assert.equal(ev('UI.tutLater'), true, 'the tutorial waits for the charter');
|
||||
// Escape, or anything that closes the window, does not get past it.
|
||||
ev("dispatchEvent(new KeyboardEvent('keydown',{key:'Escape'}))");
|
||||
assert.equal(modal(ev), 'charter');
|
||||
ev('closeModal();renderAll()');
|
||||
assert.equal(modal(ev), 'charter', 'closed some other way, it comes straight back');
|
||||
dom.window.document.querySelector('#modalCard [data-args*="broker"]').click();
|
||||
assert.equal(ev('S.charter'), 'broker');
|
||||
assert.equal(ev('S.chartSet'), true);
|
||||
assert.equal(modal(ev), '', 'signed: the window closes and the game runs');
|
||||
assert.equal(ev('UI.tutLater'), false, 'and the tutorial may start');
|
||||
ev("ACT.charter({k:'global'})");
|
||||
assert.equal(ev('S.charter'), 'broker', 'one charter for the life of the network');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('sandbox, scenarios and puzzles never ask; a save still in its first month that never picked does', () => {
|
||||
for (const o of ["{mode:'sandbox'}", '{scn:SCN[0]}']) {
|
||||
const { ev, errors } = load({ seed: 300 });
|
||||
ev(`window.__TUBES_CHARTER__=true;beginGame('X','fra',${o});if(UI.pendGame)ACT.pitchSkip()`);
|
||||
assert.notEqual(modal(ev), 'charter', o);
|
||||
assert.equal(ev('charterDue()'), false, o);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
const { ev, errors } = load({ seed: 300 });
|
||||
ev('ACT.start({})');
|
||||
const s = JSON.parse(ev('JSON.stringify(S)'));
|
||||
ev(`window.__TUBES_CHARTER__=true;S=migrate(${JSON.stringify({ ...s, day: 12, chartSet: false })});closeModal();renderAll()`);
|
||||
assert.equal(modal(ev), 'charter', 'a save in its first month that never picked is asked on load');
|
||||
ev(`S=migrate(${JSON.stringify({ ...s, day: 40, chartSet: false })});closeModal();renderAll()`);
|
||||
assert.equal(modal(ev), '', 'past the first month it is a Global backbone, as before');
|
||||
assert.deepEqual([ev('S.charter'), ev('S.chartSet')], ['global', true]);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the broker has glass and the gear to light it from day one, at the usual prices', () => {
|
||||
const { ev, errors } = picked('broker');
|
||||
assert.equal(ev('lvl()'), 1, 'still customer level 1');
|
||||
assert.equal(ev('glassLvl()'), ev('LEVELS.length'));
|
||||
for (const o of ['zr4', 'zr8', 'tp16', 'tp32']) {
|
||||
assert.equal(ev(`techOk('opt','${o}',OPT.${o}.lvl)`), true, o);
|
||||
assert.equal(ev(`optCost('${o}')`), ev(`Math.round(OPT.${o}.cost*hwMul('opt'))`), `${o} at the catalog price, no demo markup`);
|
||||
}
|
||||
for (const k of ['lite', 'roadm', 'cl']) assert.equal(ev(`sysCost('${k}')`), ev(`DF_SYS.${k}.cost`), k);
|
||||
assert.equal(ev('digMul()'), 1, 'no pioneer markup for digging');
|
||||
assert.equal(ev('cabOpen()'), true, 'own subsea cables');
|
||||
assert.equal(ev('pairsMax({sub:false})'), ev('PAIRS_BIG'));
|
||||
assert.equal(ev('RG.every((r,g)=>r.cls>RG_GLASS||rgOpen(g))'), true, 'every router the optics need');
|
||||
// Dark fiber on the best line system, at level 1.
|
||||
ev("ACT.buildPop({city:'ams'});UI.pending={a:'fra',b:'ams'};UI.dfSrc='lease';UI.dfSys='cl';ACT.orderDf()");
|
||||
assert.equal(ev("S.links.filter(l=>l.kind==='df').map(l=>l.sys).join()"), 'cl');
|
||||
// The rest of the game still unlocks by level.
|
||||
ev('ACT.buyTE()');
|
||||
assert.ok(!ev('S.te'), 'Auto-TE waits for customer level 3');
|
||||
assert.equal(ev("techOk('rg',RG.findIndex(r=>r.cls>RG_GLASS),99)"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the other charters keep their gates; own subsea cables open at level 9 for everyone (#300)', () => {
|
||||
for (const k of ['global', 'boutique']) {
|
||||
const { ev, errors } = picked(k);
|
||||
assert.equal(ev('glassLvl()'), 1);
|
||||
assert.equal(ev("techOk('opt','tp16',OPT.tp16.lvl)"), false, `${k}: optics still follow the level`);
|
||||
assert.equal(ev('digMul()'), ev('PIONEER'));
|
||||
ev("ACT.buildPop({city:'ams'});UI.pending={a:'fra',b:'ams'};UI.dfSrc='lease';UI.dfSys='lite';ACT.orderDf()");
|
||||
assert.equal(ev("S.links.filter(l=>l.kind==='df').length"), 0, `${k}: no dark fiber at level 1`);
|
||||
ev('S.lvl=8');
|
||||
assert.equal(ev('cabOpen()'), false);
|
||||
assert.match(ev("ownCabWhy('lon','nyc')"), /level 9, or Tier 1/);
|
||||
ev('S.lvl=9');
|
||||
assert.equal(ev('cabOpen()'), true, `${k}: level 9 lays its own subsea cable`);
|
||||
ev('S.lvl=1;S.won=true');
|
||||
assert.equal(ev('cabOpen()'), true, `${k}: so does a Tier 1 at any level`);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
|
||||
test('the broker runs its own ladder, every goal can be met, and Glass Baron is its own win', () => {
|
||||
const { ev, dom, errors } = picked('broker');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(goals().map(g=>g.id))')),
|
||||
['bk_df', 'bk_wave', 'bk_pair', 'bk_sea', 'bk_deal', 'bk_10k', 'bk_16t', 'bk_c4', 'bk_10t', 'bk_win']);
|
||||
ev("ACT.leftTab({t:'goals'});renderAll()");
|
||||
assert.match(dom.window.document.getElementById('left').textContent, /0\/10/);
|
||||
assert.match(dom.window.document.getElementById('left').textContent, /Glass Baron/, 'the Glass Baron card');
|
||||
const ok = (id) => ev(`BROKER_GOALS.find(g=>g.id==='${id}').ok()`);
|
||||
for (const id of ['bk_df', 'bk_wave', 'bk_pair', 'bk_sea', 'bk_deal', 'bk_10k', 'bk_16t', 'bk_c4', 'bk_10t', 'bk_win']) assert.equal(ok(id), false, `${id} not met on day 0`);
|
||||
// Glass across Europe, and cables over the oceans onto six continents.
|
||||
ev(df('e1', 'fra', 'ams') + ';' + df('e2', 'ams', 'ham'));
|
||||
for (const [id, a, b] of [['s1', 'lon', 'nyc'], ['s2', 'sin', 'per'], ['s3', 'for', 'lag']]) ev(df(id, a, b));
|
||||
ev('compute()');
|
||||
assert.equal(ok('bk_df'), true);
|
||||
assert.equal(ok('bk_sea'), true);
|
||||
assert.equal(ok('bk_16t'), true, 'fra–ams–ham, 3.2T each');
|
||||
assert.equal(ok('bk_c4'), true);
|
||||
assert.equal(ev('cableConts()'), 6);
|
||||
assert.ok(ok('bk_10k'), `${Math.round(ev('glassKm()'))} km of own glass`);
|
||||
// A seat on a consortium cable, or a leased IRU, is not your own glass.
|
||||
assert.equal(ev("ownGlassL({kind:'df',own:true,seat:true,ready:0})||ownGlassL({kind:'df',own:false,ready:0})"), false);
|
||||
// Carriers buy: a wave, a pair, a delivered subsea deal of 12.8T worth more than $1M a month.
|
||||
ev(`S.biz.push({id:'w',type:'wwave',city:'fra',city2:'ams',link:'e1',slots:2,bw:1,rate:3000,reqs:[],mood:100,since:0,name:'W'},
|
||||
{id:'p',type:'dfpair',city:'ams',city2:'ham',link:'e2',bw:1,rate:2000,reqs:[],mood:100,since:0,name:'P'},
|
||||
{id:'d',type:'capsub',city:'lon',city2:'nyc',bw:12800,rate:90,reqs:[],mood:100,since:0,live:true,due:400,name:'D'});S.stats.capDone=1;`);
|
||||
for (const id of ['bk_wave', 'bk_pair', 'bk_deal', 'bk_10t', 'bk_win']) assert.equal(ok(id), true, id);
|
||||
assert.equal(ev('capSoldG()'), 800 + 12800, 'waves at 400G each, plus subsea capacity; a dark pair is the buyer’s to light');
|
||||
// A deal not yet delivered sells nothing.
|
||||
ev("S.biz.find(b=>b.id==='d').live=false");
|
||||
assert.equal(ok('bk_win'), false);
|
||||
ev("S.biz.find(b=>b.id==='d').live=true");
|
||||
const cash = ev('S.cash');
|
||||
ev('checkGoals()');
|
||||
assert.equal(ev('goals().every(g=>S.done[g.id]!==undefined)'), true, 'the whole ladder');
|
||||
assert.equal(ev('S.cash') - cash, ev('BROKER_GOALS.reduce((a,g)=>a+g.r,0)'), 'every reward paid');
|
||||
assert.ok(ev('S.baronWon') > 0, 'Glass Baron won');
|
||||
assert.equal(ev('!!S.won'), false, 'Tier 1 is still its own thing');
|
||||
assert.equal(ev("S.ach&&S.ach.baron!==undefined"), true, 'with its badge');
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /Glass Baron/);
|
||||
assert.equal(ev("Object.keys(S.done).some(k=>GOALS.some(g=>g.id===k))"), false, 'the classic ladder is untouched');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a broker hears from carriers: more wave and pair offers, and capacity deals by phone', () => {
|
||||
const share = (k) => {
|
||||
const { ev } = picked(k);
|
||||
ev("S.lvl=3;" + df('e1', 'fra', 'ams') + ';' + df('e2', 'fra', 'par') + ';compute()');
|
||||
return ev("(()=>{let n=0,c=0;for(let i=0;i<400;i++){S.offers=[];spawnOffer();for(const o of S.offers){c++;if(['wwave','dfpair','pairs'].includes(o.type))n++;}}return n/Math.max(1,c);})()");
|
||||
};
|
||||
const g = share('global'), b = share('broker');
|
||||
assert.ok(b > g * 1.8, `capacity offers: ${(b * 100).toFixed(0)}% for a broker, ${(g * 100).toFixed(0)}% for a backbone`);
|
||||
const { ev, errors } = picked('broker');
|
||||
const day = ev('(()=>{for(let d=BROKER_CALL_FROM;d<2000;d++)if(hstr(S.asn+"|capcall|"+d)%BROKER_CALL===0)return d;return -1;})()');
|
||||
assert.ok(day >= 60);
|
||||
ev(`S.offers=[];brokerDay(${day})`);
|
||||
const o = JSON.parse(ev('JSON.stringify(S.offers)'));
|
||||
assert.equal(o.length, 1);
|
||||
assert.ok(['capw', 'capsub', 'capfib'].includes(o[0].type), 'a capacity deal from the conferences’ routes');
|
||||
ev('S.offers=[];for(let d=0;d<BROKER_CALL_FROM;d++)brokerDay(d)');
|
||||
assert.equal(ev('S.offers.length'), 0, 'not in the first two months');
|
||||
// Capacity conferences are open to a broker at any level.
|
||||
assert.equal(ev('glassLvl()>=CAP_LV'), true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('saves keep the broker and its win, and refuse charters that do not exist', () => {
|
||||
const { ev, errors } = picked('broker');
|
||||
ev('S.baronWon=1234');
|
||||
const s = JSON.parse(ev('JSON.stringify(S)'));
|
||||
ev(`S=migrate(${JSON.stringify(s)})`);
|
||||
assert.deepEqual([ev('S.charter'), ev('S.baronWon'), ev('charter()')], ['broker', 1234, 'broker']);
|
||||
ev(`S=migrate(${JSON.stringify({ ...s, charter: 'evil', baronWon: 'x' })})`);
|
||||
assert.deepEqual([ev('S.charter'), ev('S.baronWon')], ['global', 0]);
|
||||
ev(`S=migrate(${JSON.stringify(s)});S.scn={id:'x'}`);
|
||||
assert.equal(ev('charter()'), 'global', 'a scenario plays as the classic game');
|
||||
assert.equal(ev('glassLvl()'), ev('lvl()'));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -289,6 +289,28 @@ test('M5: Sandbox has no locked feature', () => {
|
|||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
test('M6: a charter changes what you set out to do, never what things cost', () => {
|
||||
const bad = [];
|
||||
const g = load();
|
||||
g.ev("beginGame('Charter','fra',{mode:'normal',preset:'oncall'});if(UI.pendGame)ACT.pitchSkip()");
|
||||
if (!g.ev('charterDue()')) bad.push('a new Normal game does not ask for its charter');
|
||||
g.ev("ACT.charter({k:'broker'});S.lvl=1");
|
||||
const glass = (x) => g.ev(`JSON.stringify({opt:Object.keys(OPT).map(o=>optCost(o)),sys:Object.keys(DF_SYS).map(sysCost),dig:digCost(500),cab:ownCabCost(5000),rt:RG.map((r,i)=>routerCost(i,1))})`);
|
||||
const b = JSON.parse(glass());
|
||||
g.ev("S.charter='global';S.lvl=LEVELS.length");
|
||||
const c = JSON.parse(glass());
|
||||
for (const k of Object.keys(b)) if (JSON.stringify(b[k]) !== JSON.stringify(c[k])) bad.push(`a broker at level 1 pays other prices for ${k} than a backbone at the top level`);
|
||||
g.ev("S.charter='broker';S.lvl=1");
|
||||
if (g.ev('S.te') || (g.ev('ACT.buyTE()'), g.ev('S.te'))) bad.push('a broker skips the levels for something that is not glass (Auto-TE)');
|
||||
for (const o of ["{mode:'sandbox'}", "{mode:'puzzle'}", '{scn:SCN[0]}']) {
|
||||
const h = load();
|
||||
h.ev(`beginGame('X','fra',${o});if(UI.pendGame)ACT.pitchSkip()`);
|
||||
if (h.ev('charterDue()')) bad.push(`${o} asks for a charter`);
|
||||
}
|
||||
fail('M6', bad, 'the broker gets glass early, not cheaper; charters belong to Normal games only');
|
||||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
// ---------- Content ----------
|
||||
|
||||
test('C1: every scenario has a goal its card checks, and none is won on day 0', () => {
|
||||
|
|
|
|||
|
|
@ -686,7 +686,7 @@ test('NOC leased lines tab prices leased dark fiber, own fiber and cables agains
|
|||
assert.match(t, /Amsterdam ⇄ Frankfurt/);
|
||||
assert.match(t, /Lease dark fiber: .* up front/);
|
||||
assert.match(t, /Your own fiber: .* up front/);
|
||||
assert.match(t, /Go transit-free first/, 'own subsea cables stay Tier 1 only');
|
||||
assert.match(t, /level 9, or Tier 1/, 'own subsea cables need customer level 9 or Tier 1 (#300)');
|
||||
const land = JSON.parse(ev("JSON.stringify(leaseSwaps().find(x=>x.a==='ams'))"));
|
||||
assert.equal(land.ls.length, 2, 'parallel waves on one route are grouped');
|
||||
assert.equal(land.cap, 800);
|
||||
|
|
|
|||
|
|
@ -122,11 +122,9 @@ test('#173 a consortium seat: offer, pay, build, light, cut, save', () => {
|
|||
test('#187 the Low-latency boutique: pick it on day 0, traders weigh more and pay more, Speed of Light wins', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
ev("ACT.leftTab({t:'goals'});renderAll()");
|
||||
assert.match(dom.window.document.body.innerHTML, /Pick a charter/);
|
||||
ev("window.innerWidth=360;renderAll()");
|
||||
assert.match(dom.window.document.body.innerHTML, /Low-latency boutique/, 'on a phone too');
|
||||
ev("window.innerWidth=1280");
|
||||
// The charter is asked in a popup when the game starts (tests/charters.test.js has the picker itself).
|
||||
ev("window.__TUBES_CHARTER__=true;renderAll()");
|
||||
assert.match(dom.window.document.getElementById('modalCard').innerHTML, /Low-latency boutique/);
|
||||
assert.equal(ev('charter()'), 'global', 'Global backbone until you pick');
|
||||
ev("ACT.charter({k:'boutique'})");
|
||||
assert.equal(ev('charter()'), 'boutique');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue