Merge remote-tracking branch 'origin/main' into df-pop-checks
# Conflicts: # src/game/90-actions/60-links.js # src/game/90-actions/87-fiber-and-hardware.js # src/game/90-actions/90-action-helpers.js
This commit is contained in:
commit
034a5de66e
19 changed files with 125 additions and 43 deletions
51
tests/borders-overland.test.js
Normal file
51
tests/borders-overland.test.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// Fiber over land inside one country: cities on land with no road in (Russia's Arctic and Kamchatka, Alaska, Greenland's
|
||||
// towns) can be dug to from the rest of their own country, and only their own. North and South Korea, like Kyiv and
|
||||
// Moscow, get no circuit between them at all.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.nextFail=S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;";
|
||||
|
||||
test('cities of one country on one piece of land can build terrestrial fiber between them', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
for (const [a, b, why] of [['pvs', 'dyr', 'Pevek–Anadyr, both Chukotka'], ['pvs', 'mos', 'Pevek–Moscow, across Russia'], ['pkc', 'vvo', 'Kamchatka–Vladivostok'],
|
||||
['jnu', 'sea', 'Juneau–Seattle, both US'], ['brw', 'ome', "Alaska's Arctic coast"], ['nuk', 'sis', "Greenland's towns, one island"]]) {
|
||||
assert.equal(ev(`isSub('${a}','${b}')`), false, `${why}: over land`);
|
||||
assert.equal(ev(`dfAllowed('${a}','${b}')`), true, `${why}: dark fiber can be built`);
|
||||
assert.equal(ev(`landMult('${a}','${b}')`) < 45, true, `${why}: not priced as a crossing between continents`);
|
||||
}
|
||||
ev("UI.lmode='wave';openLinkModal('pvs','dyr')");
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), /Terrestrial/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('only inside the country: islands and other countries stay across the sea', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
for (const [a, b, why] of [['jnu', 'van', 'Juneau–Vancouver: a border'], ['yfb', 'mtl', 'Iqaluit is on Baffin Island'], ['pkc', 'uus', 'Sakhalin is an island'],
|
||||
['ome', 'vvo', 'Nome–Vladivostok: two countries'], ['hnl', 'sea', 'Hawaii']]) {
|
||||
assert.equal(ev(`isSub('${a}','${b}')`), true, why);
|
||||
}
|
||||
assert.equal(ev("landMult('ist','esb')") < 45, true, 'Istanbul–Ankara is one country, not two continents');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('no circuit of any kind between North and South Korea, and still none between Kyiv and Moscow', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "ACT.launchBB({city:'icn'});S.pops.fnj={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:3};compute()");
|
||||
for (const [a, b, msg] of [['icn', 'fnj', /North and South Korea/], ['fnj', 'icn', /North and South Korea/], ['kyv', 'mos', /Kyiv and Moscow/]]) {
|
||||
ev(`UI.pending=null;openLinkModal('${a}','${b}')`);
|
||||
assert.match(ev("document.getElementById('modalCard').textContent"), msg);
|
||||
assert.equal(ev('UI.pending'), null, 'nothing to order');
|
||||
assert.equal(ev(`dfAllowed('${a}','${b}')`), false);
|
||||
}
|
||||
// Even an action called directly (an agent, a stale window) builds nothing.
|
||||
const n = ev('S.links.length');
|
||||
ev("UI.pending={a:'icn',b:'fnj'};ACT.buildLink({tier:0});UI.pending={a:'icn',b:'fnj'};UI.dfSrc='build';ACT.orderDf();UI.pending={a:'icn',b:'fnj'};ACT.orderCable()");
|
||||
assert.equal(ev('S.links.length'), n);
|
||||
// Seoul and Pyongyang are still on one landmass, but a latency customer cannot count on a link between them.
|
||||
assert.ok(ev("latFloor('icn','fnj')") > ev("latMaxOf('icn','fnj')"));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -92,7 +92,10 @@ test('Alaska and northern British Columbia: towns with no road in are islands, a
|
|||
}
|
||||
assert.equal(ev("isSub('anc','sea')"), false, 'Anchorage has a road south');
|
||||
assert.equal(ev("isSub('prr','van')"), false, 'so does Prince Rupert');
|
||||
for (const c of ['jnu', 'ome', 'brw', 'dut']) assert.ok(ev(`isSub('${c}','anc')`), `${c}: no road in, only the sea`);
|
||||
// No road in, but US soil joined to Anchorage: a US network may dig there. Unalaska is an island.
|
||||
for (const c of ['jnu', 'ome', 'brw']) assert.equal(ev(`isSub('${c}','anc')`), false, `${c}: overland inside the US`);
|
||||
assert.ok(ev("isSub('dut','anc')"), 'dut: an island, only the sea');
|
||||
assert.ok(ev("isSub('jnu','van')"), 'Juneau to Canada: a border, so only the sea');
|
||||
assert.ok(lands(ev, 'qtl', 'ome', 'brw') && lands(ev, 'qtl', 'brw', 'anc') && lands(ev, 'aleu', 'anc', 'dut') && lands(ev, 'topaz', 'van', 'tok'));
|
||||
assert.equal(ev('CAB.qtl.fragile'), true, 'sea ice keeps the repair ships away');
|
||||
assert.equal(ev('CITY.anc.ix.length>0'), true, 'Anchorage has its exchange');
|
||||
|
|
@ -120,8 +123,9 @@ test("Russia's Arctic and Pacific: government boxes, real cables only, beaches w
|
|||
// nothing crosses the Bering Strait
|
||||
assert.equal(ev("CABLE_PAIRS.some(p=>CITY[p.a].ru!==CITY[p.b].ru&&(CITY[p.a].cc==='US'||CITY[p.b].cc==='US'))"), false);
|
||||
assert.equal(ev("isSub('dyr','anc')"), true);
|
||||
// Kamchatka has no road to the rest of Russia; Magadan and Vladivostok do
|
||||
assert.equal(ev("isSub('pkc','vvo')"), true);
|
||||
// Kamchatka has no road to the rest of Russia, but it is Russian soil: a Russian route may dig there. Sakhalin is an island.
|
||||
assert.equal(ev("isSub('pkc','vvo')"), false);
|
||||
assert.equal(ev("isSub('uus','vvo')"), true);
|
||||
assert.equal(ev("isSub('gdx','vvo')||isSub('mmk','mos')"), false);
|
||||
assert.ok(ev("CITY.vvo.ix.length>0&&ixMembers('vvo').includes('mgf')&&ixMembers('vvo').includes('ert')"), 'the Vladivostok exchange');
|
||||
// a sovereign-internet drill cuts the cable to Japan like any other border link
|
||||
|
|
|
|||
|
|
@ -1,31 +1,39 @@
|
|||
// #273: a latency offer only asks for a ceiling something you can build meets. Pevek–Anadyr is 635 km apart as the
|
||||
// crow flies, but only a 1,717 km sea route joins them, so a 4.3 ms ceiling can never be met.
|
||||
// #273: a latency offer only asks for a ceiling something you can build meets. Iqaluit and Nuuk are about 750 km apart
|
||||
// as the crow flies, but no cable lands in Iqaluit and no road reaches it, so a 5.5 ms ceiling can never be met.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Spawn many mars offers from a network at Pevek and Anadyr only: most are between the two.
|
||||
// Spawn many mars offers from a network at two cities only: most are between the two.
|
||||
const marsOnly = "eval('('+spawnOffer.toString().replace('const t=pick(types)',\"const t='mars'\")+')')";
|
||||
const spawn = (ev, n) => ev(`(()=>{S.offers=[];const f=${marsOnly};for(let i=0;i<${n};i++)f();return JSON.stringify(S.offers.map(o=>[o.city,o.city2,o.latMax]));})()`);
|
||||
const start = (ev, cities) => ev(`ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=13;S.pops={};for(const c of ${JSON.stringify(cities)})S.pops[c]={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};compute()`);
|
||||
|
||||
test('#273 no latency offer between Pevek and Anadyr: no buildable path meets the straight-line ceiling', () => {
|
||||
test('#273 no latency offer between Iqaluit and Nuuk: no buildable path meets the straight-line ceiling', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, ['pvs', 'dyr']);
|
||||
start(ev, ['yfb', 'nuk']);
|
||||
assert.ok(ev('lvl()') >= 13, 'mars offers are unlocked');
|
||||
assert.equal(ev("latMaxOf('pvs','dyr')"), 4.3);
|
||||
const pair = o => [o[0], o[1]].sort().join('-') === 'dyr-pvs';
|
||||
assert.equal(ev("latMaxOf('yfb','nuk')"), 5.5);
|
||||
const pair = o => [o[0], o[1]].sort().join('-') === 'nuk-yfb';
|
||||
const offers = JSON.parse(spawn(ev, 60));
|
||||
assert.ok(offers.length > 0, 'mars offers still spawn');
|
||||
assert.deepEqual(offers.filter(pair), [], 'but none asks for 4.3 ms between Pevek and Anadyr');
|
||||
assert.ok(!(ev("latFloor('pvs','dyr')") <= 4.3), 'nothing on the map gets there in 4.3 ms');
|
||||
// Even with the player's own Low latency cable, 7.7 ms is the best there is.
|
||||
ev("S.links.push({id:'own1',a:'pvs',b:'dyr',kind:'df',own:true,sub:true,seaDesign:'express',sys:'roadm',ch:[],km:1717,cable:null,mo:1,trench:'own:own1',cut:0,day:0,ready:0,pairs:1});compute()");
|
||||
assert.ok(ev("bestLat('pvs','dyr')") > 4.3);
|
||||
assert.deepEqual(offers.filter(pair), [], 'but none asks for 5.5 ms between Iqaluit and Nuuk');
|
||||
assert.ok(!(ev("latFloor('yfb','nuk')") <= 5.5), 'nothing on the map gets there in 5.5 ms');
|
||||
// Even with the player's own Low latency cable round Baffin Island's coast, the best is above the ceiling.
|
||||
ev("S.links.push({id:'own1',a:'yfb',b:'nuk',kind:'df',own:true,sub:true,seaDesign:'express',sys:'roadm',ch:[],km:1300,cable:null,mo:1,trench:'own:own1',cut:0,day:0,ready:0,pairs:1});compute()");
|
||||
assert.ok(ev("bestLat('yfb','nuk')") > 5.5);
|
||||
assert.deepEqual(JSON.parse(spawn(ev, 60)).filter(pair), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#273 Pevek–Anadyr is Russian fiber over land now, so its 4.3 ms offers can be met and do come', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, ['pvs', 'dyr']);
|
||||
assert.ok(ev("latFloor('pvs','dyr')") <= ev("latMaxOf('pvs','dyr')"));
|
||||
assert.ok(JSON.parse(spawn(ev, 60)).some(o => [o[0], o[1]].sort().join('-') === 'dyr-pvs'));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#273 latency offers still come where a build meets the ceiling', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, ['lon', 'nyc']);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ test('diversity map: the indexed graph answers like disjointRoutes() over every
|
|||
ev('ACT.start({})');
|
||||
// The plain map: one record per possible link, in the order the indexed one adds them.
|
||||
ev(`window.plainLinks=state=>{const rules=state.scn&&state.scn.rules||{},links=[],cities=CITIES.filter(c=>!(rules.banCities||[]).includes(c.id)).map(c=>c.id),add=(a,b,id)=>links.push({a,b,id});
|
||||
for(let i=0;i<cities.length;i++)for(let j=i+1;j<cities.length;j++){const a=cities[i],b=cities[j];
|
||||
for(let i=0;i<cities.length;i++)for(let j=i+1;j<cities.length;j++){const a=cities[i],b=cities[j];if(noTalk(a,b))continue;
|
||||
if(!isSub(a,b)){add(a,b,'land:'+a+':'+b+':1');add(a,b,'land:'+a+':'+b+':2');}
|
||||
for(const c of cablesFor(a,b))if(!(rules.banPairs||[]).some(p=>p===c.cid+':'+a+'-'+b||p===c.cid+':'+b+'-'+a))add(a,b,'cab:'+c.cid);
|
||||
if(state.won&&seaCab(a,b)&&landing(a)&&landing(b)&&!cnCity(a)&&!cnCity(b))add(a,b,'own:'+a+':'+b);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue