From 2d88a04584692f06854052ec639eb5da0c8390fd Mon Sep 17 00:00:00 2001 From: Lambro-codes <81650630+Lambro-codes@users.noreply.github.com> Date: Wed, 4 Nov 2026 04:32:16 +0100 Subject: [PATCH] feat(ui): show billions of dollars and petabits per second Money shows $1.20B and bandwidth 1.00 Pbps instead of running on in millions and terabits, including the NOC graph and the fibre labels on the map. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + src/game/10-catalog/50-dark-fiber.js | 2 +- src/game/70-rules/10-helpers.js | 4 ++-- tests/big-numbers.test.js | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/big-numbers.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index fbebed3..664d099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Money now shows billions (`$1.20B`) and bandwidth shows petabits (`1.00 Pbps`) instead of running on in millions and terabits, including on the NOC graph and the fiber labels on the map. - Every capital in Africa is on the map, which puts every capital of the world in the game: 33 new cities from Porto-Novo, Bamako and Niamey to Khartoum, Juba, Mogadishu, Brazzaville, Tripoli, Rabat and Pretoria. Each country brings its real telcos, Nigeria gets its wholesale backbone up to Abuja, and the island capitals of the Comoros, São Tomé and Equatorial Guinea sit on their real cables. - Every capital in South, East and Southeast Asia and the Pacific is on the map: Thimphu, Kathmandu, Bandar Seri Begawan, Phnom Penh, Vientiane, Ulaanbaatar, Naypyidaw, Pyongyang, Dili, Hanoi and Wellington, with the island capitals Tarawa, Palikir, Yaren, Funafuti and Port Vila. Each country brings its real telcos, North Korea reaches the world only through China and Russia, and the islands hang on their real cables. - Every capital in the Middle East, the Caucasus and Central Asia is on the map, from Yerevan and Baku to Kabul, Tehran, Baghdad, Jerusalem, Amman, Kuwait City, Beirut, Damascus, Sanaa and Manama, with Ankara and Islamabad. Each country brings its real telcos, and Bahrain is an island on the Gulf's cables. diff --git a/src/game/10-catalog/50-dark-fiber.js b/src/game/10-catalog/50-dark-fiber.js index f6286a9..ef602d1 100644 --- a/src/game/10-catalog/50-dark-fiber.js +++ b/src/game/10-catalog/50-dark-fiber.js @@ -20,7 +20,7 @@ const dfLeaseMo=km=>Math.round(400+km*1.0); const dfBuildCost=km=>Math.round((25000+km*120)*hwMul('build')); const dfBuildDays=km=>leadDays(Math.round(120+km*0.25)),IRU_DAYS=30; const ampCount=km=>Math.max(0,Math.floor(km/AMP_EVERY)); -const fmtCap=g=>g>=1000?(+(g/1000).toFixed(1))+'T':g+'G'; +const fmtCap=g=>g>=999950?(+(g/1e6).toFixed(g>=9.995e6?0:1))+'P':g>=1000?(+(g/1000).toFixed(1))+'T':g+'G'; const WAVECO=['Zay-No Fiber','Loomin’ Technologies','Clown Castle Fiber','Bolt Technology','youNetworks','G&T (Gin and Transit)']; const MONTHS=[tr('common.jan'),tr('common.feb'),tr('common.mar'),tr('common.apr'),tr('common.may'),tr('common.jun'),tr('common.jul'),tr('common.aug'),tr('common.sep'),tr('common.oct'),tr('common.nov'),tr('common.dec')]; const REG={AM:tr('common.americas'),SA:tr('common.south_america'),EU:tr('common.europe'),AF:tr('common.africa'),AS:tr('common.asia'),OC:tr('common.oceania')}; diff --git a/src/game/70-rules/10-helpers.js b/src/game/70-rules/10-helpers.js index 891a223..d4eb4b3 100644 --- a/src/game/70-rules/10-helpers.js +++ b/src/game/70-rules/10-helpers.js @@ -1,6 +1,6 @@ /* ================= HELPERS ================= */ -const fmt$=v=>{const a=Math.abs(v),s=v<0?'-':'';if(a>=1e6)return s+'$'+(a/1e6).toFixed(a>=1e7?1:2)+'M';if(a>=1e3)return s+'$'+(a/1e3).toFixed(a>=1e5?0:1)+'k';return s+'$'+Math.round(a);}; -const fmtG=g=>g>=1000?(g/1000).toFixed(g>=10000?1:2)+' Tbps':(g>=100?g.toFixed(0):g.toFixed(1))+' Gbps'; +const fmt$=v=>{const a=Math.abs(v),s=v<0?'-':'';if(a>=999.95e6)return s+'$'+(a/1e9).toFixed(a>=9.995e9?1:2)+'B';if(a>=1e6)return s+'$'+(a/1e6).toFixed(a>=1e7?1:2)+'M';if(a>=1e3)return s+'$'+(a/1e3).toFixed(a>=1e5?0:1)+'k';return s+'$'+Math.round(a);}; +const fmtG=g=>g>=999950?(g/1e6).toFixed(g>=9.995e6?1:2)+' Pbps':g>=1000?(g/1000).toFixed(g>=10000?1:2)+' Tbps':(g>=100?g.toFixed(0):g.toFixed(1))+' Gbps'; const pct=x=>Math.round(x*100)+'%'; // Reach never rounds up to 100%: Tier 1 needs more than 99.9%, and 99.6% must not look like a full house (#73). const reachPct=x=>x>0.999?'100%':x>=0.99?(Math.floor(x*1000)/10).toFixed(1)+'%':pct(x); diff --git a/tests/big-numbers.test.js b/tests/big-numbers.test.js new file mode 100644 index 0000000..2fbe509 --- /dev/null +++ b/tests/big-numbers.test.js @@ -0,0 +1,24 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +test('money and bandwidth keep a readable unit past a billion dollars and a petabit', () => { + const { ev, errors } = load(); + const f = x => ev(x); + assert.equal(f('fmt$(1.5e6)'), '$1.50M'); + assert.equal(f('fmt$(250e6)'), '$250.0M'); + assert.equal(f('fmt$(999.97e6)'), '$1.00B'); + assert.equal(f('fmt$(1.2e9)'), '$1.20B'); + assert.equal(f('fmt$(-12.5e9)'), '-$12.5B'); + assert.equal(f('fmt$(120e9)'), '$120.0B'); + assert.equal(f('fmtG(2500)'), '2.50 Tbps'); + assert.equal(f('fmtG(999000)'), '999.0 Tbps'); + assert.equal(f('fmtG(999990)'), '1.00 Pbps'); + assert.equal(f('fmtG(12e6)'), '12.0 Pbps'); + // The map's fiber labels and the NOC graph axes use the short form. + assert.equal(f('fmtCap(334000)'), '334T'); + assert.equal(f('fmtCap(1024000)'), '1P'); + assert.equal(f('fmtCap(3152700)'), '3.2P'); + assert.equal(f('fmtCap(400)'), '400G'); + assert.deepEqual(errors, []); +});