${b.i} ${had?tr('badges.badge_upgraded_name',{name:esc(b.t)}):tr('badges.badge_unlocked_name',{name:esc(b.t)})}
${R0.n}${v==='oncall'?'':` · ${V.i} ${tr(V.n)}`} · ${esc(b.d)}`,'goal',[],{a:'tab',v:'goals'});sfx('coin');track('badge_'+b.id+(v==='oncall'?'':'_'+v));}
if(h)try{localStorage.setItem('sot-badges',JSON.stringify(h));}catch(e){}}
-function badgeGrid(){const h=hof(),got=BADGES.filter(b=>S.ach&&S.ach[b.id]!==undefined).length;
- return `${tr('common.badges')} ${tr('badges.got_total_this_game_ever_ever',{got,total:BADGES.length,ever:Object.keys(h).filter(k=>BADGES.some(b=>b.id===k)).length})}
${BADGES.map(b=>{const on=S.ach&&S.ach[b.id]!==undefined,ever=!!h[b.id],R0=RARITY[b.r],hide=b.secret&&!on&&!ever;
- return `
${hide?'❔':b.i}${esc(hide?'???':b.t)}${R0.n}${ever&&!on?' · '+tr('common.earned_before'):''}${hide?'':`${esc(b.d)}`}
`;}).join('')}
`;}
+// How many badges this device has ever earned in each variant: the collection.
+function badgeShelf(h){const o={freeze:0,oncall:0,bgp:0};for(const b of BADGES){const x=h[b.id];if(x)for(const v of BVAR_IDS)if(x.vs[v]!==undefined)o[v]++;}return o;}
+function badgeGrid(){const h=hof(),got=BADGES.filter(b=>S.ach&&S.ach[b.id]!==undefined).length,sh=badgeShelf(h),V=badgeVar();
+ return `${tr('common.badges')} ${tr('badges.got_total_this_game_ever_ever',{got,total:BADGES.length,ever:Object.keys(h).filter(k=>BADGES.some(b=>b.id===k)).length})}
+ ${BVAR_IDS.map(v=>`${BVAR[v].i} ${esc(tr(BVAR[v].n))} ${sh[v]}/${BADGES.length}`).join('')}
${V&&V!=='oncall'?`${V==='bgp'?tr('badges.this_game_earns_fiery_badges'):tr('badges.this_game_earns_frosted_badges')}
`:''}
+ ${BADGES.map(b=>{const on=S.ach&&S.ach[b.id]!==undefined,ever=!!h[b.id],R0=RARITY[b.r],hide=b.secret&&!on&&!ever,vk=on?bvar(S.achP&&S.achP[b.id]).k:ever?h[b.id].v:'',vn=vk&&vk!=='oncall'?' · '+BVAR[vk].i+' '+tr(BVAR[vk].n):'';
+ return `
${hide?'❔':b.i}${esc(hide?'???':b.t)}${R0.n}${ever&&!on?' · '+tr('common.earned_before'):''}${vk&&vk!=='oncall'?`${BVAR[vk].i} ${esc(tr(BVAR[vk].n))}`:''}${hide?'':`${esc(b.d)}`}
`;}).join('')}
`;}
function checkGoals(){checkBadges();
for(const g of GOALS){if(S.done[g.id]!==undefined)continue;let ok=false;try{ok=g.ok();}catch(e){}
if(ok){S.done[g.id]=S.day;if(g.r&&S.mode!=='sandbox'){S.cash+=g.r;}
diff --git a/src/game/93-ui/40-hud-and-panels.js b/src/game/93-ui/40-hud-and-panels.js
index 2a98394..9248b98 100644
--- a/src/game/93-ui/40-hud-and-panels.js
+++ b/src/game/93-ui/40-hud-and-panels.js
@@ -76,7 +76,7 @@ function renderLeft(){checkLayer();
h+=`${btn(tr('common.all_networks'),'netFilter',{f:'all'},!foc&&!out?'sm':'ghost sm')}${btn(tr('hud_and_panels.out_of_reach_without_transit_n',{n:lostN}),'netFilter',{f:'out'},out?'sm':'ghost sm')}
`;
if(out&&!lostN)h+=`${tr('hud_and_panels.nothing_every_network_is_reachable')}
`;
for(const n of foc?[foc]:out?ntLost():NETS){if(n.tail&&!UI.tailOpen&&!foc&&!out)continue;
- h+=`${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`
${esc(offTransitHint(n.id))}
`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;}
+ h+=`${logo(n)}
${esc(n.name)} AS${n.asn}
${TYPE_L[n.type]} ${n.pol} · ${tr('hud_and_panels.p_of_traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('hud_and_panels.transit_price_gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}
${esc(n.blurb)}
${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`
${esc(offTransitHint(n.id))}
`:''}${(foc||out)&&coneVia(n.id)&&(R.cone[n.id]||!R.nt[n.id])?`
${R.cone[n.id]?tr('hud_and_panels.reached_through_the_customer_cone_of',{net:esc(coneVia(n.id).name)}):tr('hud_and_panels.buys_transit_from_net_peer_with',{net:esc(coneVia(n.id).name)})}
`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}
`;}
if(!foc&&!out)h+=`${tr('hud_and_panels.the_long_tail')} ${tr('hud_and_panels.n_small_networks',{n:tl.length})}
${tr('hud_and_panels.p_of_traffic_between_them_scattered',{p:(tl.reduce((a,n)=>a+NSH[n.id],0)*100).toFixed(1),n:tlOn})}
${btn(UI.tailOpen?tr('common.hide'):tr('common.show'),'tailTog',{},'ghost sm')}
`;
}
if(h!==UI._lh){UI._lh=h;morph($('leftBody'),h);}
diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js
index 0378b3f..e89b6e4 100644
--- a/src/game/93-ui/70-link-panels.js
+++ b/src/game/93-ui/70-link-panels.js
@@ -132,6 +132,8 @@ function svgChart(rows,stackKeys,lines,fmtY){
// For a network you currently reach over transit: the cheapest way to move it to peering.
// Exchange members as sets, rebuilt once per routing pass: hints are asked for many networks at a time.
let IXMR=null,IXMC={};const ixHas=(x,id)=>{if(IXMR!==R){IXMR=R;IXMC={};}return (IXMC[x]||(IXMC[x]=new Set(ixMembers(x)))).has(id);};
+// Who brings a network along (#85): the nearest of its upstreams, then theirs; null if it sits in nobody's cone.
+function coneVia(id){const a=ANC[id];if(!a||!a.length)return null;const t1=a.find(u=>NET[u].type==='t1');return NET[t1||a[0]];}
function offTransitHint(id,city){const n=NET[id];if(n.type==='t1')return tr('link_panels.tier_1_only_a_pni_and');
const ixc=Object.keys(S.pops).flatMap(ixIdsIn).filter(x=>ixHas(x,id)),here=city&&ixIdsIn(city).find(x=>ixHas(x,id))||null,pick1=here||ixc.find(x=>S.ixp[x]!==undefined)||ixc[0];
if(n.pol==='open'){if(pick1)return here||ixNamesCity(pick1)?tr('link_panels.open_peer_join_the_route_server',{ix:ixName(pick1)}):tr('link_panels.open_peer_join_the_route_server_01a1',{ix:ixName(pick1),city:CITY[ixCity(pick1)].name});const x=nearestSpot(id);return x?tr('link_panels.open_peer_but_not_on_any',{city:CITY[x.c].name}):tr('link_panels.open_peer_but_not_on_any_bfbb');}
diff --git a/src/game/94-dashboard/20-meet-a-network.js b/src/game/94-dashboard/20-meet-a-network.js
index 344f305..736005a 100644
--- a/src/game/94-dashboard/20-meet-a-network.js
+++ b/src/game/94-dashboard/20-meet-a-network.js
@@ -27,5 +27,7 @@ function t1Card(){const cur=GOALS.find(g=>S.done[g.id]===undefined);if(!((cur&&c
h+=pRow({l:tr('meet_a_network.pnis_with_every_tier_1'),v:need.length-miss.length,max:need.length,txt:`${need.length-miss.length} / ${need.length}`});
if(miss.length)h+=`${miss.map(nb).join('')}
`+(club.ok?'':`${tr('meet_a_network.tier_1s_only_take_a_pni',{list:club.missing.join(', ')})}
`);
h+=pRow({l:tr('meet_a_network.reach_without_transit'),v:Math.min(R.reachNT,0.999),max:0.999,txt:`${reachPct(R.reachNT)} / 99.9%`});
+ // Their customers come along for free (#85): say how many, so the long tail does not look like homework.
+ {const nc=Object.keys(R.cone||{}).length;h+=`${nc?trn('meet_a_network.peer_with_the_tier_1_club_n',nc):tr('meet_a_network.peer_with_the_tier_1_club')}
`;}
if(lost.length)h+=`${lost.slice(0,3).map(nb).join('')}${btn(trn('meet_a_network.all_n_out_of_reach',lost.length),'netFilter',{f:'out'},'pink sm')}
`;
return h+'';}
diff --git a/src/game/95-modals/60-help.js b/src/game/95-modals/60-help.js
index e8e5e51..e632c99 100644
--- a/src/game/95-modals/60-help.js
+++ b/src/game/95-modals/60-help.js
@@ -5,7 +5,7 @@ function showHelp(){
${tr('common.eyeballs')}${tr('help.home_broadband_users_they_mostly')}
POP${tr('help.point_of_presence_your_router_in')}
${tr('common.ip_transit')}${tr('help.you_pay_a_bigger_network_per')}
- Tier 1 / Tier 2${tr('help.tier_1s_reach_the_whole_internet')}
+ Tier 1 / Tier 2${tr('help.tier_1s_reach_the_whole_internet_cones')}
CDN${tr('help.content_networks_like_netchill_and')}
${tr('help.ix_internet_exchange')}${tr('help.a_shared_switch_in_a_city')}
PNI${tr('help.private_network_interconnect_a_cable')}
diff --git a/src/i18n/en.js b/src/i18n/en.js
index 008cdfd..2a4aa4f 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -18,6 +18,7 @@
"badges.attend_a_conference":"Attend a conference.",
"badges.attend_six_conferences_in_one_game":"Attend six conferences in one game.",
"badges.badge_unlocked_name":"Badge unlocked: {name}",
+"badges.badge_upgraded_name":"Badge upgraded: {name}",
"badges.blackhole_one_of_your_own_cities":"Blackhole one of your own cities to stop a DDoS.",
"badges.bring_up_your_first_peering_session":"Bring up your first peering session.",
"badges.build_fiber_across_the_andes":"Build fiber across the Andes.",
@@ -99,9 +100,14 @@
"badges.take_a_de_kicks_retention_offer":"Take a DE-KICKS retention offer.",
"badges.take_out_a_loan":"Take out a loan.",
"badges.the_long_way_round":"The Long Way Round",
+"badges.this_game_earns_fiery_badges":"This game runs BGP at 3 a.m.: every badge you earn here is forged in fire, and upgrades one you already have.",
+"badges.this_game_earns_frosted_badges":"This game runs a Change Freeze: badges you earn here come freeze-dried.",
"badges.through_the_wall":"Through the Wall",
"badges.turn_on_a_transit_clean_pipe":"Turn on a transit clean-pipe add-on.",
"badges.two_buildings_three_cities":"Two Buildings, Three Cities",
+"badges.variant_forged_at_3_a_m":"Forged at 3 a.m.",
+"badges.variant_freeze_dried":"Freeze-dried",
+"badges.variant_on_call":"On-call",
"badges.weather_a_ddos_with_your_defences":"Weather a DDoS with your defences ready.",
"badges.weather_a_multi_terabit_ddos":"Weather a multi-terabit DDoS.",
"badges.win_without_ever_taking_a_loan":"Win without ever taking a loan.",
@@ -1828,7 +1834,7 @@
"goals.make_5_peering_friends":"Make 5 peering friends",
"goals.on_the_peering_tab_request_sessions":"On the Peering tab, request sessions, or join the route server to peer with every open network at once.",
"goals.open_your_home_city_and_press":"Open your home city and press “Launch broadband”. Eyeballs are people at home watching cat videos. They pay you every month.",
-"goals.peer_with_every_tier_1_over":"Peer with every Tier 1 over PNIs and cancel every transit port. Then nobody charges you to reach the internet.",
+"goals.peer_with_every_tier_1_their_customers":"Peer with every Tier 1 over PNIs and cancel every transit port. Their customers come along for free, so you only chase the networks nobody sells transit to.",
"goals.pops_in_five_of_the_six":"POPs in five of the six regions on the map.",
"goals.reach_the_whole_internet":"Reach the whole internet",
"goals.serve_10_tbps":"Serve 10 Tbps",
@@ -1890,7 +1896,7 @@
"help.the_chart_button_at_the_top":"The chart button at the top opens traffic graphs by exit (caches, PNIs, IX, transit), money over time, per-ASN traffic with how it reaches you and what its transit costs, plus your busiest links and routers.",
"help.the_group_behind_several_big":"The group behind several big exchanges (Frankfurt, Madrid, Marseille, Dubai, Mumbai, New York) treats price lists as a state secret. Ports are quoted per customer and go up the bigger you look. Haggling can work, backfire or stall for a week. Prices get \"harmonised\" upwards once a year, add-ons appear on your invoice until you opt out, and trying to leave earns you a retention discount that ends with a fee.",
"help.things_break_all_the_time_fiber":"Things break all the time: fiber cuts, router crashes, power cuts, IX loops, fabric outages, route leaks, DDoS, fat fingers, cooling failures, and geopolitics: sanctions, tariffs, BGP hijacks, landing permit disputes, exam-day shutdowns and Red Sea cable cuts. Traffic reroutes automatically over other paths and upstreams. Parallel links on diverse routes, a second router and a backup generator all help. Or pay to rush repairs.",
-"help.tier_1s_reach_the_whole_internet":"Tier 1s reach the whole internet without paying anyone, because they all peer with each other. Tier 2s peer a lot but still buy some transit.",
+"help.tier_1s_reach_the_whole_internet_cones":"Tier 1s reach the whole internet without paying anyone: they all peer with each other, and each brings along its customer cone, everyone who buys transit from it. Tier 2s peer a lot but still buy some transit.",
"help.traffic_follows_the_shortest_path_by":"Traffic follows the shortest path by distance and link metric, and reroutes by itself when links fail. When a path is merely full, the overflow is dropped, just like a real IGP. From customer level 3 you can install Auto-TE in the NOC tab: it spills overflow onto up to two alternate paths with free capacity, as long as they are no more than twice as long.",
"help.transit_bills_sample_your_usage":"Transit bills sample your usage every day and charge the 95th percentile of the last 30 days, so short spikes are forgiven but long ones are not.",
"help.users_feel_the_round_trip_to":"Users feel the round trip to wherever their traffic leaves your network for transit. Up to 20 ms (about 1,500 km) is fine; past 50 ms broadband and internet services count as bad service, which costs revenue and customers. Traffic over your own peering, PNIs and caches is not penalised.",
@@ -1915,12 +1921,13 @@
"hot_ports_and_rank.upgrade_the_ix_port_or_add":"Upgrade the IX port or add a LAG member.",
"hot_ports_and_rank.upgrade_the_router_or_add_a":"Upgrade the router or add a second one in the Infra tab.",
"hot_ports_and_rank.you_buy_transit_again":"you buy transit again",
-"hot_ports_and_rank.you_cannot_reach_list":"you cannot reach {list}",
+"hot_ports_and_rank.you_cannot_reach_list_outside_cones":"you cannot reach {list}, which nobody you peer with sells transit to",
"hot_ports_and_rank.your_reach_is_p_not_100":"your reach is {p}, not 100%",
"hud_and_panels.all_connections_n":"All connections {n}",
"hud_and_panels.all_systems_green_enjoy_it_while":"All systems green. Enjoy it while it lasts.",
"hud_and_panels.auto_fix_in_n_day":{"one":"Auto-fix in {n} day","other":"Auto-fix in {n} days"},
"hud_and_panels.blackholing_g":"blackholing {g}",
+"hud_and_panels.buys_transit_from_net_peer_with":"Buys transit from {net}. Peer with {net} and it comes along.",
"hud_and_panels.customer_level_lv_name":"Customer level {lv}: {name}",
"hud_and_panels.dropping_or_overflowing":"dropping or overflowing",
"hud_and_panels.every_network_on_the_map_traffic":"Every network on the map. Traffic share is how much of your users' traffic goes to them. Tap a connection to jump to its POP.",
@@ -1957,6 +1964,7 @@
"hud_and_panels.p_of_traffic_between_them_scattered":"{p}% of traffic between them, scattered across exchanges. You peer with {n}.",
"hud_and_panels.ports_caches_and_routers_running_hot":"Ports, caches and routers running hot",
"hud_and_panels.raise_a_full_link_s_metric":"Raise a full link’s metric so traffic prefers another path, upgrade it, or install Auto-TE.",
+"hud_and_panels.reached_through_the_customer_cone_of":"Reached through the customer cone of {net}: it buys transit there.",
"hud_and_panels.reaches_networks_from_the_last":"Reaches networks from the last update that you have no other path to, for free. Connect to them before it ends.",
"hud_and_panels.reward_cash":"Reward {cash}",
"hud_and_panels.survived_with_no_impact":"Survived with no impact",
@@ -2348,6 +2356,8 @@
"loop.welcome_back_name_your_network_is":"Welcome back, {name}.
Your network is right where you left it: {date}.",
"loop.your_saved_game_could_not_be":"Your saved game could not be loaded.
It was damaged, so a backup was kept and you can start fresh.",
"meet_a_network.all_n_out_of_reach":{"one":"All {n} out of reach","other":"All {n} out of reach"},
+"meet_a_network.peer_with_the_tier_1_club":"Peer with the Tier 1 club: their customers come along for free. Only networks in nobody’s customer cone need peering of their own.",
+"meet_a_network.peer_with_the_tier_1_club_n":{"one":"Peer with the Tier 1 club: their customers come along for free. {n} network already comes along with a peer.","other":"Peer with the Tier 1 club: their customers come along for free. {n} networks already come along with a peer."},
"meet_a_network.pnis_with_every_tier_1":"PNIs with every Tier 1",
"meet_a_network.reach_without_transit":"Reach without transit",
"meet_a_network.road_to_tier_1":"Road to Tier 1",
@@ -3035,6 +3045,7 @@
"title.scenarios_amp_weekly_challenge":"Scenarios & weekly challenge →",
"title.source_on_github":"Source on GitHub",
"title.your_network_name_was_saved_and":"Your network {name} was saved and is waiting for you.",
+"traceroute.a_peer_s_customers_come_after":"a peer’s customers come after direct peers, before transit",
"traceroute.across_the_ix_switch":"across the {ix} switch",
"traceroute.as_path_path":"AS path: {path}",
"traceroute.caches_beat_pnis":"caches beat PNIs",
@@ -3050,6 +3061,7 @@
"traceroute.n_network_unreachable":"!N network unreachable",
"traceroute.name_transit":"{name} transit",
"traceroute.net_carries_it_to_city":"{net} carries it to {city}",
+"traceroute.net_hands_it_to_its_customer":"{net} hands it to its customer {to}",
"traceroute.net_hands_it_to_to":"{net} hands it to {to}",
"traceroute.no_path_every_route_between_these":"No path: every route between these cities is down or missing.",
"traceroute.no_working_path_between_these_pops":"no working path between these POPs",
diff --git a/src/styles/40-modal.css b/src/styles/40-modal.css
index 4e1845f..ed4b79c 100644
--- a/src/styles/40-modal.css
+++ b/src/styles/40-modal.css
@@ -10,6 +10,17 @@
.bdg.ever{opacity:.85;border-style:dashed;border-color:var(--rc)}
.bdg.on{opacity:1;border-color:var(--rc);background:#fff;box-shadow:0 2px 0 var(--rc)}
.bdg.on .bi,.bdg.ever .bi{filter:none}
+.bdg .bv{font:900 10px Nunito,sans-serif;letter-spacing:.02em}
+.bdg.on.v-freeze{background:linear-gradient(160deg,#F2FBFF,#D6F1FC);border-color:#5BC0EB;box-shadow:0 2px 0 #5BC0EB,inset 0 0 0 2px #fff}
+.bdg.v-freeze .bv{color:#2A8DB8}
+.bdg.on.v-bgp{background:linear-gradient(160deg,#FFF6E8,#FFD9B8);border-color:#FF5A1F;box-shadow:0 2px 0 #C8102E,0 0 8px rgba(255,90,31,.45)}
+.bdg.v-bgp .bv{color:#C8102E}
+.bdg.ever.v-freeze{border-color:#5BC0EB}.bdg.ever.v-bgp{border-color:#FF5A1F}
+.bshelf{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 8px}
+.bsh{font:800 12px Nunito,sans-serif;border:2px solid #C9CEDD;border-radius:999px;padding:2px 9px;background:#fff;white-space:nowrap}
+.bsh.v-freeze{border-color:#5BC0EB}.bsh.v-oncall{border-color:#FFD23F}.bsh.v-bgp{border-color:#FF5A1F}
+.bsh.cur{box-shadow:0 2px 0 var(--ink)}
+.bvt.v-freeze{color:#2A8DB8;font-weight:900}.bvt.v-bgp{color:#FF5A1F;font-weight:900}
.scn{display:flex;gap:10px;align-items:center;border:2px solid #DDE1EC;border-radius:12px;padding:8px 10px;margin-top:8px}
.scn.wk{border-color:var(--me);background:#FFF0F6}
.scn .nm{font-weight:900}
diff --git a/tests/badges-variants.test.js b/tests/badges-variants.test.js
new file mode 100644
index 0000000..648aaed
--- /dev/null
+++ b/tests/badges-variants.test.js
@@ -0,0 +1,137 @@
+// Badge variants by ruleset preset (2.0): On-call earns the standard badge, Change Freeze a frosted one and BGP at
+// 3 a.m. a fiery one; Sandbox and puzzles earn none. A harder preset upgrades a badge you already have.
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const { load } = require('./harness');
+
+// The preset is read from S.rules.preset until the ruleset feature lands with rulePreset().
+const start = (ev, preset) => {
+ ev("localStorage.removeItem('sot-badges');ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})");
+ if (preset) ev(`S.rules={preset:'${preset}'}`);
+ ev("S.ach={};S.achP={};compute()");
+};
+const earnHello = (ev) => ev("S.pni.push({id:'x',net:'nfx',city:'fra',tier:0});compute();checkBadges()");
+const hof = (ev) => JSON.parse(ev("localStorage.getItem('sot-badges')||'{}'"));
+
+test('every save without a preset plays On-call and earns the standard badge', () => {
+ const { ev, errors } = load();
+ start(ev);
+ assert.equal(ev('badgeVar()'), 'oncall');
+ earnHello(ev);
+ assert.ok(ev('S.ach.hello!==undefined'));
+ assert.equal(ev('S.achP.hello'), 'oncall');
+ assert.deepEqual(hof(ev).hello.vs && Object.keys(hof(ev).hello.vs), ['oncall']);
+ assert.equal(hof(ev).hello.v, 'oncall');
+ assert.deepEqual(errors, []);
+});
+
+test('Change Freeze earns frosted badges and BGP at 3 a.m. fiery ones, shown in the toast and the list', () => {
+ for (const [p, name, cls] of [['freeze', /Freeze-dried/, 'v-freeze'], ['bgp', /Forged at 3 a\.m\./, 'v-bgp']]) {
+ const { ev, dom, errors } = load();
+ start(ev, p);
+ ev("window.__t=[];const _t=toast;toast=(h,...a)=>{window.__t.push(h);return _t(h,...a);}");
+ earnHello(ev);
+ assert.equal(ev('S.achP.hello'), p);
+ assert.match(ev("window.__t.join(' ')"), name, `${p}: the toast names the variant`);
+ ev("UI.left='goals';UI.leftOpen=true;UI.sel=null;renderLeft()");
+ const card = dom.window.document.querySelector(`#leftBody .bdg.on.${cls}`);
+ assert.ok(card, `${p}: the badge list shows the variant`);
+ assert.match(card.textContent, name);
+ assert.equal(hof(ev).hello.v, p, 'remembered on this device');
+ assert.deepEqual(errors, []);
+ }
+});
+
+test('Sandbox and puzzles earn no badges', () => {
+ for (const p of ['sandbox', 'puzzle']) {
+ const { ev, errors } = load();
+ start(ev, p);
+ earnHello(ev);
+ assert.equal(ev('badgeVar()'), null);
+ assert.equal(ev('Object.keys(S.ach).length'), 0, p);
+ assert.deepEqual(errors, []);
+ }
+ const { ev, errors } = load();
+ start(ev);
+ ev("S.mode='sandbox'");
+ earnHello(ev);
+ assert.equal(ev('Object.keys(S.ach).length'), 0, 'the old sandbox mode too');
+ assert.deepEqual(errors, []);
+});
+
+test('a harder preset upgrades a badge, an easier one never downgrades it', () => {
+ const { ev, errors } = load();
+ start(ev, 'freeze');
+ earnHello(ev);
+ const day = ev('S.ach.hello');
+ ev("window.__t=[];const _t=toast;toast=(h,...a)=>{window.__t.push(h);return _t(h,...a);}");
+ ev("S.rules.preset='oncall';checkBadges()");
+ assert.equal(ev('S.achP.hello'), 'oncall', 'On-call beats Change Freeze');
+ assert.match(ev("window.__t.join(' ')"), /Badge upgraded/);
+ ev("S.day+=10;S.rules.preset='bgp';checkBadges()");
+ assert.equal(ev('S.achP.hello'), 'bgp');
+ assert.equal(ev('S.ach.hello'), day, 'the day it was first earned stays');
+ ev("window.__t=[];S.rules.preset='freeze';checkBadges()");
+ assert.equal(ev('S.achP.hello'), 'bgp', 'never downgraded');
+ assert.equal(ev("window.__t.length"), 0, 'and no toast');
+ const h = hof(ev).hello;
+ assert.deepEqual(Object.keys(h.vs).sort(), ['bgp', 'freeze', 'oncall'], 'the collection holds every variant earned');
+ assert.equal(h.v, 'bgp', 'the shelf shows the best one');
+ assert.deepEqual(errors, []);
+});
+
+test('the collection counts badges per variant on this device, and fits a phone', () => {
+ const { ev, dom, errors } = load();
+ ev('window.innerWidth=360');
+ start(ev, 'bgp');
+ earnHello(ev);
+ ev("UI.left='goals';UI.leftOpen=true;UI.sel=null;renderLeft()");
+ const shelf = dom.window.document.querySelector('#leftBody .bshelf');
+ assert.ok(shelf);
+ const total = ev('BADGES.length');
+ assert.match(shelf.textContent, new RegExp(`Forged at 3 a\\.m\\. 1/${total}`));
+ assert.match(shelf.textContent, new RegExp(`Freeze-dried 0/${total}`));
+ assert.ok(dom.window.document.querySelector('#leftBody .bsh.v-bgp.cur'), 'the variant this game earns is marked');
+ assert.match(dom.window.document.getElementById('leftBody').textContent, /forged in fire/);
+ assert.deepEqual(JSON.parse(ev('JSON.stringify(badgeShelf(hof()))')), { freeze: 0, oncall: 0, bgp: 1 });
+ assert.deepEqual(errors, []);
+});
+
+test('old saves and old halls of fame keep loading, as standard badges', () => {
+ const { ev, errors } = load();
+ start(ev);
+ // a 1.x save: S.ach holds days, no S.achP; a 1.x hall of fame: {d, n} per badge
+ ev("localStorage.setItem('sot-badges',JSON.stringify({hello:{d:'2025-01-02',n:'Old'},t1:{d:'2025-03-04',n:'Old'},junk:5}))");
+ ev("const o=JSON.parse(JSON.stringify(S));o.ach={hello:12,t1:'400'};delete o.achP;S=migrate(o)");
+ assert.equal(ev('S.achP.hello'), 'oncall');
+ assert.equal(ev('S.ach.t1'), 400, 'days are numbers');
+ assert.deepEqual(JSON.parse(ev("JSON.stringify(Object.keys(S.achP).sort())")), ['hello', 't1']);
+ const h = JSON.parse(ev('JSON.stringify(hof())'));
+ assert.equal(h.hello.v, 'oncall');
+ assert.equal(h.hello.vs.oncall, '2025-01-02');
+ assert.equal(h.junk, undefined, 'broken entries are dropped');
+ // a hand-edited variant is not trusted
+ ev("const o=JSON.parse(JSON.stringify(S));o.achP={hello:'lava',t1:'bgp'};S=migrate(o)");
+ assert.equal(ev('S.achP.hello'), 'oncall');
+ assert.equal(ev('S.achP.t1'), 'bgp');
+ ev("localStorage.setItem('sot-badges','[1,2]')");
+ assert.equal(ev('JSON.stringify(hof())'), '{}');
+ ev("UI.left='goals';UI.leftOpen=true;renderLeft()");
+ // new games start with an empty variant map
+ ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
+ assert.equal(ev('JSON.stringify(S.achP)'), '{}');
+ assert.deepEqual(errors, []);
+});
+
+test('the share card rings the variant badges', () => {
+ const { ev, errors } = load();
+ start(ev, 'bgp');
+ earnHello(ev);
+ // count the strokes the card draws with a variant badge and with the same badge in its standard look
+ const calls = () => ev("(()=>{const cv=shareCanvas();return cv.getContext('2d').calls.n;})()");
+ const fiery = calls();
+ ev("S.achP.hello='oncall'");
+ const plain = calls();
+ assert.ok(fiery > plain, `the ring and the tally are drawn (${fiery} > ${plain} calls)`);
+ assert.deepEqual(errors, []);
+});
diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js
index a5c557c..a69d199 100644
--- a/tests/helpers/reference-allocation.js
+++ b/tests/helpers/reference-allocation.js
@@ -6,7 +6,7 @@ module.exports = `
if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue;
Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++;
const candidates=E.filter(e=>e.used(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
for(let i=0;i1e-6;){
let j=i+1;while(j {
+ ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;delete S.done.t1;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=500");
+ ev("S.transit=[];S.ixp={};S.peers={};S.pni=[];S.grace=null;for(const n of t1Need())S.pni.push({id:'p'+n.id,net:n.id,city:'fra',tier:2});compute()");
+};
+
+test('cones are built once at load and hold customers of customers', () => {
+ const { ev, errors } = load();
+ assert.equal(ev("CONE.voc.includes('ddo')&&CONE.voc.includes('spn')"), true, 'Hocus Pocus brings its own customers');
+ // Doodoo buys from Hocus Pocus, which buys from Not That Telecom: two levels down
+ assert.equal(ev("NET.ddo.up.includes('voc')&&NET.voc.up.includes('ntt')"), true);
+ assert.equal(ev("CONE_S.ntt.has('ddo')"), true, 'the Tier 1 cone is transitive');
+ assert.equal(ev("CONE.ntt[0]"), 'ntt', 'a network is first in its own cone');
+ assert.equal(ev("PNI_NETS===CONE"), true);
+ assert.equal(ev("ANC.ddo[0]"), 'voc', 'nearest upstream first');
+ assert.equal(ev("NETS.filter(n=>n.tail).every(n=>n.up&&n.up.length&&n.up.every(u=>NET[u]))"), true, 'the long tail buys transit');
+ assert.equal(ev("NETS.filter(n=>n.tail).every(n=>ANC[n.id].some(u=>NET[u].type==='t1'))"), true, 'from a Tier 1, directly or through a carrier');
+ assert.equal(ev("NET.tail45.up.join()"), 'mag', 'Auckland has no Tier 1: Hobbit Hole buys from a carrier that is there');
+ assert.equal(ev("NETS.filter(n=>n.tail).map(n=>n.up.join('+')).join()"), ev("NETS.filter(n=>n.tail).map(n=>tailUp(n.name,n.pops).join('+')).join()"), 'stable: picked by name');
+ // Australians buy only from Australian carriers, so a Tier 1 PNI is still no back door into Australia.
+ assert.equal(ev("['opt','tpr','abb','npt','lpt','lnt','pnt','stb','blg'].some(id=>t1Need().some(t=>CONE_S[t.id].has(id)))"), false);
+ assert.deepEqual(errors, []);
+});
+
+test('a transit-free network with PNIs to every Tier 1 reaches the long tail through their cones', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ const tail = ev("NETS.find(n=>n.tail&&n.pops.includes('akl')).id");
+ for (const id of ['tail0', 'tail38', tail, 'sky', 'kys', 'tim']) {
+ assert.equal(ev(`!!R.reachable.${id}`), true, `${id} is reachable`);
+ assert.equal(ev(`!!R.nt.${id}`), true, `${id} without transit`);
+ assert.equal(ev(`!!R.cone.${id}`), true, `${id} through a peer's cone`);
+ }
+ // the traffic really goes over the PNI with the upstream, not some made-up exit
+ const up = ev("NET.tail0.up[0]");
+ assert.ok(ev("(R.netEg.tail0||{}).p") > 0, 'over a PNI');
+ assert.ok(ev(`R.usePni['p${up}']`) > 0, 'the PNI with its upstream carries it');
+ // the traceroute shows the hand-off to the customer and an AS path one hop longer
+ const tr = JSON.parse(ev("JSON.stringify(traceroute('fra',{net:'tail0'}))"));
+ assert.match(tr.text, /hands it to its customer/);
+ assert.equal(tr.asPath.length, 3, 'you, the Tier 1, the customer');
+ assert.equal(tr.asPath[1], ev(`NET.${up}.asn`), 'through the upstream it buys transit from');
+ assert.match(tr.why, /customers come after direct peers/);
+ assert.deepEqual(errors, []);
+});
+
+test('a network in nobody\'s cone still needs reaching directly', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ // Doitsche Telekomm buys from no one: no Tier 1 PNI reaches it
+ assert.equal(ev("(NET.dtk.up||[]).length"), 0);
+ assert.equal(ev("R.reachable.dtk"), false);
+ assert.equal(ev("isTier1()"), false);
+ assert.match(ev('t1Why()'), /nobody you peer with sells transit to/);
+ // peer with every island directly and the win comes
+ ev("for(const n of NETS)if(!R.reachable[n.id])S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});for(const n of NETS)if(n.pops.length&&!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};compute()");
+ assert.ok(ev("R.reach") > 0.999, `reach ${ev('R.reach')}`);
+ assert.equal(ev("isTier1()"), true);
+ assert.deepEqual(errors, []);
+});
+
+test('the long tail no longer stands between you and Tier 1', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ // peer directly only with the networks in nobody's cone, never with the long tail itself
+ ev("for(const n of NETS)if(!R.reachable[n.id]){if(!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});}compute()");
+ assert.equal(ev("S.pni.some(p=>NET[p.net].tail)"), false, 'no session with any long-tail network');
+ assert.equal(ev("NETS.filter(n=>n.tail).every(n=>R.reachable[n.id])"), true);
+ assert.equal(ev("isTier1()"), true);
+ // the peers you need directly are all real networks of some size, and fewer than before
+ const islands = ev("S.pni.filter(p=>p.id[0]==='i').length");
+ assert.ok(islands < 70, `${islands} networks to peer with directly`);
+ assert.deepEqual(errors, []);
+});
+
+test('a peer\'s cone comes after direct peering and before transit, so peering widely still pays', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ ev("ACT.buyTransit({city:'fra',net:'cog',tier:2});S.pni=S.pni.filter(p=>p.net!=='cog');compute()");
+ // a Cogentle customer is reached through another Tier 1's cone only if it buys from one; transit is the fallback
+ const id = ev("NETS.find(n=>n.tail&&n.up.length===1&&n.up[0]==='tly').id");
+ assert.ok(ev(`(R.netEg.${id}||{}).p`) > 0, 'over the PNI with its upstream, not over transit');
+ assert.equal(ev(`(R.netEg.${id}||{}).t||0`), 0);
+ // a direct session beats the cone: peer with it at the exchange and its traffic moves there
+ ev(`S.pops.fra.bb.d=500;ACT.buyIx({city:'fra',tier:1,signed:true});ACT.rs({city:'fra'});compute()`);
+ if (ev(`ixSessions('fra').has('${id}')`)) {
+ assert.ok(ev(`(R.netEg.${id}||{}).ix`) > 0, 'direct peering wins over the cone');
+ assert.equal(ev(`(R.netEg.${id}||{}).p||0`), 0);
+ }
+ // an IX session also brings the member's customers along
+ assert.equal(ev("ixSessions('fra').has('gsl')"), true);
+ const down = ev("DOWN.gsl.find(id=>!t1Need().some(t=>CONE_S[t.id].has(id))&&!ixSessions('fra').has(id))||''");
+ if (down) assert.equal(ev(`R.reachable.${down}`), true, `${down} comes along with Glowball Sakura Lager's session`);
+ assert.deepEqual(errors, []);
+});
+
+test('old saves keep their win: cones only ever add reach', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ ev("for(const n of NETS)if(!R.reachable[n.id]){if(!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});}compute()");
+ ev("S.won=true;S.done.t1=S.day;S.t1Now=true");
+ // a save from before 2.0, with an older Tier 1 set and no record of cones, loads and is still Tier 1
+ ev("const o=JSON.parse(JSON.stringify(S));o.t1v=2;S=migrate(o);compute()");
+ assert.equal(ev("S.won"), true);
+ assert.equal(ev("isTier1()"), true);
+ assert.equal(ev("tierLabel()"), 'Tier 1');
+ // and reach with cones is never lower than reach without: every exit still reaches what it did
+ const before = ev("R.reach");
+ ev("for(const id of NET_IDS){CONE_S[id]=new Set([id]);DOWN[id]=[];}compute()");
+ assert.ok(ev("R.reach") <= before + 1e-9, 'switching cones off can only lose reach');
+ assert.deepEqual(errors, []);
+});
+
+test('the Road to Tier 1 card and the network list explain the cone, on a phone too', () => {
+ for (const w of [1280, 360]) {
+ const { ev, dom, errors } = load();
+ ev(`window.innerWidth=${w}`);
+ t1Club(ev);
+ ev("UI.left='goals';UI.leftOpen=true;UI.sel=null;renderLeft()");
+ const txt = dom.window.document.getElementById('leftBody').textContent;
+ assert.match(txt, /Road to Tier 1/);
+ assert.match(txt, /their customers come along for free/);
+ assert.match(txt, /\d+ networks already come along with a peer/);
+ ev("ACT.netFocus({id:'tail0'})");
+ assert.match(dom.window.document.getElementById('leftBody').textContent, /Reached through the customer cone of/);
+ ev("S.pni=[];compute();ACT.netFocus({id:'tail0'})");
+ assert.match(dom.window.document.getElementById('leftBody').textContent, /Buys transit from .*Peer with/);
+ assert.match(ev("GOALS.find(g=>g.id==='t1').d"), /customers come along for free/);
+ assert.deepEqual(errors, [], `${w}px`);
+ }
+});
+
+test('routing with cones costs about what it did: exits are asked once, cones are built at load', () => {
+ const { ev, errors } = load();
+ t1Club(ev);
+ ev("for(const n of NETS.filter(n=>!n.tail&&!n.cn).slice(0,40))for(const c of ['fra','ams','lon']){if(!S.pops[c])S.pops[c]={day:0,bb:{d:400},boost:0,down:0,routers:4,gen:true};S.pni.push({id:n.id+c,net:n.id,city:c,tier:2});}compute()");
+ const t = ev("(()=>{for(let i=0;i<3;i++)compute();const a=performance.now();for(let i=0;i<10;i++)compute();return (performance.now()-a)/10;})()");
+ const plain = ev(`(()=>{const keep={};for(const id of NET_IDS){keep[id]=[CONE_S[id],DOWN[id]];CONE_S[id]=new Set([id]);DOWN[id]=[];}
+ for(let i=0;i<3;i++)compute();const a=performance.now();for(let i=0;i<10;i++)compute();const r=(performance.now()-a)/10;for(const id of NET_IDS){CONE_S[id]=keep[id][0];DOWN[id]=keep[id][1];}return r;})()`);
+ assert.ok(t < plain * 2 + 20, `compute() with cones ${t.toFixed(1)} ms vs without ${plain.toFixed(1)} ms`);
+ assert.deepEqual(errors, []);
+});