From 12ef18f9e62baa91c110031e928ec627fd43b991 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 10:48:24 +0100 Subject: [PATCH] Puzzles: eighteen puzzles in five packs with traffic, and their tests Fat Pipes, Router Rodeo, Traffic Cops, N-1 Club and Grand Tour. Every puzzle has 1-star and 3-star references played through the player's actions; budgets sit over the cheapest 3-star build the solver found, and the tests check that no single change keeps three stars for less. --- site/i18n/de.js | 2 +- site/i18n/es.js | 2 +- site/i18n/fr.js | 2 +- site/i18n/it.js | 2 +- site/i18n/pt.js | 2 +- site/puzzles/weekly/2026-W44.json | 2 +- site/puzzles/weekly/2026-W45.json | 2 +- site/puzzles/weekly/2026-W46.json | 2 +- site/puzzles/weekly/index.json | 2 +- src/game/60-features/90-puzzles-data.js | 32 +- src/i18n/en.js | 2 +- tests/puzzles.test.js | 675 +++++++++++++----------- 12 files changed, 403 insertions(+), 324 deletions(-) diff --git a/site/i18n/de.js b/site/i18n/de.js index f7a33b8..7fd624d 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2947,7 +2947,6 @@ "puzzles.every_star_in_this_pack_is":"Alle Sterne in diesem Paket gehören dir.", "puzzles.everything_at_once_across_oceans":"Alles auf einmal, über Ozeane. Knappe Budgets.", "puzzles.fat_pipes":"Dicke Rohre", -"puzzles.five_small_cities_one_small_router":"Fünf Städte, je ein paar Gigabit, und ein Router mit acht Ports. Erst zählen, dann graben.", "puzzles.fjord_focus":"Fjord im Fokus", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"Leitung {a} ⇄ {b}", @@ -3035,6 +3034,7 @@ "puzzles.sao_paulo_to_miami_before_the":"São Paulo nach Miami, bevor der Caipirinha warm wird.", "puzzles.sea_to_shining_sea":"Von Küste zu Küste", "puzzles.share_line":"Series of Tubes Puzzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Sechs Städte, je ein paar Gigabit, und ein Router mit acht Ports. Erst zählen, dann graben.", "puzzles.size":"Größe", "puzzles.small_networks_real_traffic":"Kleine Netze, echter Traffic", "puzzles.spent_x":"Ausgegeben {x}", diff --git a/site/i18n/es.js b/site/i18n/es.js index a8b6476..d300f54 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2945,7 +2945,6 @@ "puzzles.every_star_in_this_pack_is":"Todas las estrellas de este paquete son tuyas.", "puzzles.everything_at_once_across_oceans":"Todo a la vez, cruzando océanos. Presupuestos ajustados.", "puzzles.fat_pipes":"Tubos gordos", -"puzzles.five_small_cities_one_small_router":"Cinco ciudades, pocos gigas cada una, y un router con ocho puertos. Cuenta antes de cavar.", "puzzles.fjord_focus":"Rumbo al fiordo", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}", @@ -3033,6 +3032,7 @@ "puzzles.sao_paulo_to_miami_before_the":"De São Paulo a Miami antes de que se caliente la caipiriña.", "puzzles.sea_to_shining_sea":"De costa a costa", "puzzles.share_line":"Series of Tubes puzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Seis ciudades, pocos gigas cada una, y un router con ocho puertos. Cuenta antes de cavar.", "puzzles.size":"Tamaño", "puzzles.small_networks_real_traffic":"Redes pequeñas, tráfico de verdad", "puzzles.spent_x":"Gastado {x}", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index b4c714b..b84b1a5 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2945,7 +2945,6 @@ "puzzles.every_star_in_this_pack_is":"Toutes les étoiles de ce pack sont à toi.", "puzzles.everything_at_once_across_oceans":"Tout à la fois, par-delà les océans. Budgets serrés.", "puzzles.fat_pipes":"Gros tuyaux", -"puzzles.five_small_cities_one_small_router":"Cinq villes, quelques gigas chacune, et un routeur à huit ports. Compte avant de creuser.", "puzzles.fjord_focus":"Cap sur le fjord", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"Circuit {a} ⇄ {b}", @@ -3033,6 +3032,7 @@ "puzzles.sao_paulo_to_miami_before_the":"São Paulo–Miami avant que la caïpirinha ne tiédisse.", "puzzles.sea_to_shining_sea":"D’une côte à l’autre", "puzzles.share_line":"Series of Tubes puzzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Six villes, quelques gigas chacune, et un routeur à huit ports. Compte avant de creuser.", "puzzles.size":"Taille", "puzzles.small_networks_real_traffic":"Petits réseaux, vrai trafic", "puzzles.spent_x":"Dépensé {x}", diff --git a/site/i18n/it.js b/site/i18n/it.js index 1a0e9a1..94f2d17 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2945,7 +2945,6 @@ "puzzles.every_star_in_this_pack_is":"Tutte le stelle di questo pacchetto sono tue.", "puzzles.everything_at_once_across_oceans":"Tutto insieme, oltre gli oceani. Budget stretti.", "puzzles.fat_pipes":"Tubi grossi", -"puzzles.five_small_cities_one_small_router":"Cinque città, pochi giga ciascuna, e un router con otto porte. Conta prima di scavare.", "puzzles.fjord_focus":"Fuoco sul fiordo", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}", @@ -3033,6 +3032,7 @@ "puzzles.sao_paulo_to_miami_before_the":"Da São Paulo a Miami prima che la caipirinha si scaldi.", "puzzles.sea_to_shining_sea":"Da costa a costa", "puzzles.share_line":"Series of Tubes puzzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Sei città, pochi giga ciascuna, e un router con otto porte. Conta prima di scavare.", "puzzles.size":"Taglia", "puzzles.small_networks_real_traffic":"Reti piccole, traffico vero", "puzzles.spent_x":"Speso {x}", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index c65ace3..38ee4f2 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2945,7 +2945,6 @@ "puzzles.every_star_in_this_pack_is":"Todas as estrelas deste pacote são suas.", "puzzles.everything_at_once_across_oceans":"Tudo de uma vez, atravessando oceanos. Orçamentos apertados.", "puzzles.fat_pipes":"Canos grossos", -"puzzles.five_small_cities_one_small_router":"Cinco cidades, poucos gigas cada, e um router com oito portas. Conte antes de cavar.", "puzzles.fjord_focus":"Foco no fiorde", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}", @@ -3033,6 +3032,7 @@ "puzzles.sao_paulo_to_miami_before_the":"De São Paulo a Miami antes que a caipirinha esquente.", "puzzles.sea_to_shining_sea":"De costa a costa", "puzzles.share_line":"Series of Tubes puzzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Seis cidades, poucos gigas cada, e um router com oito portas. Conte antes de cavar.", "puzzles.size":"Tamanho", "puzzles.small_networks_real_traffic":"Redes pequenas, tráfego de verdade", "puzzles.spent_x":"Gasto {x}", diff --git a/site/puzzles/weekly/2026-W44.json b/site/puzzles/weekly/2026-W44.json index 128937c..be7a930 100644 --- a/site/puzzles/weekly/2026-W44.json +++ b/site/puzzles/weekly/2026-W44.json @@ -1 +1 @@ -{"v":1,"key":"2026-W44","theme":"ring","cities":["mil","vie","rom","mrs","stg"],"via":[],"avoid":[],"budget":240000,"twist":{"ring":true},"name":{"l":"puzzles_weekly.name_ring_around_reg","p":{"reg":"EU"}},"joke":{"l":"puzzles_weekly.joke_one_ring_through_every_pop","p":{}},"ref":{"one":226300,"three":226300}} +{"v":2,"key":"2026-W44","theme":"ring","cities":["ham","fra","bru","dus"],"src":["ham"],"dem":[{"t":"eye","a":"fra","g":30},{"t":"eye","a":"bru","g":60},{"t":"eye","a":"dus","g":60}],"via":[],"avoid":[],"budget":360000,"twist":{"ring":true},"name":{"l":"puzzles_weekly.name_one_ring_to_rule_reg","p":{"reg":"EU"}},"joke":{"l":"puzzles_weekly.joke_a_ring_survives_one_cut","p":{}},"ref":{"one":341708,"three":341708}} diff --git a/site/puzzles/weekly/2026-W45.json b/site/puzzles/weekly/2026-W45.json index 413d8ac..fc475a5 100644 --- a/site/puzzles/weekly/2026-W45.json +++ b/site/puzzles/weekly/2026-W45.json @@ -1 +1 @@ -{"v":1,"key":"2026-W45","theme":"tour","cities":["abj","fih","acc","dkr"],"via":["lag"],"avoid":[],"budget":740000,"twist":{},"name":{"l":"puzzles_weekly.name_tour_de_reg","p":{"reg":"AF"}},"joke":{"l":"puzzles_weekly.joke_a_road_trip_for_photons","p":{}},"ref":{"one":457084,"three":695668}} +{"v":2,"key":"2026-W45","theme":"tour","cities":["abj","fih","acc","dkr"],"src":["abj"],"dem":[{"t":"eye","a":"fih","g":20},{"t":"eye","a":"acc","g":10},{"t":"eye","a":"dkr","g":30}],"via":["lag"],"avoid":[],"budget":1750000,"twist":{},"name":{"l":"puzzles_weekly.name_tour_de_reg","p":{"reg":"AF"}},"joke":{"l":"puzzles_weekly.joke_a_road_trip_for_photons","p":{}},"ref":{"one":989200,"three":1657240}} diff --git a/site/puzzles/weekly/2026-W46.json b/site/puzzles/weekly/2026-W46.json index d7b9f26..11a7fbf 100644 --- a/site/puzzles/weekly/2026-W46.json +++ b/site/puzzles/weekly/2026-W46.json @@ -1 +1 @@ -{"v":1,"key":"2026-W46","theme":"ocean","cities":["for","ssa","lad","lun"],"via":["dla","sao"],"avoid":[],"budget":2060000,"twist":{},"name":{"l":"puzzles_weekly.name_across_the_big_blue","p":{}},"joke":{"l":"puzzles_weekly.joke_somewhere_between_a_and_b","p":{"a":"for","b":"lad"}},"ref":{"one":943664,"three":1959268}} +{"v":2,"key":"2026-W46","theme":"ocean","cities":["for","ssa","lad","lun"],"src":["for"],"dem":[{"t":"eye","a":"ssa","g":8},{"t":"eye","a":"lad","g":5},{"t":"eye","a":"lun","g":8}],"via":["sao","dla"],"avoid":[],"budget":4520000,"twist":{},"name":{"l":"puzzles_weekly.name_sea_you_in_b","p":{"b":"lad"}},"joke":{"l":"puzzles_weekly.joke_somewhere_between_a_and_b","p":{"a":"for","b":"lad"}},"ref":{"one":2368700,"three":4296628}} diff --git a/site/puzzles/weekly/index.json b/site/puzzles/weekly/index.json index 8955841..e112cc1 100644 --- a/site/puzzles/weekly/index.json +++ b/site/puzzles/weekly/index.json @@ -1 +1 @@ -{"v":1,"weeks":["2026-W44","2026-W45","2026-W46"]} +{"v":2,"weeks":["2026-W44","2026-W45","2026-W46"]} diff --git a/src/game/60-features/90-puzzles-data.js b/src/game/60-features/90-puzzles-data.js index 1d64d54..b9c611e 100644 --- a/src/game/60-features/90-puzzles-data.js +++ b/src/game/60-features/90-puzzles-data.js @@ -15,22 +15,22 @@ const PZ_PACKS=[ const PZ=[ {id:'hello',pack:'hello',n:tr('puzzles.hello_world'),j:tr('puzzles.every_internet_starts_with_one_tube'),src:['nyc'],dem:[{t:'eye',a:'lon',g:8}],budget:0}, {id:'eurotrip',pack:'hello',n:tr('puzzles.euro_trip'),j:tr('puzzles.three_cities_two_currencies_one_very'),src:['ams'],dem:[{t:'eye',a:'lon',g:30},{t:'eye',a:'fra',g:60}],budget:0}, - {id:'bigboat',pack:'hello',n:tr('puzzles.a_bigger_boat'),j:tr('puzzles.paris_wants_150g_one_100g_wave'),src:['fra'],dem:[{t:'eye',a:'par',g:150}],budget:1}, - {id:'shining',pack:'hello',n:tr('puzzles.sea_to_shining_sea'),j:tr('puzzles.four_cities_one_continent_and_a'),src:['nyc'],dem:[{t:'eye',a:'chi',g:40},{t:'eye',a:'dal',g:30},{t:'eye',a:'sjc',g:60}],budget:1}, - {id:'downunder',pack:'hello',n:tr('puzzles.down_under_up_and_running'),j:tr('puzzles.one_very_big_island_and_a'),src:['syd'],dem:[{t:'eye',a:'mel',g:50},{t:'eye',a:'bne',g:30},{t:'eye',a:'adl',g:20}],budget:1}, - {id:'edgelord',pack:'rodeo',n:tr('puzzles.edge_lord'),j:tr('puzzles.london_wants_half_a_terabit_your'),src:['ams'],dem:[{t:'eye',a:'lon',g:500}],budget:1}, - {id:'hubcap',pack:'rodeo',n:tr('puzzles.hub_cap'),j:tr('puzzles.all_of_europe_s_cat_videos'),src:['lon'],dem:[{t:'eye',a:'ams',g:150},{t:'eye',a:'par',g:150},{t:'eye',a:'fra',g:120}],budget:1}, - {id:'ports',pack:'rodeo',n:tr('puzzles.port_authority'),j:tr('puzzles.five_small_cities_one_small_router'),src:['zrh'],dem:[{t:'eye',a:'mil',g:8},{t:'eye',a:'muc',g:8},{t:'eye',a:'fra',g:8},{t:'eye',a:'par',g:8},{t:'eye',a:'vie',g:8}],budget:1}, - {id:'flash',pack:'cops',n:tr('puzzles.flash_boys'),j:tr('puzzles.traders_paid_millions_to_shave_milliseconds'),src:['nyc'],dem:[{t:'l2',a:'nyc',b:'lon',g:10,ms:26},{t:'eye',a:'lon',g:80,be:1}],budget:1}, - {id:'baltic',pack:'cops',n:tr('puzzles.baltic_shortcut'),j:tr('puzzles.the_road_to_tallinn_is_short'),src:['fra'],dem:[{t:'eye',a:'tll',g:60},{t:'l2',a:'fra',b:'tll',g:10,ms:8.8}],via:['hel'],budget:1}, - {id:'fjord',pack:'cops',n:tr('puzzles.fjord_focus'),j:tr('puzzles.the_oil_rigs_want_their_numbers'),src:['par'],dem:[{t:'eye',a:'svg',g:30},{t:'l2',a:'par',b:'svg',g:10,ms:7.2}],via:['lon'],budget:1}, - {id:'braces',pack:'n1',n:tr('puzzles.belt_and_braces'),j:tr('puzzles.two_cables_across_the_atlantic_because'),src:['nyc'],dem:[{t:'eye',a:'lon',g:60},{t:'eye',a:'dub',g:40}],budget:1}, - {id:'sharks',pack:'n1',n:tr('puzzles.the_shark_tank'),j:tr('puzzles.the_sharks_have_been_biting_again'),src:['lis'],dem:[{t:'eye',a:'mad',g:40},{t:'eye',a:'par',g:60},{t:'eye',a:'mil',g:30}],via:['bcn','mrs'],noSub:true,budget:1}, - {id:'nofra',pack:'n1',n:tr('puzzles.not_through_frankfurt'),j:tr('puzzles.de_kicks_sales_has_your_number'),src:['ams'],dem:[{t:'eye',a:'ber',g:50},{t:'eye',a:'muc',g:50},{t:'eye',a:'zrh',g:40}],via:['ham','dus'],avoid:['fra'],budget:1}, - {id:'fire',pack:'n1',n:tr('puzzles.ring_of_fire'),j:tr('puzzles.four_cities_four_cables_one_ring'),src:['tok'],dem:[{t:'eye',a:'hkg',g:20},{t:'eye',a:'sin',g:20},{t:'eye',a:'syd',g:10}],ring:true,budget:1}, - {id:'suez',pack:'final',n:tr('puzzles.suez_you_later'),j:tr('puzzles.frankfurt_to_singapore_the_short_way'),src:['fra'],dem:[{t:'l2',a:'fra',b:'sin',g:10,ms:68},{t:'eye',a:'sin',g:30,be:1}],via:['mrs','bom'],budget:1}, - {id:'kiwi',pack:'final',n:tr('puzzles.kiwi_fruit_salad'),j:tr('puzzles.new_zealand_is_far_from_everything'),src:['sea'],dem:[{t:'eye',a:'akl',g:20},{t:'eye',a:'syd',g:40}],via:['hnl','suv','lax'],budget:1}, - {id:'samba',pack:'final',n:tr('puzzles.samba_sprint'),j:tr('puzzles.sao_paulo_to_miami_before_the'),src:['mia'],dem:[{t:'l2',a:'sao',b:'mia',g:10,ms:45},{t:'eye',a:'sao',g:40},{t:'eye',a:'rio',g:20,be:1}],via:['for'],budget:1}, + {id:'bigboat',pack:'hello',n:tr('puzzles.a_bigger_boat'),j:tr('puzzles.paris_wants_150g_one_100g_wave'),src:['fra'],dem:[{t:'eye',a:'par',g:150}],budget:175000}, + {id:'shining',pack:'hello',n:tr('puzzles.sea_to_shining_sea'),j:tr('puzzles.four_cities_one_continent_and_a'),src:['nyc'],dem:[{t:'eye',a:'chi',g:40},{t:'eye',a:'dal',g:30},{t:'eye',a:'sjc',g:60}],budget:715000}, + {id:'downunder',pack:'hello',n:tr('puzzles.down_under_up_and_running'),j:tr('puzzles.one_very_big_island_and_a'),src:['syd'],dem:[{t:'eye',a:'mel',g:50},{t:'eye',a:'bne',g:30},{t:'eye',a:'adl',g:20}],budget:585000}, + {id:'edgelord',pack:'rodeo',n:tr('puzzles.edge_lord'),j:tr('puzzles.london_wants_half_a_terabit_your'),src:['ams'],dem:[{t:'eye',a:'lon',g:500}],budget:240000}, + {id:'hubcap',pack:'rodeo',n:tr('puzzles.hub_cap'),j:tr('puzzles.all_of_europe_s_cat_videos'),src:['lon'],dem:[{t:'eye',a:'ams',g:150},{t:'eye',a:'par',g:150},{t:'eye',a:'fra',g:120}],budget:455000}, + {id:'ports',pack:'rodeo',n:tr('puzzles.port_authority'),j:tr('puzzles.six_cities_a_few_gigs_each'),src:['zrh'],dem:[{t:'eye',a:'mil',g:12},{t:'eye',a:'muc',g:12},{t:'eye',a:'fra',g:12},{t:'eye',a:'par',g:12},{t:'eye',a:'vie',g:12},{t:'eye',a:'prg',g:12}],budget:470000}, + {id:'flash',pack:'cops',n:tr('puzzles.flash_boys'),j:tr('puzzles.traders_paid_millions_to_shave_milliseconds'),src:['nyc'],dem:[{t:'l2',a:'nyc',b:'lon',g:10,ms:26},{t:'eye',a:'lon',g:80,be:1}],budget:660000}, + {id:'baltic',pack:'cops',n:tr('puzzles.baltic_shortcut'),j:tr('puzzles.the_road_to_tallinn_is_short'),src:['fra'],dem:[{t:'eye',a:'tll',g:60},{t:'l2',a:'fra',b:'tll',g:10,ms:8.8}],via:['hel'],budget:285000}, + {id:'fjord',pack:'cops',n:tr('puzzles.fjord_focus'),j:tr('puzzles.the_oil_rigs_want_their_numbers'),src:['par'],dem:[{t:'eye',a:'svg',g:30},{t:'l2',a:'par',b:'svg',g:10,ms:7.2}],via:['lon'],budget:265000}, + {id:'braces',pack:'n1',n:tr('puzzles.belt_and_braces'),j:tr('puzzles.two_cables_across_the_atlantic_because'),src:['nyc'],dem:[{t:'eye',a:'lon',g:60},{t:'eye',a:'dub',g:40}],budget:840000}, + {id:'sharks',pack:'n1',n:tr('puzzles.the_shark_tank'),j:tr('puzzles.the_sharks_have_been_biting_again'),src:['lis'],dem:[{t:'eye',a:'mad',g:40},{t:'eye',a:'par',g:60},{t:'eye',a:'mil',g:30}],via:['bcn','mrs'],noSub:true,budget:450000}, + {id:'nofra',pack:'n1',n:tr('puzzles.not_through_frankfurt'),j:tr('puzzles.de_kicks_sales_has_your_number'),src:['ams'],dem:[{t:'eye',a:'ber',g:50},{t:'eye',a:'muc',g:50},{t:'eye',a:'zrh',g:40}],via:['ham','dus'],avoid:['fra'],budget:390000}, + {id:'fire',pack:'n1',n:tr('puzzles.ring_of_fire'),j:tr('puzzles.four_cities_four_cables_one_ring'),src:['tok'],dem:[{t:'eye',a:'hkg',g:20},{t:'eye',a:'sin',g:20},{t:'eye',a:'syd',g:10}],ring:true,budget:4070000}, + {id:'suez',pack:'final',n:tr('puzzles.suez_you_later'),j:tr('puzzles.frankfurt_to_singapore_the_short_way'),src:['fra'],dem:[{t:'l2',a:'fra',b:'sin',g:10,ms:68},{t:'eye',a:'sin',g:30,be:1}],via:['mrs','bom'],budget:1790000}, + {id:'kiwi',pack:'final',n:tr('puzzles.kiwi_fruit_salad'),j:tr('puzzles.new_zealand_is_far_from_everything'),src:['sea'],dem:[{t:'eye',a:'akl',g:20},{t:'eye',a:'syd',g:40}],via:['hnl','suv','lax'],budget:4200000}, + {id:'samba',pack:'final',n:tr('puzzles.samba_sprint'),j:tr('puzzles.sao_paulo_to_miami_before_the'),src:['mia'],dem:[{t:'l2',a:'sao',b:'mia',g:10,ms:45},{t:'eye',a:'sao',g:40},{t:'eye',a:'rio',g:20,be:1}],via:['for'],budget:2655000}, ]; // Weekly puzzle pools: each is one landmass and one region, so every pair has an overland route. const PZ_WEEK_POOLS=[ diff --git a/src/i18n/en.js b/src/i18n/en.js index 8ab1e1d..a0e51dc 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2946,7 +2946,6 @@ "puzzles.every_star_in_this_pack_is":"Every star in this pack is yours.", "puzzles.everything_at_once_across_oceans":"Everything at once, across oceans. Tight budgets.", "puzzles.fat_pipes":"Fat Pipes", -"puzzles.five_small_cities_one_small_router":"Five cities, a few gigs each, and a router with eight ports. Count before you dig.", "puzzles.fjord_focus":"Fjord Focus", "puzzles.flash_boys":"Flash Boys", "puzzles.flow_circuit_a_b":"{a} ⇄ {b} circuit", @@ -3034,6 +3033,7 @@ "puzzles.sao_paulo_to_miami_before_the":"São Paulo to Miami before the caipirinha gets warm.", "puzzles.sea_to_shining_sea":"Sea to Shining Sea", "puzzles.share_line":"Series of Tubes puzzle {what} {stars} {spend} · seriesoftub.es", +"puzzles.six_cities_a_few_gigs_each":"Six cities, a few gigs each, and a router with eight ports. Count before you dig.", "puzzles.size":"Size", "puzzles.small_networks_real_traffic":"Small networks, real traffic", "puzzles.spent_x":"Spent {x}", diff --git a/tests/puzzles.test.js b/tests/puzzles.test.js index 9290a77..8e1db0d 100644 --- a/tests/puzzles.test.js +++ b/tests/puzzles.test.js @@ -1,99 +1,94 @@ -// Puzzle mode (#190): small builds with stars, no clock, and a main save that is never touched. +// Puzzle mode (#190), with traffic: small builds that carry real flows, routed by the game's own compute(), with stars, +// no clock, and a main save that is never touched. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); +const SV = require('../scripts/lib/puzzle-solver'); -// Reference solutions: [a, b, route ('land' or a cable id), tier (0 = 10G, 1 = 100G)]. -// `one` earns the goal star, `three` earns all three. A second land link on the same pair is a diverse route. +/* Reference solutions, played through the player's own actions. A link is [a, b, route ('land' or a cable id), tier + (0 = 10G, 1 = 100G, 2 = 400G), same]: a further overland link on a pair takes a diverse route, or with same = k + goes into the k-th trench already there (added from the link panel). ['@rt', city, model, count] sets a POP's + routers (RG index), ['@route', flow, 'fast'] sends a circuit the lowest-latency way. `one` earns the delivery star, + `three` all three: the three-star ones are the cheapest builds the solver (scripts/lib/puzzle-solver.js) found. */ const REF = { - hello: { one: [['lon', 'nyc', 'grace']], three: [['lon', 'nyc', 'grace'], ['lon', 'nyc', 'amitie']] }, - eurotrip: { one: [['lon', 'ams', 'uly'], ['ams', 'fra', 'land']], three: [['ams', 'lon', 'concerto'], ['ams', 'lon', 'nshuttle'], ['ams', 'fra', 'land'], ['ams', 'fra', 'land']] }, - shining: { one: [['nyc', 'chi', 'land'], ['chi', 'dal', 'land'], ['dal', 'sjc', 'land']], three: [['chi', 'nyc', 'land'], ['chi', 'sjc', 'land'], ['dal', 'nyc', 'land'], ['dal', 'sjc', 'land']] }, - smorgas: { one: [['osl', 'sto', 'land'], ['sto', 'hel', 'land'], ['osl', 'cph', 'land']], three: [['osl', 'sto', 'land'], ['cph', 'osl', 'land'], ['cph', 'hel', 'land'], ['hel', 'sto', 'land']] }, - downunder: { one: [['syd', 'mel', 'land'], ['mel', 'adl', 'land'], ['syd', 'bne', 'land']], three: [['mel', 'syd', 'land'], ['bne', 'syd', 'land'], ['adl', 'mel', 'land'], ['adl', 'bne', 'land']] }, - aloha: { one: [['sjc', 'hnl', 'scx'], ['hnl', 'syd', 'hwk']], three: [['hnl', 'sjc', 'scx'], ['hnl', 'sjc', 'aag'], ['hnl', 'syd', 'hwk'], ['hnl', 'syd', 'aloha']] }, - rimshot: { one: [['sea', 'tok', 'fast'], ['tok', 'hkg', 'adc'], ['hkg', 'sin', 'sjc2']], three: [['sea', 'tok', 'fast'], ['sea', 'tok', 'ncp'], ['hkg', 'tok', 'apg'], ['hkg', 'tok', 'adc'], ['hkg', 'sin', 'land'], ['hkg', 'sin', 'land']] }, - fire: { one: [['tok', 'hkg', 'adc'], ['hkg', 'sin', 'sjc2'], ['sin', 'syd', 'indigo'], ['syd', 'tok', 'guam']], three: [['hkg', 'tok', 'adc'], ['hkg', 'sin', 'land'], ['sin', 'syd', 'indigo'], ['syd', 'tok', 'guam']] }, - // Hawaiki is Seattle's only cable south, so the second way out runs overland to LA and on via Suva. - kiwi: { one: [['akl', 'sea', 'hwk'], ['akl', 'syd', 'tasman']], three: [['akl', 'syd', 'tasman'], ['akl', 'sea', 'hwk'], ['suv', 'syd', 'scxn'], ['lax', 'sea', 'land'], ['lax', 'suv', 'scxn']] }, - guam: { one: [['tok', 'gum', 'jga'], ['gum', 'syd', 'guam'], ['tok', 'mnl', 'jup']], three: [['mnl', 'tok', 'jup'], ['syd', 'tok', 'sushi'], ['gum', 'mnl', 'bifrost'], ['gum', 'syd', 'guam']] }, - flash: { one: [['nyc', 'lon', 'hibx']], three: [['lon', 'nyc', 'grace'], ['lon', 'nyc', 'hibx']] }, - pingpong: { one: [['lax', 'tok', 'jup']], three: [['lax', 'tok', 'jup'], ['lax', 'sea', 'land'], ['sea', 'tok', 'fast']] }, - suez: { one: [['fra', 'mrs', 'land'], ['mrs', 'sin', 'peace']], three: [['fra', 'mrs', 'land'], ['fra', 'mrs', 'land'], ['mrs', 'sin', 'peace'], ['bom', 'sin', 'land'], ['bom', 'mrs', 'twoaf']] }, - samba: { one: [['sao', 'mia', 'monet']], three: [['for', 'sao', 'land'], ['for', 'sao', 'land'], ['for', 'mia', 'monet'], ['for', 'mia', 'sam1']] }, - sharks: { one: [['lis', 'mad', 'land'], ['mad', 'par', 'land'], ['par', 'mil', 'land']], three: [['lis', 'mad', 'land'], ['lis', 'mil', 'land'], ['mad', 'par', 'land'], ['mil', 'par', 'land']] }, - braces: { one: [['nyc', 'lon', 'grace'], ['lon', 'dub', 'celtix']], three: [['lon', 'nyc', 'grace'], ['dub', 'nyc', 'havf'], ['dub', 'lon', 'celtix']] }, - nofra: { one: [['ams', 'ber', 'land'], ['ber', 'muc', 'land'], ['muc', 'zrh', 'land']], three: [['ams', 'ber', 'land'], ['ams', 'zrh', 'land'], ['ber', 'muc', 'land'], ['muc', 'zrh', 'land']] }, - fatpipes: { one: [['par', 'mrs', 'land', 1], ['mrs', 'mil', 'land', 1], ['mil', 'zrh', 'land', 1]], three: [['par', 'zrh', 'land', 1], ['mrs', 'par', 'land', 1], ['mil', 'mrs', 'land', 1], ['mil', 'zrh', 'land', 1]] }, + hello: { one: [['nyc', 'lon', 'grace', 0]], three: [['nyc', 'lon', 'grace', 0], ['nyc', 'lon', 'amitie', 0]] }, + eurotrip: { one: [['ams', 'lon', 'nshuttle', 1], ['ams', 'fra', 'land', 1]], three: [['ams', 'lon', 'concerto', 1], ['ams', 'lon', 'nshuttle', 1], ['ams', 'fra', 'land', 1], ['ams', 'fra', 'land', 1]] }, + bigboat: { one: [['fra', 'par', 'land', 1], ['fra', 'par', 'land', 1]], three: [['fra', 'par', 'land', 1], ['fra', 'par', 'land', 1], ['fra', 'par', 'land', 1]] }, + shining: { one: [['nyc', 'chi', 'land', 1], ['dal', 'sjc', 'land', 1], ['nyc', 'dal', 'land', 1]], three: [['nyc', 'chi', 'land', 1], ['nyc', 'chi', 'land', 1], ['chi', 'sjc', 'land', 1], ['dal', 'sjc', 'land', 1], ['nyc', 'dal', 'land', 1]] }, + downunder: { one: [['syd', 'mel', 'land', 1], ['syd', 'bne', 'land', 1], ['mel', 'adl', 'land', 1]], three: [['syd', 'mel', 'land', 1], ['syd', 'bne', 'land', 1], ['mel', 'adl', 'land', 1], ['bne', 'adl', 'land', 1]] }, + edgelord: { one: [['@rt', 'ams', 5, 1], ['@rt', 'lon', 5, 1], ['ams', 'lon', 'nshuttle', 2], ['ams', 'lon', 'circe', 1]], three: [['@rt', 'ams', 5, 1], ['@rt', 'lon', 5, 1], ['ams', 'lon', 'concerto', 2], ['ams', 'lon', 'nshuttle', 2], ['ams', 'lon', 'circe', 1]] }, + hubcap: { one: [['@rt', 'lon', 5, 1], ['lon', 'par', 'pasdc', 1], ['lon', 'ams', 'concerto', 1], ['lon', 'ams', 'circe', 1], ['lon', 'ams', 'nshuttle', 1], ['lon', 'par', 'pasdc', 1], ['ams', 'fra', 'land', 1], ['ams', 'fra', 'land', 1]], three: [['@rt', 'lon', 5, 1], ['lon', 'par', 'chn', 1], ['lon', 'par', 'pasdc', 1], ['ams', 'fra', 'land', 1], ['lon', 'ams', 'concerto', 1], ['lon', 'ams', 'circe', 1], ['lon', 'ams', 'nshuttle', 1], ['lon', 'par', 'chn', 1], ['lon', 'par', 'pasdc', 1], ['ams', 'fra', 'land', 1], ['ams', 'fra', 'land', 1], ['lon', 'ams', 'uly', 1]] }, + flash: { one: [['nyc', 'lon', 'grace', 1], ['nyc', 'lon', 'hibx', 0]], three: [['nyc', 'lon', 'grace', 1], ['nyc', 'lon', 'hibx', 0]] }, + baltic: { one: [['fra', 'hel', 'clion', 1], ['tll', 'hel', 'land', 1], ['@route', 1, 'fast']], three: [['fra', 'hel', 'clion', 1], ['tll', 'hel', 'land', 1], ['fra', 'tll', 'land', 1], ['@route', 1, 'fast']] }, + fjord: { one: [['par', 'lon', 'pasdc', 1], ['svg', 'lon', 'tampn', 1], ['@route', 1, 'fast']], three: [['par', 'svg', 'land', 1], ['par', 'lon', 'pasdc', 1], ['svg', 'lon', 'tampn', 1], ['@route', 1, 'fast']] }, + braces: { one: [['nyc', 'dub', 'havf', 1], ['lon', 'dub', 'celtix', 1]], three: [['nyc', 'lon', 'grace', 1], ['nyc', 'dub', 'havf', 1], ['lon', 'dub', 'celtix', 1]] }, + sharks: { one: [['lis', 'mad', 'land', 1], ['lis', 'bcn', 'land', 1], ['par', 'mil', 'land', 1], ['par', 'mrs', 'land', 1], ['bcn', 'mrs', 'land', 1]], three: [['lis', 'mad', 'land', 1], ['lis', 'mad', 'land', 1], ['lis', 'bcn', 'land', 1], ['mad', 'bcn', 'land', 1], ['par', 'mil', 'land', 1], ['par', 'mrs', 'land', 1], ['mil', 'bcn', 'land', 1], ['bcn', 'mrs', 'land', 1]] }, + nofra: { one: [['ams', 'dus', 'land', 1], ['ams', 'dus', 'land', 1], ['ber', 'ham', 'land', 1], ['muc', 'zrh', 'land', 1], ['muc', 'dus', 'land', 1], ['ham', 'dus', 'land', 1]], three: [['ams', 'ham', 'land', 1], ['ams', 'dus', 'land', 1], ['ams', 'dus', 'land', 1], ['ber', 'ham', 'land', 1], ['ber', 'ham', 'land', 1], ['muc', 'zrh', 'land', 1], ['muc', 'dus', 'land', 1], ['zrh', 'dus', 'land', 1], ['ham', 'dus', 'land', 1]] }, + fire: { one: [['tok', 'hkg', 'adc', 1], ['hkg', 'sin', 'land', 1], ['sin', 'syd', 'indigo', 1], ['syd', 'tok', 'guam', 1]], three: [['tok', 'hkg', 'adc', 1], ['hkg', 'sin', 'land', 1], ['sin', 'syd', 'indigo', 1], ['syd', 'tok', 'guam', 1]] }, + suez: { one: [['fra', 'mrs', 'land', 1], ['sin', 'mrs', 'peace', 1]], three: [['fra', 'mrs', 'land', 1], ['fra', 'mrs', 'land', 0], ['sin', 'mrs', 'peace', 1], ['sin', 'bom', 'land', 0], ['mrs', 'bom', 'twoaf', 0]] }, + kiwi: { one: [['sea', 'lax', 'land', 1], ['akl', 'syd', 'tasman', 1], ['akl', 'hnl', 'hwk', 1], ['hnl', 'lax', 'seaus', 1]], three: [['sea', 'hnl', 'hwk', 1], ['sea', 'lax', 'land', 1], ['akl', 'syd', 'scx', 1], ['akl', 'syd', 'tasman', 1], ['akl', 'hnl', 'hwk', 1], ['akl', 'suv', 'scx', 1], ['hnl', 'suv', 'scx', 1], ['hnl', 'lax', 'seaus', 1]] }, + samba: { one: [['mia', 'for', 'monet', 1], ['sao', 'rio', 'land', 1], ['sao', 'for', 'land', 1]], three: [['mia', 'for', 'monet', 1], ['mia', 'for', 'sam1', 1], ['sao', 'rio', 'land', 1], ['sao', 'for', 'land', 1], ['rio', 'for', 'land', 1]] }, + ports: { one: [['@rt', 'zrh', 4, 1], ['zrh', 'mil', 'land', 0], ['zrh', 'mil', 'land', 0], ['zrh', 'muc', 'land', 0], ['zrh', 'muc', 'land', 0], ['zrh', 'fra', 'land', 0], ['zrh', 'fra', 'land', 0], ['zrh', 'par', 'land', 0], ['zrh', 'par', 'land', 0], ['zrh', 'vie', 'land', 0], ['zrh', 'vie', 'land', 0], ['zrh', 'prg', 'land', 0], ['zrh', 'prg', 'land', 0]], three: [['@rt', 'zrh', 5, 1], ['zrh', 'mil', 'land', 0], ['zrh', 'mil', 'land', 0], ['zrh', 'mil', 'land', 0], ['zrh', 'muc', 'land', 0], ['zrh', 'muc', 'land', 0], ['zrh', 'muc', 'land', 0], ['zrh', 'fra', 'land', 0], ['zrh', 'fra', 'land', 0], ['zrh', 'fra', 'land', 0], ['zrh', 'par', 'land', 0], ['zrh', 'par', 'land', 0], ['zrh', 'par', 'land', 0], ['zrh', 'vie', 'land', 0], ['zrh', 'vie', 'land', 0], ['zrh', 'vie', 'land', 0], ['zrh', 'prg', 'land', 0], ['zrh', 'prg', 'land', 0], ['zrh', 'prg', 'land', 0]] }, }; -// Builds links the way a player does: POP at the first city, then the link picker for each hop. -function build(ev, links) { - for (const [a, b, via, tier] of links) { +function build(ev, steps) { + for (const s of steps) { + if (s[0] === '@rt') { const [, c, g, n] = s; if (!ev(`!!S.pops['${c}']`)) ev(`ACT.pzPop({city:'${c}'})`); if (g) ev(`ACT.pzRtModel({city:'${c}',g:${g}})`); for (let i = 1; i < n; i++) ev(`ACT.pzRtAdd({city:'${c}'})`); continue; } + if (s[0] === '@route') { ev(`ACT.pzRoute({i:${s[1]},m:'${s[2]}'})`); continue; } + const [a, b, via, tier, same] = s; if (!ev(`!!S.pops['${a}']`)) ev(`ACT.pzPop({city:'${a}'})`); - ev(`ACT.pzLinkTo({a:'${a}',b:'${b}'});ACT.pzVia({v:'${via}'});ACT.pzDiv({v:1});ACT.pzLink({tier:${tier || 0}})`); + if (same) ev(`(()=>{const ls=S.links.filter(l=>edgeKey(l)===edgeKey({a:'${a}',b:'${b}'})&&!l.cable),ts=[...new Set(ls.map(pzUnit))],l=ls.find(x=>pzUnit(x)===ts[${same - 1}]);ACT.pzAddPar({id:l.id,div:0});ACT.pzLink({tier:${tier}})})()`); + else ev(`ACT.pzLinkTo({a:'${a}',b:'${b}'});ACT.pzVia({v:'${via}'});ACT.pzDiv({v:1});ACT.pzLink({tier:${tier || 0}})`); } ev('closeModal()'); } const evalP = (ev) => JSON.parse(ev('JSON.stringify(pzEval())')); +const links = (steps) => steps.filter((s) => s[0] !== '@rt'); -test('puzzle data: every puzzle is valid, solvable, and its 3-star reference earns three stars', () => { +test('puzzle data: every puzzle is valid, carries traffic, and its references earn their stars through the real routing', () => { const { ev, errors } = load(); const ids = JSON.parse(ev('JSON.stringify(PZ.map(p=>p.id))')); - assert.ok(ids.length >= 16, 'at least 16 puzzles'); + assert.ok(ids.length >= 16 && ids.length <= 20, '16 to 20 puzzles'); assert.equal(new Set(ids).size, ids.length, 'ids are unique'); assert.deepEqual(Object.keys(REF).sort(), ids.slice().sort(), 'every puzzle has a reference solution'); - assert.ok(ev("PZ.every(p=>PZ_PACKS.some(k=>k.id===p.pack)&&p.n&&p.j&&p.cities.length>=2&&p.cities.length<=6&&[...p.cities,...(p.via||[]),...(p.avoid||[])].every(c=>isCity(c)&&!CITY[c].off&&!CITY[c].cn))"), 'cities exist and are playable'); + assert.ok(ev("PZ.every(p=>PZ_PACKS.some(k=>k.id===p.pack)&&p.n&&p.j&&p.dem.length>=1&&pzCities(p).length>=2&&pzCities(p).length<=7&&[...pzCities(p),...(p.via||[]),...(p.avoid||[])].every(pzCityOk))"), 'cities exist and are playable'); + assert.ok(ev("PZ.every(p=>p.dem.every(f=>f.g>0&&(f.t==='eye'?(p.src||[]).length>0&&!p.src.includes(f.a):f.t==='l2'&&f.a!==f.b)))"), 'eyeballs have an origin, circuits two ends'); assert.ok(ev("PZ.every(p=>!p.budget||(p.budget>=100000&&p.budget<=5e6))"), 'budgets are sane'); assert.ok(ev("PZ_PACKS[0].need===0&&PZ_PACKS.every((k,i)=>!i||k.need>PZ_PACKS[i-1].need)"), 'packs unlock in order'); + assert.ok(ev("PZ_PACKS.every(k=>PZ.filter(p=>p.pack===k.id).length>=3)"), 'every pack has at least three puzzles'); assert.ok(ev("PZ.filter(p=>p.pack==='hello'&&!p.budget).length>=2"), 'the first puzzles give the budget star away'); for (const id of ids) { ev(`pzBegin(pzDef('${id}'))`); build(ev, REF[id].one); let e = evalP(ev); - assert.ok(e.goal, `${id}: the one-star reference reaches the goal`); - assert.ok(e.stars >= 1, `${id}: one star`); + assert.ok(e.goal, `${id}: the one-star reference delivers everything (${JSON.stringify(e.flows.map((x) => [x.g, x.ms]))})`); ev('ACT.pzReset({})'); assert.equal(evalP(ev).stars, 0, `${id}: reset clears it`); build(ev, REF[id].three); e = evalP(ev); - assert.equal(e.stars, 3, `${id}: three stars (spend ${e.spend} of ${ev('S.pz.budget')}, n1 ${e.n1}, twists ${JSON.stringify(e.tw)})`); + assert.equal(e.stars, 3, `${id}: three stars (spend ${e.spend} of ${ev('S.pz.budget')}, n1 ${e.n1}, worst cut ${JSON.stringify(e.worst)})`); } assert.deepEqual(errors, []); }); -// Brute force over every route between the puzzle's cities (one size: 10G, or 100G under minG): is any 3-star build -// cheaper than `limit`? Each cable is one failure unit; each overland link its own trench (a second one is diverse). -function cheaper3(ev, id, limit) { - const D = JSON.parse(ev(`(()=>{pzBegin(pzDef('${id}'));const P=S.pz,cs=[...P.cities,...P.via],tier=P.minG?1:0,o=[]; - for(const a of cs)for(const b of cs)if(a o[i].cab ? 'c' + o[i].cab : 't' + i; - const reach = (ls, skip) => { const adj = {}; for (const i of ls) { if (unit(i) === skip) continue; const { a, b } = o[i]; (adj[a] = adj[a] || []).push(b); (adj[b] = adj[b] || []).push(a); } - const seen = new Set([P.cities[0]]), q = [P.cities[0]]; while (q.length) for (const v of adj[q.pop()] || []) if (!seen.has(v)) { seen.add(v); q.push(v); } return P.cities.every((c) => seen.has(c)); }; - const lat = (ls) => { const d = { [P.lat[0]]: 0 }, done = new Set(); for (;;) { let u = null; for (const k in d) if (!done.has(k) && (u === null || d[k] < d[u])) u = k; if (u === null) return Infinity; if (u === P.lat[1]) return d[u]; done.add(u); - for (const i of ls) { const l = o[i]; if (l.a !== u && l.b !== u) continue; const v = l.a === u ? l.b : l.a, nd = d[u] + l.ms + 0.05; if (!(nd >= d[v])) d[v] = nd; } } }; - const ring = (ls) => { const nb = {}; for (const i of ls) { const { a, b } = o[i]; (nb[a] = nb[a] || new Set()).add(b); (nb[b] = nb[b] || new Set()).add(a); } const ns = Object.keys(nb); - if (ns.length < 3 || !ns.every((c) => nb[c].size === 2)) return false; let prev = null, cur = ns[0], n = 0; do { const nx = [...nb[cur]].find((x) => x !== prev); prev = cur; cur = nx; n++; } while (cur !== ns[0] && n <= ns.length); return n === ns.length; }; - const ok = (ls) => { if (!reach(ls, null) || (P.ring && !ring(ls)) || (P.lat && lat(ls) > P.lat[2])) return false; return [...new Set(ls.map(unit))].every((u) => reach(ls, u)); }; - let found = null; - const rec = (start, ls, cost) => { if (found) return; if (ls.length && cost < limit - 1) { const pops = new Set(P.cities); for (const i of ls) { pops.add(o[i].a); pops.add(o[i].b); } const tot = cost + [...pops].reduce((x, c) => x + pop[c], 0); if (tot < limit - 1 && ok(ls)) { found = tot; return; } } - if (ls.length >= 7) return; for (let i = start; i < o.length; i++) { if (o[i].div && !ls.some((j) => !o[j].div && !o[j].cab && o[j].a === o[i].a && o[j].b === o[i].b)) continue; if (cost + o[i].cost < limit - 1) rec(i + 1, [...ls, i], cost + o[i].cost); } }; - rec(0, [], 0); - return found; -} - -test('budgets follow the difficulty curve: roomy first pack, ~10% in the middle, tight N-1 Club', () => { +test('budgets follow the teaching curve, and each 3-star reference is the cheapest build nearby', () => { const { ev, errors } = load(); - const SLACK = { hello: [0.15, 0.2], fire: [0.09, 0.11], speed: [0.09, 0.11], n1: [0.05, 0.08] }; + SV.install(ev); + // Slack over the cheapest 3-star build found: roomy first, tight at the end. Traffic Cops is tight on purpose: the + // routing trick (a circuit on the lowest-latency path) is what brings it under budget. + const SLACK = { hello: [0.15, 0.22], rodeo: [0.09, 0.13], cops: [0.03, 0.06], n1: [0.05, 0.08], final: [0.04, 0.07] }; const rows = JSON.parse(ev('JSON.stringify(PZ.filter(p=>p.budget).map(p=>({id:p.id,pack:p.pack,budget:p.budget})))')); for (const { id, pack, budget } of rows) { ev(`pzBegin(pzDef('${id}'))`); build(ev, REF[id].three); const e = evalP(ev); assert.equal(e.stars, 3, id); - assert.equal(cheaper3(ev, id, e.spend), null, `${id}: the reference is the cheapest 3-star build`); + // The routers in the reference are the cheapest that carry it: the solver prices the same build the same. + const L = links(REF[id].three), j = SV.judge(ev, L); + assert.ok(j.three && Math.abs(j.spend - e.spend) < 1, `${id}: solver ${j.spend} vs game ${e.spend}`); + // No single change (drop a link, shrink one, move it to another route or trench) keeps three stars for less. + const r = SV.improve(ev, L); + assert.ok(r.spend >= e.spend - 1, `${id}: ${JSON.stringify(r.links)} is cheaper (${r.spend})`); const slack = budget / e.spend - 1, [lo, hi] = SLACK[pack]; assert.ok(slack >= lo && slack <= hi, `${id}: ${(slack * 100).toFixed(1)}% slack, want ${lo * 100}-${hi * 100}%`); } @@ -101,58 +96,331 @@ test('budgets follow the difficulty curve: roomy first pack, ~10% in the middle, assert.deepEqual(errors, []); }); -test('stars: goal, budget, N-1 and twists each count', () => { +test('stars come from traffic: capacity, latency caps, best effort and N-1 under load', () => { const { ev, errors } = load(); - ev("pzBegin(pzDef('braces'))"); - build(ev, REF.braces.one); + // Connected is not delivered: a 10G wave for 30G of London eyeballs gets 10G there. + ev("pzBegin(pzDef('eurotrip'))"); + build(ev, [['ams', 'lon', 'nshuttle', 0], ['ams', 'fra', 'land', 1]]); let e = evalP(ev); - assert.equal(e.stars, 2, 'connected and under budget, but one cut splits it'); - assert.ok(!e.n1 && e.weak.length > 0); - build(ev, [['dub', 'nyc', 'havf']]); + assert.ok(!e.goal && Math.abs(e.flows[0].g - 10) < 0.1, `10G of 30G (${e.flows[0].g})`); + assert.match(ev("document.getElementById('pzBox').textContent"), /Eyeballs in London(9\.\d|10\.0) Gbps \/ 30\.0 Gbps/); + ev("ACT.pzTier({id:S.links[0].id,tier:1})"); + assert.ok(evalP(ev).goal, 'a 100G wave carries it'); + // N-1 under load: two trenches into Paris are connected after a cut, but one 100G wave cannot carry 150G. + ev("pzBegin(pzDef('bigboat'))"); + build(ev, [['fra', 'par', 'land', 1], ['fra', 'par', 'land', 1, 1], ['fra', 'par', 'land', 1]]); + e = evalP(ev); + assert.ok(e.goal && !e.n1, 'still connected after a cut, but short'); + assert.equal(Math.round(e.worst.g), 50, 'cutting the trench with two waves leaves 100G for 150G: 50G drop'); + assert.match(ev("document.getElementById('pzBox').textContent"), /A cut on Frankfurt ⇄ Paris drops 50\.\d Gbps/); + build(ev, [['fra', 'par', 'land', 1, 2]]); + assert.ok(evalP(ev).n1, 'two waves in each trench: either one carries Paris alone'); + // A latency cap: Grace Hopscotch is too slow for the traders; the eyeballs are best effort and may drop on a cut. + ev("pzBegin(pzDef('flash'))"); + build(ev, [['nyc', 'lon', 'grace', 1]]); + e = evalP(ev); + assert.ok(!e.goal && e.flows[0].full && !e.flows[0].fast, 'all of the circuit, but at 29 ms'); + build(ev, [['nyc', 'lon', 'hibx', 0]]); + e = evalP(ev); + assert.equal(e.stars, 3, 'the fast cable for the circuit; when the big one is cut, only best effort drops'); + // A circuit follows the metrics unless told otherwise: the road to Tallinn is shorter, the light via Helsinki faster. + ev("pzBegin(pzDef('baltic'))"); + build(ev, links(REF.baltic.three).filter((s) => s[0] !== '@route')); + e = evalP(ev); + assert.ok(!e.goal && e.flows[1].ms > 8.8, `the metric path is too slow (${e.flows[1].ms})`); + assert.ok(ev("!!document.querySelector('#pzBox [data-act=pzRoute]')"), 'the card has the circuit\'s route switch'); + ev("document.querySelector('#pzBox [data-act=pzRoute][data-args*=fast]').click()"); + e = evalP(ev); + assert.ok(e.goal && e.flows[1].ms <= 8.8, 'lowest latency goes via Helsinki'); + ev('ACT.pzUndo({})'); + assert.equal(ev("S.biz[0].route"), 'normal', 'undo takes the route back'); + // The main game's metric control works in a puzzle and moves the traffic: Backup only on the road pushes the + // eyeballs through Helsinki too. + ev("ACT.pzRoute({i:1,m:'fast'});ACT.selLink({id:S.links.find(l=>edgeKey(l)==='fra|tll').id})"); + assert.match(ev("document.getElementById('panelBody').textContent"), /Routing metric/); + ev("ACT.setMetric({id:S.links.find(l=>edgeKey(l)==='fra|tll').id,v:'backup'})"); + assert.ok(ev("(R.load[S.links.find(l=>edgeKey(l)==='fra|tll').id]||0)<0.01"), 'nothing on a backup-only link while the others are up'); + ev('ACT.pzUndo({})'); + assert.ok(ev("!S.pairMet['fra|tll']"), 'undo takes the metric back'); + // Over budget loses the second star only. + ev("pzBegin(pzDef('braces'))");build(ev, REF.braces.three); assert.equal(evalP(ev).stars, 3); ev('S.pz.budget=1000'); - assert.equal(evalP(ev).stars, 2, 'over budget loses the second star'); - // Two waves in the same trench are one backhoe away from nothing. - ev("pzBegin(pzDef('shining'))"); - build(ev, REF.shining.one); - ev("ACT.pzLinkTo({a:'nyc',b:'chi'});ACT.pzVia({v:'land'});ACT.pzDiv({v:0});ACT.pzLink({tier:0})"); - assert.equal(ev("new Set(S.links.filter(l=>edgeKey(l)==='chi|nyc').map(pzUnit)).size"), 1, 'same trench shares the cut'); - // A cable fails as a whole: two waves on one cable, even between different cities, are one cut. - ev("pzBegin(pzDef('guam'))"); - build(ev, [['tok', 'mnl', 'jup'], ['mnl', 'gum', 'bifrost'], ['gum', 'syd', 'guam'], ['syd', 'tok', 'guam']]); - e = evalP(ev); - assert.ok(e.goal && !e.n1, 'both of Sydney\'s links ride the Guam cable: one anchor splits Sydney off'); - assert.equal(ev("new Set(S.links.filter(l=>l.cable==='guam').map(pzUnit)).size"), 1, 'one cable, one failure unit'); - assert.ok(ev("document.getElementById('pzBox').textContent").includes('One cut splits it: ' + ev('CAB.guam.name')), 'the weak spot names the cable'); - ev("ACT.pzRmLink({id:S.links[3].id})");build(ev, [['tok', 'syd', 'sushi']]); - assert.equal(evalP(ev).stars, 3, 'a second cable into Sydney fixes it'); - // Twists: no subsea, ring, latency, minimum size, cities to avoid. - ev("pzBegin(pzDef('sharks'))");build(ev, REF.sharks.one); - assert.ok(evalP(ev).goal); - ev("pzBegin(pzDef('fire'))");build(ev, REF.fire.one);ev("ACT.pzRmLink({id:S.links[3].id})"); - e = evalP(ev); - assert.ok(e.conn && !e.goal, 'a line is not a ring'); - ev('ACT.pzUndo({})'); - assert.ok(evalP(ev).goal, 'undo puts the ring back'); - ev("pzBegin(pzDef('flash'))");build(ev, [['nyc', 'lon', 'grace']]); - e = evalP(ev); - assert.ok(e.conn && !e.goal, 'Grace Hopscotch is too slow for the traders'); - ev("pzBegin(pzDef('fatpipes'))");build(ev, REF.fatpipes.one.map(([a, b, v]) => [a, b, v, 0])); - assert.ok(!evalP(ev).goal, '10G is too thin'); - ev("ACT.pzTier({id:S.links[0].id,tier:1});ACT.pzTier({id:S.links[1].id,tier:1});ACT.pzTier({id:S.links[2].id,tier:1})"); - assert.ok(evalP(ev).goal, 'upgraded in place'); - ev("pzBegin(pzDef('nofra'))"); - ev("ACT.pzPop({city:'fra'})"); - assert.equal(ev("!!S.pops.fra"), false, 'no POP in a city to avoid'); - assert.equal(ev("pzKind('lon')"), null, 'cities outside the puzzle are inert'); - ev("ACT.pzPop({city:'lon'})"); - assert.equal(ev("Object.keys(S.pops).length"), 0); - // Subsea is greyed out in the shark tank. - ev("pzBegin(pzDef('sharks'));ACT.pzPop({city:'lis'});ACT.pzLinkTo({a:'lis',b:'bcn'});ACT.pzVia({v:'medusa'});ACT.pzLink({tier:0})"); - assert.equal(ev('S.links.length'), 0); + assert.equal(evalP(ev).stars, 2); + // A cable fails as a whole: two waves on one cable are one cut. + ev("pzBegin(pzDef('kiwi'))"); + build(ev, [['akl', 'syd', 'scx', 1], ['akl', 'suv', 'scx', 1]]); + assert.equal(ev("new Set(S.links.map(pzUnit)).size"), 1, 'one cable, one failure unit'); assert.deepEqual(errors, []); }); +test('parallel links say how many they are and where they run; diversity from the link panel', () => { + const { ev, errors } = load(); + ev("pzBegin(pzDef('bigboat'))"); + build(ev, [['fra', 'par', 'land', 1]]); + const id = ev('S.links[0].id'); + ev(`ACT.selLink({id:'${id}'})`); + let panel = ev("document.getElementById('panelBody').textContent"); + assert.match(panel, /Add another link on this pair/); + // Same trench from the panel: no surcharge, one failure unit, one line on the map labelled 2×100G. + ev(`ACT.pzAddPar({id:'${id}',div:0})`); + assert.match(ev("document.getElementById('modalCard').textContent"), /Already on this pair: 1×100G · trench 1/); + ev('ACT.pzLink({tier:1})'); + assert.equal(ev("new Set(S.links.map(pzUnit)).size"), 1); + assert.equal(ev('S.links[1].mo'), ev('S.links[0].mo')); + assert.equal(ev("pzLinkLab(S.links,S.links,R.load[S.links[0].id]+R.load[S.links[1].id],200)"), '2×100G · 75%'); + assert.equal(ev("groupLabel(linkGroups()[0],linkGroups()[0])"), '2×100G', 'the map draws one line for the trench, labelled with its count'); + // A diverse one from the panel: its own trench, 40% dearer, its own line. + ev(`ACT.pzAddPar({id:'${id}',div:1});ACT.pzLink({tier:1})`); + assert.equal(ev("new Set(S.links.map(pzUnit)).size"), 2); + assert.equal(ev('S.links[2].mo'), ev('Math.round(S.links[0].mo*DIVERSE)')); + assert.equal(ev('linkGroups().length'), 2); + ev(`ACT.selLink({id:'${id}'})`); + panel = ev("document.getElementById('panelBody').textContent"); + assert.match(panel, /3 links on this pair: 3×100G/); + assert.match(panel, /trench 1/); + assert.match(panel, /trench 2/); + // Selecting a city lights up every pair it has links on, and its panel lists them with their loads. + ev("selectCity('par')"); + assert.ok(ev('pzLinkHot(S.links)')); + panel = ev("document.getElementById('panelBody').textContent"); + assert.match(panel, /Frankfurt · 3×100G150 Gbps \/ 300 Gbps/); + // A subsea link: "a different route" picks another cable. + ev("pzBegin(pzDef('hello'))");build(ev, [['nyc', 'lon', 'grace', 0]]); + ev("ACT.pzAddPar({id:S.links[0].id,div:1})"); + assert.notEqual(ev('UI.pzVia'), 'grace'); + assert.match(ev("document.getElementById('modalCard').textContent"), /Already on this pair: 1×10G/); + assert.deepEqual(errors, []); +}); + +test('routers in a puzzle: ports, wave sizes and capacity as in the main game, priced into the budget', () => { + const { ev, errors } = load(); + ev("pzBegin(pzDef('edgelord'))"); + build(ev, [['ams', 'lon', 'nshuttle', 0]]); + // A Rusty Router lights 100G at most. + ev("ACT.pzLinkTo({a:'ams',b:'lon'});ACT.pzVia({v:'concerto'})"); + assert.match(ev("document.querySelector('#modalCard .tierbtn[data-args*=\"2\"]').textContent"), /needs 400G routers/); + assert.equal(ev("document.querySelector('#modalCard .tierbtn[data-args*=\"2\"]').disabled"), true); + ev('closeModal()'); + // Eight ports: the ninth wave is refused, a second router makes room, and it is in the bill. + for (let i = 0; i < 7; i++) ev("ACT.pzLinkTo({a:'ams',b:'lon'});ACT.pzVia({v:'nshuttle'});ACT.pzLink({tier:0})"); + assert.equal(ev('S.links.length'), 8); + ev("ACT.pzLinkTo({a:'ams',b:'lon'})"); + assert.match(ev("document.getElementById('modalCard').textContent"), /No free router ports in Amsterdam, London/); + ev("ACT.pzVia({v:'nshuttle'});ACT.pzLink({tier:0})"); + assert.equal(ev('S.links.length'), 8, 'no port, no wave'); + const sp0 = evalP(ev).spend; + ev("ACT.pzRtAdd({city:'ams'});ACT.pzRtAdd({city:'lon'})"); + assert.equal(evalP(ev).spend - sp0, ev('2*pzRtCost(0,2)'), 'two second routers, priced as the main game prices them'); + ev("ACT.pzLinkTo({a:'ams',b:'lon'});ACT.pzVia({v:'nshuttle'});ACT.pzLink({tier:0})"); + assert.equal(ev('S.links.length'), 9); + ev("ACT.pzRtRm({city:'ams'})"); + assert.equal(ev('S.pops.ams.routers'), 2, 'cannot drop a router whose ports are in use'); + // The city panel shows the POP: model, load against capacity, ports. + ev("selectCity('lon')"); + const panel = ev("document.getElementById('panelBody').textContent"); + assert.match(panel, /2 × Rusty Router 9000/); + assert.match(panel, /Ports9 of 16 used/); + assert.match(panel, /Router load90\.0 Gbps \/ 800 Gbps/); + // Capacity: a Rusty Router moves 400G. Three 400G waves on Sonic routers bring 1.2T, but a Rusty-sized POP would + // stop at 400G of the 500G London wants. + ev("pzBegin(pzDef('edgelord'))"); + build(ev, [['@rt', 'ams', 5, 1], ['@rt', 'lon', 5, 1], ['ams', 'lon', 'concerto', 2], ['ams', 'lon', 'nshuttle', 2]]); + assert.equal(Math.round(evalP(ev).flows[0].g), 500); + ev("ACT.pzRtModel({city:'lon',g:0})"); + assert.equal(ev('S.pops.lon.rgen'), 5, 'a Rusty Router cannot take a 400G wave: the swap is refused'); + ev("S.pops.lon.rgen=4;UI.pzEv=null");// a Mikrowtik moves 300G (set directly: it refuses 400G waves too) + assert.ok(Math.abs(evalP(ev).flows[0].g - 300) < 5, 'the router is the bottleneck'); + assert.deepEqual(errors, []); +}); + +test('the whole world is open: an off-plan city can get a POP and links, and it counts in the budget', () => { + const { ev, errors } = load(); + ev("pzBegin(pzDef('bigboat'))"); + assert.equal(ev("pzKind('bru')"), 'off'); + ev("selectCity('bru')"); + assert.match(ev("document.getElementById('panelBody').textContent"), /Not in the plan/); + ev("ACT.pzPop({city:'bru'})"); + assert.ok(ev('!!S.pops.bru')); + const sp = evalP(ev).spend; + assert.equal(sp, ev("pzPopCost('bru')")); + ev("ACT.pzLinkTo({a:'bru',b:'par'});ACT.pzVia({v:'land'});ACT.pzLink({tier:1})"); + ev("ACT.pzLinkTo({a:'bru',b:'fra'});ACT.pzVia({v:'land'});ACT.pzLink({tier:1})"); + const e = evalP(ev); + assert.ok(e.spend > sp && Math.round(e.flows[0].g) === 100, 'Paris gets 100G through Brussels'); + assert.equal(ev("pzKind('pek')"), null, 'cities that need a licence stay out'); + ev("pzBegin(pzDef('nofra'));ACT.pzPop({city:'fra'})"); + assert.equal(ev('!!S.pops.fra'), false, 'a city to avoid stays off limits'); + assert.deepEqual(errors, []); +}); + +test('determinism and speed: the same build always gets the same stars, fast enough on the biggest puzzle', () => { + const { ev, errors } = load(); + const run = (id) => { ev(`pzBegin(pzDef('${id}'))`); build(ev, REF[id].three); ev('UI.pzEv=null'); const a = ev('JSON.stringify(pzEval())'); ev('UI.pzEv=null'); return [a, ev('JSON.stringify(pzEval())')]; }; + const [a, b] = run('kiwi'), [c] = run('kiwi'); + assert.equal(a, b, 'twice in a row'); + assert.equal(a, c, 'and from scratch'); + // The biggest puzzle by failure units: one full evaluation (routing plus every single cut). + const big = ev("PZ.map(p=>p.id).sort()[0]") && JSON.parse(ev('JSON.stringify(PZ.map(p=>p.id))')).map((id) => { ev(`pzBegin(pzDef('${id}'))`); build(ev, REF[id].three); return [id, ev('new Set(S.links.map(pzUnit)).size')]; }).sort((x, y) => y[1] - x[1])[0]; + ev(`pzBegin(pzDef('${big[0]}'))`); build(ev, REF[big[0]].three); + for (let i = 0; i < 3; i++) ev('UI.pzEv=null;pzEval()'); + const ms = ev('(()=>{const t=performance.now();for(let i=0;i<5;i++){UI.pzEv=null;pzEval();}return (performance.now()-t)/5})()'); + console.log(`# star evaluation on ${big[0]} (${big[1]} failure units): ${ms.toFixed(1)} ms`); + assert.ok(ms < 150, `${big[0]}: ${ms.toFixed(1)} ms`); + assert.deepEqual(errors, []); +}); + +test('progress: the puzzle set with traffic starts the stars again once, with the old ones framed', () => { + const { ev, errors } = load(); + ev("localStorage.setItem('sot-puzzles',JSON.stringify({s:{hello:{st:3,sp:1},eurotrip:{st:2},gone:{st:3}},wk:{'2026-W40':{st:3,sp:9}},streak:{last:'2026-W40',n:2,best:4}}))"); + let p = JSON.parse(ev('JSON.stringify(pzLoad())')); + assert.deepEqual(p.s, {}, 'old stars do not count in the new set'); + assert.equal(p.old, 8); + assert.deepEqual(p.wk, { '2026-W40': { st: 3, sp: 9 } }, 'weekly results stay'); + assert.equal(p.streak.best, 4, 'and so does the streak'); + ev('ACT.puzzleMenu({})'); + assert.match(ev("document.getElementById('modalCard').textContent"), /Puzzles got traffic!.*Your old 8 ⭐ are framed on the wall/); + ev('closeModal();ACT.puzzleMenu({})'); + assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /Puzzles got traffic!/, 'the note shows once'); + assert.match(ev("document.getElementById('modalCard').textContent"), /Framed on the wall: 8 ⭐/); + // New stars are kept under the new set. + ev("pzBegin(pzDef('hello'))");build(ev, REF.hello.three); + p = JSON.parse(ev("localStorage.getItem('sot-puzzles')")); + assert.equal(p.set, 2); + assert.equal(p.s.hello.st, 3); + assert.equal(JSON.parse(ev('JSON.stringify(pzLoad())')).old, 8); + // Bad data is ignored. + ev("localStorage.setItem('sot-puzzles',JSON.stringify({set:2,s:{hello:{st:99,sp:'x'},nope:{st:3}},old:'',wk:{bad:{st:3}},streak:{n:-4,last:''}}))"); + p = JSON.parse(ev('JSON.stringify(pzLoad())')); + assert.deepEqual(p.s, { hello: { st: 3, sp: null } }); + assert.equal(p.old, null); + assert.deepEqual(p.wk, {}); + assert.deepEqual(p.streak, { last: null, n: 0, best: 0 }); + ev("localStorage.setItem('sot-puzzles','{nope')"); + assert.equal(ev('pzStarsTotal(pzLoad())'), 0); + // Packs unlock by the new stars. + ev("localStorage.removeItem('sot-puzzles')"); + assert.equal(ev("pzPackOpen('rodeo')"), false); + ev("ACT.pzStart({id:'edgelord'})"); + assert.notEqual(ev('S.pz.id'), 'edgelord', 'a locked puzzle does not start'); + ev("localStorage.setItem('sot-puzzles',JSON.stringify({set:2,s:{hello:{st:3},eurotrip:{st:3},bigboat:{st:2},shining:{st:2}}}))"); + assert.equal(ev("pzPackOpen('rodeo')"), true, '10 stars open pack 2'); + ev('ACT.puzzleMenu({})'); + assert.match(ev("document.getElementById('modalCard').textContent"), /Next pack, Traffic Cops, unlocks at 18/); + assert.deepEqual(errors, []); +}); + +test('results card: stars, the next puzzle, a retry, a share line and stars left in the pack', () => { + const { ev, errors } = load(); + ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('eurotrip'))"); + build(ev, REF.eurotrip.one); + let card = ev("document.getElementById('modalCard').textContent"); + assert.match(card, /Puzzle solved/); + assert.equal(evalP(ev).stars, 2, 'delivered, and the budget star is on the house'); + assert.match(card, /One backhoe away/); + assert.match(card, /13 ⭐ left in this pack/); + assert.ok(ev("!!document.querySelector('#modalCard [data-act=pzRetry]')")); + build(ev, [['ams', 'lon', 'concerto', 1], ['ams', 'fra', 'land', 1]]); + card = ev("document.getElementById('modalCard').textContent"); + assert.match(card, /A backhoe walks into your network/); + assert.equal(ev("document.querySelectorAll('#modalCard .pzbig.on').length"), 3); + assert.ok(ev("document.querySelector('#modalCard .btns.cta').classList.contains('pzdone')")); + assert.match(ev("document.querySelector('#modalCard .pznext').textContent"), /Next puzzle →/); + assert.equal(ev("document.querySelector('#modalCard [data-act=pzRetry]')"), null, 'no retry after three stars'); + assert.match(ev('pzShareText(pzEval())'), /^Series of Tubes puzzle Euro Trip ⭐⭐⭐ \$[\d.]+[kM] · seriesoftub\.es$/); + // The last puzzle points back to the list. + ev("localStorage.setItem('sot-puzzles',JSON.stringify({set:2,s:Object.fromEntries(PZ.map(p=>[p.id,{st:3}]))}));pzBegin(pzDef('samba'))"); + build(ev, REF.samba.three); + assert.match(ev("document.querySelector('#modalCard .pznext').textContent"), /More puzzles/); + assert.match(ev("document.getElementById('modalCard').textContent"), /Every star in this pack is yours/); + assert.deepEqual(errors, []); +}); + +test('best spend: kept for the best star count, and a cheaper build at the same stars counts', () => { + const { ev, errors } = load(); + ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('braces'))"); + const rec = () => JSON.parse(ev("JSON.stringify(pzLoad().s.braces||null)")); + build(ev, REF.braces.three); + const three = evalP(ev); + assert.deepEqual(rec(), { st: 3, sp: three.spend }); + ev('S.pz.budget=1e7;ACT.pzTier({id:S.links[0].id,tier:2})'); + assert.equal(ev('S.links[0].tier'), 1, 'a 400G wave needs 400G routers: refused'); + ev("ACT.pzRtAdd({city:'nyc'})"); + assert.equal(evalP(ev).stars, 3); + assert.deepEqual(rec(), { st: 3, sp: three.spend }, 'a dearer 3-star build does not replace it'); + ev("ACT.pzRmLink({id:S.links[0].id})"); + assert.deepEqual(rec(), { st: 3, sp: three.spend }, 'fewer stars never overwrite more'); + ev('ACT.puzzleMenu({})'); + assert.ok(ev("document.getElementById('modalCard').textContent").includes('best ' + ev(`fmt$(${three.spend})`))); + assert.deepEqual(errors, []); +}); + +test('weekly puzzle (seeded stand-in): stable per week, carries traffic, its reference ring earns three stars, streak', () => { + const { ev, errors } = load(); + const a = ev("JSON.stringify(pzWeekly(new Date(2026,9,28)))"), b = ev("JSON.stringify(pzWeekly(new Date(2026,10,1)))"), c = ev("JSON.stringify(pzWeekly(new Date(2026,10,2)))"); + assert.equal(a, b, 'same week, same puzzle'); + assert.notEqual(a, c, 'next week, a new one'); + const w = JSON.parse(a); + assert.equal(w.key, '2026-W44'); + assert.ok(w.cities.length >= 4 && w.dem.length === w.cities.length - 1 && w.src[0] === w.cities[0]); + for (let i = 0; i < 400; i += 28) { + const wi = JSON.parse(ev(`JSON.stringify(pzWeekly(new Date(2026,0,1+${i})))`)); + ev(`pzBegin(pzWeekly(new Date(2026,0,1+${i})))`); + build(ev, wi.ref.map((x, j) => [x, wi.ref[(j + 1) % wi.ref.length], wi.refVia[j], 0])); + assert.equal(evalP(ev).stars, 3, `week +${i}`); + } + ev("localStorage.removeItem('sot-puzzles');pzBegin(pzWeekly(new Date(2026,9,28)))"); + build(ev, w.ref.map((x, j) => [x, w.ref[(j + 1) % w.ref.length], w.refVia[j], 0])); + assert.match(ev('pzShareText(pzEval())'), /^Series of Tubes puzzle 2026-W44 ⭐⭐⭐ \$[\d.]+[kM] · seriesoftub\.es$/); + assert.equal(ev("JSON.parse(localStorage.getItem('sot-puzzles')).streak.n"), 1); + ev("const p=pzLoad();pzStreak(p,'2026-W45');pzStreak(p,'2026-W45');pzStreak(p,'2026-W46');window.__p=p"); + assert.equal(ev('__p.streak.n'), 3); + ev("pzStreak(__p,'2026-W49')"); + assert.equal(ev('__p.streak.n'), 1); + assert.equal(ev('__p.streak.best'), 3); + assert.deepEqual(errors, []); +}); + +test('puzzle HUD and panels fit a 360 px phone, portrait and landscape', () => { + const { ev, errors } = load(); + ev("innerWidth=360;innerHeight=740;dispatchEvent(new Event('resize'))"); + ev("pzBegin(pzDef('baltic'))"); + assert.equal(ev("document.getElementById('tabbar').hidden"), true); + assert.equal(ev("document.getElementById('pzBox').hidden"), false); + const box = ev("document.getElementById('pzBox').textContent"); + assert.match(box, /Eyeballs in Tallinn/); + assert.match(box, /Frankfurt ⇄ Tallinn circuit/); + assert.match(box, /Content lives in Frankfurt/); + ev("selectCity('fra')"); + assert.match(ev("document.getElementById('panelBody').textContent"), /Open a POP/); + ev("document.querySelector('#panelBody [data-act=pzPop]').click()"); + assert.match(ev("document.getElementById('panelBody').textContent"), /Your POP[\s\S]*Router load[\s\S]*Ports[\s\S]*Router model/); + ev("pzLinkModal('fra','tll')"); + assert.equal(ev("document.querySelectorAll('#modalCard .tierbtn').length"), 4, 'four sizes'); + ev("closeModal();innerWidth=740;innerHeight=360;dispatchEvent(new Event('resize'));renderAll()"); + assert.equal(ev("document.getElementById('pzBox').hidden"), false, 'landscape too'); + // jsdom has no layout: the phone rules keep 40 px targets and pin the action row. + const rules = JSON.parse(ev(`JSON.stringify([...document.styleSheets].flatMap(s=>[...s.cssRules]).filter(r=>r.media&&/max-width: ?760px/.test(r.media.mediaText)) + .flatMap(m=>[...m.cssRules]).filter(r=>/#pzBox/.test(r.selectorText||'')).map(r=>({sel:r.selectorText,mh:r.style.getPropertyValue('min-height'),pos:r.style.getPropertyValue('position')})))`)); + assert.ok(rules.some((r) => /#pzBox \.btns \.b/.test(r.sel) && parseFloat(r.mh) >= 40), 'touch targets'); + assert.ok(rules.some((r) => /^#pzBox ?> ?\.btns$/.test(r.sel) && r.pos === 'sticky'), 'pinned actions'); + assert.ok(ev("[...document.querySelectorAll('#pzBox button')].every(b=>b.classList.contains('b'))"), 'every sheet button is a .b the rule sizes'); + assert.deepEqual(errors, []); +}); + +test('puzzles in every language', () => { + for (const lang of ['de', 'es', 'fr', 'it', 'pt']) { + const { ev, errors } = load({ lang }); + ev("ACT.puzzleMenu({});pzBegin(pzDef('baltic'))"); + build(ev, REF.baltic.three); + ev("selectCity('hel');renderAll()"); + const seen = ev("['pzBox','modalCard','hud','panelBody'].map(id=>document.getElementById(id).textContent).join(' ')"); + assert.ok(!/puzzles\./.test(seen), `${lang}: no raw labels`); + assert.match(seen, /⭐/); + assert.deepEqual(errors, [], lang); + } +}); + test('no clock in a puzzle: days never pass, nothing breaks, no bills', () => { const { ev, errors } = load(); ev("pzBegin(pzDef('hello'))"); @@ -205,152 +473,6 @@ test('leaving a puzzle with no game goes back to the title screen', () => { assert.deepEqual(errors, []); }); -test('results card pops the stars, offers the next puzzle, a retry and a share line', () => { - const { ev, errors } = load(); - ev("pzBegin(pzDef('eurotrip'))"); - build(ev, REF.eurotrip.one); - let card = ev("document.getElementById('modalCard').textContent"); - assert.match(card, /Puzzle solved/); - assert.ok(ev("!!document.querySelector('#modalCard [data-act=pzRetry]')")); - assert.match(ev("document.querySelector('#modalCard [data-act=pzStart]').dataset.args"), /shining/); - build(ev, [['lon', 'ams', 'concerto'], ['ams', 'fra', 'land']]); - card = ev("document.getElementById('modalCard').textContent"); - assert.match(card, /A backhoe walks into your network/); - assert.equal(ev("document.querySelectorAll('#modalCard .pzbig.on').length"), 3); - const line = ev('pzShareText(pzEval())'); - assert.match(line, /^Series of Tubes puzzle Euro Trip ⭐⭐⭐ \$\d+k · seriesoftub\.es$/); - assert.deepEqual(errors, []); -}); - -test('weekly puzzle: stable seed per ISO week, solvable, share string and streak', () => { - const { ev, errors } = load(); - const a = ev("JSON.stringify(pzWeekly(new Date(2026,9,28)))"), b = ev("JSON.stringify(pzWeekly(new Date(2026,10,1)))"), c = ev("JSON.stringify(pzWeekly(new Date(2026,10,2)))"); - assert.equal(a, b, 'same week, same puzzle'); - assert.notEqual(a, c, 'next week, a new one'); - const w = JSON.parse(a); - assert.equal(w.key, '2026-W44'); - assert.ok(w.cities.length >= 4 && w.cities.length <= 5 && w.budget > 0); - // Every week of a few years can be solved with three stars by its own reference ring. - for (let i = 0; i < 400; i += 7) { - ev(`pzBegin(pzWeekly(new Date(2026,0,1+${i})))`); - const w = JSON.parse(ev('JSON.stringify(pzWeekly(new Date(2026,0,1+' + i + ')))')); - const cabs = w.refVia.filter((v) => v !== 'land'); - assert.equal(new Set(cabs).size, cabs.length, `week +${i}: no two hops of the reference ring share a cable`); - build(ev, w.ref.map((x, j) => [x, w.ref[(j + 1) % w.ref.length], w.refVia[j]])); - assert.equal(evalP(ev).stars, 3, `week +${i}`); - } - ev("localStorage.removeItem('sot-puzzles');pzBegin(pzWeekly(new Date(2026,9,28)))"); - build(ev, w.ref.map((x, j) => [x, w.ref[(j + 1) % w.ref.length], w.refVia[j]])); - assert.match(ev('pzShareText(pzEval())'), /^Series of Tubes puzzle 2026-W44 ⭐⭐⭐ \$\d+k · seriesoftub\.es$/); - assert.equal(ev("JSON.parse(localStorage.getItem('sot-puzzles')).streak.n"), 1); - // A streak counts weeks in a row; a gap starts again. - ev("const p=pzLoad();pzStreak(p,'2026-W45');pzStreak(p,'2026-W45');pzStreak(p,'2026-W46');window.__p=p"); - assert.equal(ev('__p.streak.n'), 3); - ev("pzStreak(__p,'2026-W49')"); - assert.equal(ev('__p.streak.n'), 1); - assert.equal(ev('__p.streak.best'), 3); - assert.equal(ev("pzPrevKey('2027-W01')"), '2026-W53'); - assert.equal(ev("pzPrevKey('2026-W01')"), '2025-W52'); - assert.deepEqual(errors, []); -}); - -test('pack unlocking follows the stars, and bad progress data is ignored', () => { - const { ev, errors } = load(); - ev("localStorage.removeItem('sot-puzzles')"); - assert.equal(ev("pzPackOpen('hello')"), true); - assert.equal(ev("pzPackOpen('fire')"), false); - ev("ACT.pzStart({id:'aloha'})"); - assert.notEqual(ev('S&&S.mode'), 'puzzle', 'a locked puzzle does not start'); - ev("localStorage.setItem('sot-puzzles',JSON.stringify({s:{hello:{st:3},eurotrip:{st:3}}}))"); - assert.equal(ev("pzPackOpen('fire')"), true, '6 stars open pack 2'); - ev('ACT.puzzleMenu({})'); - assert.match(ev("document.getElementById('modalCard').textContent"), /Next pack, Speed Runs, unlocks at 14/); - ev("localStorage.setItem('sot-puzzles',JSON.stringify({s:{hello:{st:99,sp:'x'},nope:{st:3},__proto__:{st:3}},wk:{bad:{st:3}},streak:{n:-4,last:''}}))"); - const p = JSON.parse(ev('JSON.stringify(pzLoad())')); - assert.deepEqual(p.s, { hello: { st: 3, sp: null } }); - assert.deepEqual(p.wk, {}); - assert.deepEqual(p.streak, { last: null, n: 0, best: 0 }); - ev("localStorage.setItem('sot-puzzles','{nope')"); - assert.equal(ev('pzStarsTotal(pzLoad())'), 0); - assert.deepEqual(errors, []); -}); - -test('puzzle HUD fits a 360 px phone: bottom sheet, no tab bar, panels work', () => { - const { dom, ev, errors } = load(); - ev("innerWidth=360;innerHeight=740;dispatchEvent(new Event('resize'))"); - ev("pzBegin(pzDef('hello'))"); - assert.equal(ev("document.getElementById('tabbar').hidden"), true); - assert.equal(ev("document.getElementById('pzBox').hidden"), false); - ev("selectCity('lon')"); - assert.match(ev("document.getElementById('panelBody').textContent"), /Open a POP/); - ev("document.querySelector('#panelBody [data-act=pzPop]').click()"); - assert.ok(ev('!!S.pops.lon')); - ev("selectCity('par')"); - assert.equal(ev("document.getElementById('panel').hidden"), true, 'other cities do nothing'); - ev("pzLinkModal('lon','nyc')"); - assert.ok(ev("document.querySelectorAll('#modalCard .tierbtn').length") === 3, 'three sizes'); - assert.deepEqual(errors, []); - void dom; -}); - -test('puzzles in every language', () => { - for (const lang of ['de', 'es', 'fr', 'it', 'pt']) { - const { ev, errors } = load({ lang }); - ev("ACT.puzzleMenu({});pzBegin(pzDef('braces'))"); - build(ev, REF.braces.three); - const seen = ev("['pzBox','modalCard','hud'].map(id=>document.getElementById(id).textContent).join(' ')"); - assert.ok(!/puzzles\./.test(seen), `${lang}: no raw labels`); - assert.match(seen, /⭐/); - assert.deepEqual(errors, [], lang); - } -}); - -test('a POP in a thin market costs its higher monthly rent too, and the panel says so', () => { - const { ev, errors } = load(); - ev("pzBegin(pzDef('kiwi'))"); - assert.ok(ev('colo("suv")') > 1, 'Suva is a thin market'); - assert.equal(ev("pzPopCost('suv')"), ev("popCost('suv')+12*popMo('suv')")); - assert.ok(ev("pzPopCost('suv')") > ev("popCost('suv')+12*POP_MO")); - ev("selectCity('suv')"); - assert.ok(ev("document.getElementById('panelBody').textContent").includes(ev("fmt$(popMo('suv'))") + '/mo')); - assert.deepEqual(errors, []); -}); - -test('best spend: kept for the best star count, and a cheaper build at the same stars counts', () => { - const { ev, errors } = load(); - ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('braces'))"); - const rec = () => JSON.parse(ev("JSON.stringify(pzLoad().s.braces||null)")); - build(ev, REF.braces.one); - const two = evalP(ev).spend; - assert.deepEqual(rec(), { st: 2, sp: two }); - // A gold-plated third link: N-1 but over budget is still two stars, and dearer, so the best stays. - ev("ACT.pzLinkTo({a:'dub',b:'nyc'});ACT.pzVia({v:'havf'});ACT.pzLink({tier:2});closeModal()"); - assert.equal(evalP(ev).stars, 2); - assert.deepEqual(rec(), { st: 2, sp: two }); - // Shrinking it to 10G earns the third star: the best spend starts again at the 3-star build. - ev('ACT.pzTier({id:S.links[2].id,tier:0})'); - const three = evalP(ev); - assert.equal(three.stars, 3); - assert.deepEqual(rec(), { st: 3, sp: three.spend }); - // With a looser budget, a dearer 3-star build does not replace it; going back to the cheaper one keeps it. - ev('S.pz.budget=1e7;ACT.pzTier({id:S.links[0].id,tier:1})'); - assert.equal(evalP(ev).stars, 3); - assert.deepEqual(rec(), { st: 3, sp: three.spend }); - // A cheaper 3-star build after a dearer first one is recorded (the old code only recorded star rises). - ev("localStorage.removeItem('sot-puzzles')"); - ev('ACT.pzTier({id:S.links[1].id,tier:1})'); - const dear = evalP(ev).spend; - assert.deepEqual(rec(), { st: 3, sp: dear }); - ev('ACT.pzTier({id:S.links[1].id,tier:0});ACT.pzTier({id:S.links[0].id,tier:0})'); - assert.deepEqual(rec(), { st: 3, sp: three.spend }); - // Fewer stars never overwrite more. - ev('ACT.pzRmLink({id:S.links[2].id})'); - assert.deepEqual(rec(), { st: 3, sp: three.spend }); - ev('ACT.puzzleMenu({})'); - assert.ok(ev("document.getElementById('modalCard').textContent").includes('best ' + ev(`fmt$(${three.spend})`))); - assert.deepEqual(errors, []); -}); - test('main-game toasts and leftover buttons do nothing in a puzzle', () => { const { ev, errors } = load(); ev("ACT.start({});S.cash=1e7;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buildPop({city:'ams'});save(true)"); @@ -394,56 +516,13 @@ test('a city to avoid reads as a rule, not a goal that can fail', () => { assert.deepEqual(errors, []); }); -test('phone sheet: 40 px touch targets, pinned actions, and goal chips with a clear mark', () => { +test('a POP in a thin market costs its higher monthly rent too, and the panel says so', () => { const { ev, errors } = load(); - // jsdom has no layout: read the phone media rules from the page's stylesheet (Chromium at 360 px measures 40 px). - const rules = JSON.parse(ev(`JSON.stringify([...document.styleSheets].flatMap(s=>[...s.cssRules]).filter(r=>r.media&&/max-width: ?760px/.test(r.media.mediaText)) - .flatMap(m=>[...m.cssRules]).filter(r=>/#pzBox/.test(r.selectorText||'')).map(r=>({sel:r.selectorText,mh:r.style.getPropertyValue('min-height'),mw:r.style.getPropertyValue('min-width'),pos:r.style.getPropertyValue('position'),bottom:r.style.getPropertyValue('bottom')})))`)); - const tap = rules.find((r) => /#pzBox \.btns \.b/.test(r.sel) && /#pzBox \.pzh \.b/.test(r.sel)); - assert.ok(tap && parseFloat(tap.mh) >= 40 && parseFloat(tap.mw) >= 40, `Undo/Reset/Back/☰ are at least 40 px (${JSON.stringify(tap)})`); - const pin = rules.find((r) => /^#pzBox ?> ?\.btns$/.test(r.sel)); - assert.ok(pin && pin.pos === 'sticky' && parseFloat(pin.bottom) === 0, `the action row stays at the foot of a scrolling sheet (${JSON.stringify(pin)})`); - ev("innerWidth=360;innerHeight=740;dispatchEvent(new Event('resize'));pzBegin(pzDef('braces'))"); - const chips = () => ev("[...document.querySelectorAll('#pzBox .pzc')].map(x=>x.textContent).join('|')"); - assert.equal(chips(), '○ New York|○ London|○ Dublin', 'not reached yet: a hollow mark, nothing that looks cut off'); - assert.doesNotMatch(chips(), /…/); - build(ev, [['nyc', 'lon', 'grace']]); - ev("ACT.pzPop({city:'dub'})"); - assert.equal(chips(), '✓ New York|✓ London|◐ Dublin'); - assert.ok(ev("[...document.querySelectorAll('#pzBox button')].every(b=>b.classList.contains('b'))"), 'every sheet button is a .b the rule sizes'); - assert.deepEqual(errors, []); -}); - -test('results pull you on: Next is the big tap after three stars, stars left in the pack, and a nudge when 3 stars are one link away', () => { - const { ev, errors } = load(); - ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('braces'))"); - build(ev, REF.braces.one); - let card = ev("document.getElementById('modalCard').textContent"); - assert.equal(evalP(ev).stars, 2); - assert.match(card, /So close: one more link and a backhoe can't touch you\./, 'Dublin to New York would do it, within budget'); - assert.match(ev("document.getElementById('pzBox').textContent"), /So close/); - assert.match(card, /10 ⭐ left in this pack/, '4 puzzles × 3 stars, 2 won'); - assert.ok(ev("!!document.querySelector('#modalCard [data-act=pzRetry]')")); - assert.ok(!ev("document.querySelector('#modalCard .btns.cta').classList.contains('pzdone')")); - build(ev, [['dub', 'nyc', 'havf']]); - card = ev("document.getElementById('modalCard').textContent"); - assert.match(card, /9 ⭐ left in this pack/); - assert.ok(ev("document.querySelector('#modalCard .btns.cta').classList.contains('pzdone')"), 'three stars: the big Next layout'); - assert.ok(ev("document.activeElement===document.querySelector('#modalCard .pznext')"), 'the big button has the focus'); - assert.equal(ev("document.querySelector('#modalCard [data-act=pzRetry]')"), null, 'no retry after three stars'); - assert.match(ev("document.querySelector('#modalCard .pznext').textContent"), /More puzzles/, 'the last pack points back to the list'); - ev("pzBegin(pzDef('eurotrip'))");build(ev, REF.eurotrip.three); - assert.match(ev("document.querySelector('#modalCard .pznext').textContent"), /Next puzzle →/); - assert.equal(ev("document.activeElement.dataset.act"), 'pzStart'); - // No nudge when no single link fits the budget: an over-budget gold plate is not "close". - ev("pzBegin(pzDef('braces'));S.pz.budget=245000"); - build(ev, REF.braces.one); - assert.equal(evalP(ev).stars, 2); - assert.doesNotMatch(ev("document.getElementById('modalCard').textContent"), /So close/); - assert.match(ev("document.getElementById('modalCard').textContent"), /One backhoe away/); - // A finished pack says so. - ev("localStorage.setItem('sot-puzzles',JSON.stringify({s:{sharks:{st:3},braces:{st:3},nofra:{st:3},fatpipes:{st:2}}}));pzBegin(pzDef('fatpipes'))"); - build(ev, REF.fatpipes.three); - assert.match(ev("document.getElementById('modalCard').textContent"), /Every star in this pack is yours/); + ev("pzBegin(pzDef('kiwi'))"); + assert.ok(ev('colo("suv")') > 1, 'Suva is a thin market'); + assert.equal(ev("pzPopCost('suv')"), ev("popCost('suv')+12*popMo('suv')")); + assert.ok(ev("pzPopCost('suv')") > ev("popCost('suv')+12*POP_MO")); + ev("selectCity('suv')"); + assert.ok(ev("document.getElementById('panelBody').textContent").includes(ev("fmt$(popMo('suv'))") + '/mo')); assert.deepEqual(errors, []); });