Consortium seats take regen sites; the broker sells listings as the market wants (#203)
A seat bought at level 2 or 3 could not be lit: early optics do not reach across an ocean. Seats can now regenerate in the landing stations along their cable. A capacity broker listing is now standing: list some alien waves or the spare pair and they sell over time as carriers on that route want capacity. Each route's market is sized by the eyeballs at both ends (a landing town counts the city it serves), and rented capacity, from the broker or a random offer, never outgrows it. Gameplay rule F5.
This commit is contained in:
parent
664dd24bbd
commit
43938083d4
15 changed files with 170 additions and 34 deletions
69
tests/fiber-broker.test.js
Normal file
69
tests/fiber-broker.test.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// The capacity broker sells a listing as the route's market wants (#203), and consortium seats can regenerate in the
|
||||
// landing stations along their cable, so a seat bought early can be lit with early optics.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;S.offers=[];S.biz=[]");
|
||||
const fiber = (ev, id, a, b, km) => ev(`for(const c of ['${a}','${b}'])if(!S.pops[c])ACT.buildPop({city:c});S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'roadm',ch:['tp16'],km:${km},ready:0,day:0,cut:0,mo:100,trench:'own:${id}',pairs:1,spares:false});compute()`);
|
||||
|
||||
test('a route\'s market follows the eyeballs at both ends, and a landing town counts the city it serves', () => {
|
||||
const { ev } = load();
|
||||
start(ev);
|
||||
assert.ok(ev("brMarket('fra','ams')") >= 6, 'Frankfurt to Amsterdam wants a handful of waves');
|
||||
assert.equal(ev("brMarket('jed','gdx')"), 1, 'Jeddah to Magadan (#203) wants about one');
|
||||
assert.ok(ev("brMarket('nyc','bde')") > 10, 'Bude lands the Atlantic for London');
|
||||
assert.ok(ev("brMarket('nyc','bde')") > ev("brMarket('nyc','gdx')"));
|
||||
});
|
||||
|
||||
test('a listing sells over time, never past the market, and rent from a road to nowhere stays small', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev);
|
||||
fiber(ev, 'big', 'fra', 'ams', 450);
|
||||
fiber(ev, 'far', 'jed', 'gdx', 9089);
|
||||
ev("__reseed(7);ACT.listFiber({id:'big',w:60});ACT.listFiber({id:'far',w:60})");
|
||||
assert.equal(ev("S.biz.length"), 0, 'nothing sells the moment it is listed');
|
||||
ev('for(let d=0;d<720;d++)brTick()');
|
||||
const sold = (id) => ev(`S.biz.filter(b=>b.link==='${id}').reduce((a,b)=>a+(b.slots||0),0)`);
|
||||
assert.ok(sold('big') >= 3, `Frankfurt–Amsterdam sold ${sold('big')}`);
|
||||
assert.ok(sold('big') <= ev("brMarket('fra','ams')"), 'never more than the route wants');
|
||||
assert.equal(sold('far'), 1, 'Jeddah–Magadan: one wave, then the market is full');
|
||||
assert.equal(ev("brFree(S.links.find(l=>l.id==='far'))"), 0);
|
||||
// random alien-wave offers respect the market too
|
||||
ev("S.offers=[];for(let i=0;i<400;i++)spawnOffer()");
|
||||
assert.equal(ev("S.offers.filter(o=>o.link==='far').length"), 0, 'no random offer for a full route');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a listing is kept in the save, checked, and can be taken off the market', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev);
|
||||
fiber(ev, 'big', 'fra', 'ams', 450);
|
||||
ev("ACT.listFiber({id:'big',w:4})");
|
||||
ev("const t=JSON.stringify(packSave(S));S=migrate(JSON.parse(t))");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links.find(l=>l.id==='big').list)")), { w: 4, p: 0 });
|
||||
ev("const o=JSON.parse(JSON.stringify(packSave(S)));o.links.find(l=>l.id==='big').list={w:'lots',p:-3};S=migrate(o)");
|
||||
assert.equal(ev("S.links.find(l=>l.id==='big').list===undefined"), true, 'junk is dropped');
|
||||
ev("ACT.listFiber({id:'big',w:2});ACT.unlistFiber({id:'big'})");
|
||||
assert.equal(ev("S.links.find(l=>l.id==='big').list===undefined"), true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a consortium seat regenerates in the landing stations along its cable, so early optics can light it', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev);
|
||||
ev("S.lvl=2;for(const c of ['mrs','sin'])if(!S.pops[c])ACT.buildPop({city:c});S.pops.mrs.rgen=S.pops.sin.rgen=1;S.seatOff={a:'mrs',b:'sin',name:'Sea, Me, We, Us, Them',km:seatKm('mrs','sin'),exp:S.day+30};ACT.seatBuy({n:1});const l=S.links.at(-1);l.ready=S.day;compute()");
|
||||
const id = ev('S.links.at(-1).id');
|
||||
assert.ok(ev(`!!chWhy(S.links.at(-1),'zr4')`), 'out of reach without regens');
|
||||
for (let i = 0; i < 8; i++) ev(`ACT.regen({id:'${id}',d:1})`);
|
||||
assert.equal(ev('S.links.at(-1).regen'), 8, 'regen sites on a seat');
|
||||
assert.equal(ev(`chWhy(S.links.at(-1),'zr4')`), '', 'and the level-2 optic reaches');
|
||||
ev(`ACT.addCh({id:'${id}',o:'zr4'})`);
|
||||
assert.equal(ev('S.links.at(-1).ch.length'), 1, 'lit');
|
||||
ev(`selectLink(S.links.at(-1));renderPanel()`);
|
||||
assert.match(ev("document.getElementById('panelBody').textContent"), /landing stations along the way/);
|
||||
// your own point-to-point cable still cannot
|
||||
ev("S.links.push({id:'own',a:'lis',b:'for',kind:'df',own:true,sub:true,seaDesign:'standard',sys:'roadm',ch:[],km:6000,ready:0,day:0,cut:0,mo:1,trench:'own:own',pairs:1});ACT.regen({id:'own',d:1})");
|
||||
assert.equal(ev("S.links.find(l=>l.id==='own').regen|0"), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -382,6 +382,15 @@ test('F4: the chaos monkey only visits On-call and BGP at 3 a.m., late, for 120
|
|||
assert.equal(g.ev('mkElig()'), false, 'F4: never in Sandbox');
|
||||
});
|
||||
|
||||
test('F5: rented capacity never outgrows the route\'s market (#203)', () => {
|
||||
const g = load();
|
||||
g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.biz=[];S.offers=[];for(const c of ['jed','gdx'])ACT.buildPop({city:c})");
|
||||
g.ev("S.links.push({id:'f',a:'jed',b:'gdx',kind:'df',own:true,sys:'roadm',ch:[],km:9089,ready:0,day:0,cut:0,mo:1,trench:'own:f',pairs:1});compute();__reseed(5);ACT.listFiber({id:'f',w:120,p:1})");
|
||||
g.ev('for(let d=0;d<1500;d++){brTick();if(d%7===0)spawnOffer();}for(const o of S.offers.filter(o=>o.link===\'f\'))ACT.accept({id:o.id})');
|
||||
assert.ok(g.ev("brSold('jed','gdx')") <= g.ev("brMarket('jed','gdx')"), 'F5: no more than the route wants');
|
||||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
test('no page errors while checking the rules', () => {
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1259,23 +1259,24 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
|
|||
ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'ams'});S.offers=[];S.links.push({id:'df1',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',ch:['tp16','tp16'],km:450,ready:0,day:0,cut:0,mo:100,trench:'own:df1',pairs:1});after();UI.sel={type:'link',id:'df1'};renderPanel()");
|
||||
const txt = () => ev("document.getElementById('panelBody').textContent");
|
||||
assert.match(txt(), /Selling spare capacity/); assert.match(txt(), /Free channels\s*62 \/ 64/);
|
||||
// a broker finds a buyer for free channels at once, and keeps 10%
|
||||
ev("__reseed(9);ACT.advertise({id:'df1'})");
|
||||
const o = JSON.parse(ev("JSON.stringify(S.offers.find(x=>x.link==='df1'))"));
|
||||
assert.equal(o.type, 'wwave'); assert.ok(o.broker);
|
||||
assert.equal(o.rate, ev(`Math.round(waveMo(450,false,2)*0.55*${o.slots}*0.9)`), 'the usual alien-wave price minus the broker');
|
||||
assert.match(txt(), /via a capacity broker/);
|
||||
ev("ACT.advertise({id:'df1'})"); assert.equal(ev("S.offers.filter(x=>x.link==='df1').length"), 1, 'one listing at a time');
|
||||
ev(`document.querySelector('#panelBody [data-act=accept]').click()`);
|
||||
assert.ok(txt().includes(o.name), 'the customer is listed on the fiber');
|
||||
assert.match(txt(), new RegExp(`Free channels\\s*${62 - o.slots} / 64`));
|
||||
// when every channel is lit or sold, the spare pair in your own trench is offered instead; then nothing is left
|
||||
ev("const l=S.links[0];l.ch=Array(chMax(l)-soldSlots(l)).fill('tp16');after();ACT.advertise({id:'df1'})");
|
||||
assert.equal(ev("S.offers.find(x=>x.link==='df1').type"), 'dfpair');
|
||||
ev("for(const x of S.offers.filter(x=>x.link==='df1'))ACT.accept({id:x.id});S.biz.push({id:'p2',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'X',bw:1,rate:1,reqs:[]});S.offers=[];renderPanel()");
|
||||
// a broker keeps a listing and sells it as the route's market wants (#203), keeping 10%
|
||||
ev("__reseed(9);ACT.listFiber({id:'df1',w:4})");
|
||||
assert.equal(ev("S.links[0].list.w"), 4);
|
||||
assert.match(txt(), /Listed with a capacity broker/);
|
||||
ev("for(let i=0;i<120&&!S.biz.some(b=>b.link==='df1');i++)brTick();renderPanel()");
|
||||
const b = JSON.parse(ev("JSON.stringify(S.biz.find(x=>x.link==='df1'))"));
|
||||
assert.equal(b.type, 'wwave');
|
||||
assert.equal(b.rate, ev(`Math.round(waveMo(450,false,2)*0.55*${b.slots}*0.9)`), 'the usual alien-wave price minus the broker');
|
||||
assert.ok(txt().includes(b.name), 'the customer is listed on the fiber');
|
||||
assert.match(txt(), new RegExp(`Free channels\\s*${62 - b.slots} / 64`));
|
||||
assert.equal(ev("S.links[0].list?S.links[0].list.w:0"), 4 - b.slots, 'the listing shrinks by what sold');
|
||||
// when every channel is lit or sold, only the spare pair in your own trench can be listed; then nothing is left
|
||||
ev("const l=S.links[0];delete l.list;l.ch=Array(chMax(l)-soldSlots(l)).fill('tp16');after();ACT.listFiber({id:'df1',w:4,p:1})");
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(S.links[0].list)")), { w: 0, p: 1 });
|
||||
ev("S.biz.push({id:'p1',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'X',bw:1,rate:1,reqs:[]},{id:'p2',type:'dfpair',link:'df1',city:'fra',city2:'ams',name:'Y',bw:1,rate:1,reqs:[]});delete S.links[0].list;S.offers=[];renderPanel()");
|
||||
assert.match(txt(), /Nothing spare to sell on this fiber right now/);
|
||||
ev("ACT.advertise({id:'df1'})"); assert.equal(ev("S.offers.length"), 0);
|
||||
// a broker offer survives a save, and random offers still come the same way
|
||||
ev("ACT.listFiber({id:'df1',w:1,p:1})"); assert.equal(ev("S.links[0].list===undefined"), true);
|
||||
// an old broker offer still survives a save
|
||||
ev("S.offers=[{...fiberOffer('dfpair',S.links[0],()=>'Y',0.9),broker:'yes'}];S=sanitize(S)");
|
||||
assert.equal(ev('S.offers[0].broker'), true);
|
||||
assert.deepEqual(errors, []);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue