diff --git a/engine/src/achievements.ts b/engine/src/achievements.ts index 10cac0f..24ffdb7 100644 --- a/engine/src/achievements.ts +++ b/engine/src/achievements.ts @@ -9,7 +9,7 @@ import { GameState, MapName, Player, PowerPlantType } from './gamestate'; // custom map that graduates gets one then. A new custom map must be added here, // so the choice is made on purpose. The lookup below already handles a map // with no badge. -type CustomMapName = 'HawaiiCustom'; +type CustomMapName = 'HawaiiCustom' | 'SwitzerlandCustom'; const mapAchievements: Record, string> = { Germany: 'germany-champion', USA: 'usa-champion', diff --git a/engine/src/available-moves.ts b/engine/src/available-moves.ts index 086b046..51cbd57 100644 --- a/engine/src/available-moves.ts +++ b/engine/src/available-moves.ts @@ -7,6 +7,7 @@ import { Phase, Player, playerColors, + PowerPlant, PowerPlantType, ResourceType, } from './gamestate'; @@ -15,6 +16,30 @@ import { MoveName } from './move'; import prices from './prices'; import { minBy } from './utils'; +/** SwitzerlandCustom: the plants the Alpine +1 applies to — the green (ecological) plants only, never fusion. */ +export function alpineEligible(pp: PowerPlant): boolean { + return pp.type == PowerPlantType.Wind; +} + +/** SwitzerlandCustom: the Alpine cities the player owns. */ +export function alpineCitiesOwned(G: GameState, player: Player): number { + const alpine = new Set(G.map.cities.filter((c) => c.alpine).map((c) => c.name)); + return alpine.size ? player.cities.filter((c) => alpine.has(c.name)).length : 0; +} + +/** + * SwitzerlandCustom, Bureaucracy: how many more ecological plants still get the Alpine +1 this round. + * Each ecological plant fired powers one more city, up to the number of Alpine cities owned. + */ +export function alpineBonusLeft(G: GameState, player: Player): number { + const owned = alpineCitiesOwned(G, player); + if (!owned) return 0; + const fired = player.powerPlants.filter( + (pp) => alpineEligible(pp) && !player.powerPlantsNotUsed.includes(pp.number) + ).length; + return Math.max(0, owned - fired); +} + // Central Europe: a player whose network includes Wien buys garbage $1 cheaper, but // never for less than $1 ("his cost per piece may not be 0" — Original and Recharged). export function garbagePrice(G: GameState, player: Player, printedPrice: number): number { @@ -596,7 +621,9 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves { toUse.push({ powerPlant: powerPlant.number, resourcesSpent: [], - citiesPowered: powerPlant.citiesPowered, + citiesPowered: + powerPlant.citiesPowered + + (alpineEligible(powerPlant) && alpineBonusLeft(G, player) > 0 ? 1 : 0), }); break; diff --git a/engine/src/engine.ts b/engine/src/engine.ts index b092686..f775835 100644 --- a/engine/src/engine.ts +++ b/engine/src/engine.ts @@ -3,6 +3,8 @@ import { cloneDeep, isEqual, range } from 'lodash'; import seedrandom from 'seedrandom'; import { applyAnalysisMoney, isAnalysisMoneyCommand } from './analysis-money'; import { + alpineCitiesOwned, + alpineEligible, availableMoves, buildOptions, coalOilOverCapacity, @@ -3231,10 +3233,14 @@ export function calculateMaxCitiesPowered(G: GameState, player: Player) { permutations.push(perm); } + const alpineOwned = alpineCitiesOwned(G, player); let max = 0; permutations.forEach((permutation) => { if (isValid(player, permutation)) { - const citiesPowered = permutation.map((p) => p.citiesPowered).reduce((a, b) => a + b, 0); + const citiesPowered = + permutation.map((p) => p.citiesPowered).reduce((a, b) => a + b, 0) + + // SwitzerlandCustom: +1 per ecological plant, capped by the Alpine cities owned. + Math.min(alpineOwned, permutation.filter(alpineEligible).length); max = Math.max(max, citiesPowered); } }); diff --git a/engine/src/gamestate.ts b/engine/src/gamestate.ts index 3c0a514..ec676b4 100644 --- a/engine/src/gamestate.ts +++ b/engine/src/gamestate.ts @@ -35,7 +35,8 @@ export type MapName = | 'Bremen' | 'Manhattan' | 'Chile' - | 'HawaiiCustom'; + | 'HawaiiCustom' + | 'SwitzerlandCustom'; export type Variant = 'original' | 'recharged'; // 'standard' is the base game's deck; deck1 and deck2 are The New Power Plants // (Set 1) and Set 2. 'shuffled' plays every plant of all three decks together; diff --git a/engine/src/maps.ts b/engine/src/maps.ts index 413f1d7..b1c4abb 100644 --- a/engine/src/maps.ts +++ b/engine/src/maps.ts @@ -25,6 +25,7 @@ import { map as quebec } from './maps/quebec'; import { map as russia } from './maps/russia'; import { map as southafrica } from './maps/southafrica'; import { map as spainportugal } from './maps/spainportugal'; +import { map as switzerland } from './maps/switzerland'; import { map as ukireland } from './maps/ukireland'; export interface City { @@ -64,6 +65,9 @@ export interface City { // Chile: the grid this city belongs to. Until Step 3 a player with cities buys only from their grid's market // (North, or the main market for Central). grid?: 'North' | 'Central'; + // SwitzerlandCustom: an Alpine city. Each ecological plant its owner fires powers one more city, + // up to the number of Alpine cities that player owns (see alpineBonusLeft). + alpine?: boolean; } export interface Connection { @@ -74,6 +78,10 @@ export interface Connection { via?: [number, number]; // Purely visual: a sea crossing, drawn as a dashed blue line. Pricing is unchanged. sea?: boolean; + // Purely visual: an air link (SwitzerlandCustom's helicopters), drawn dotted. Pricing is unchanged. + air?: boolean; + // Purely visual: a railway (SwitzerlandCustom's Glacier Express), drawn as red rails with ties. Pricing is unchanged. + rail?: boolean; // Does not count when deciding which regions are neighbours (region selection). // The link itself still exists whenever both of its cities are in play. ignoreForRegions?: boolean; @@ -194,7 +202,7 @@ export interface GameMap { } // Community custom maps: selectable by name, never drawn by 'Random'. -export const customMaps: GameMap[] = [hawaii]; +export const customMaps: GameMap[] = [hawaii, switzerland]; export const maps: GameMap[] = [ america, diff --git a/engine/src/maps/switzerland.ts b/engine/src/maps/switzerland.ts new file mode 100644 index 0000000..a2f03b0 --- /dev/null +++ b/engine/src/maps/switzerland.ts @@ -0,0 +1,235 @@ +import { GameMap } from './../maps'; + +// SwitzerlandCustom: a community custom map (draft). The seven Swiss Grossregionen. +// Flat, dense north; Alpine south with dear links (+6 into an Alpine city, +2 over a named pass). +// Link prices come from the real distances; the layout is spread for legibility. +// Generated by .drafts/switzerland/gen_swiss.py. + +export enum Regions { + Blue = 'blue', // Lake Geneva + Yellow = 'yellow', // Espace Mittelland (Bern, Bernese Oberland) + Purple = 'purple', // Northwestern (Basel, Aargau) + Red = 'red', // Zurich + Green = 'green', // Eastern (St. Gallen, Graubunden) + Cyan = 'cyan', // Central (Lucerne) + Pink = 'pink', // Ticino +} + +export enum Cities { + Geneva = 'Geneva', + Nyon = 'Nyon', + Lausanne = 'Lausanne', + Montreux = 'Montreux', + Sion = 'Sion', + Zermatt = 'Zermatt', + Yverdon = 'Yverdon', + Neuchatel = 'Neuchatel', + Biel = 'Biel', + Bern = 'Bern', + Fribourg = 'Fribourg', + Thun = 'Thun', + Interlaken = 'Interlaken', + Grindelwald = 'Grindelwald', + Basel = 'Basel', + Liestal = 'Liestal', + Rheinfelden = 'Rheinfelden', + Aarau = 'Aarau', + Brugg = 'Brugg', + Baden = 'Baden', + Zofingen = 'Zofingen', + Zurich = 'Zurich', + Winterthur = 'Winterthur', + Kloten = 'Kloten', + Uster = 'Uster', + Dietikon = 'Dietikon', + Wadenswil = 'Wadenswil', + Bulach = 'Bulach', + Schaffhausen = 'Schaffhausen', + Frauenfeld = 'Frauenfeld', + StGallen = 'St. Gallen', + Appenzell = 'Appenzell', + Chur = 'Chur', + Davos = 'Davos', + StMoritz = 'St. Moritz', + Lucerne = 'Lucerne', + Zug = 'Zug', + Schwyz = 'Schwyz', + Altdorf = 'Altdorf', + Engelberg = 'Engelberg', + Andermatt = 'Andermatt', + Sarnen = 'Sarnen', + Airolo = 'Airolo', + Bellinzona = 'Bellinzona', + Locarno = 'Locarno', + Lugano = 'Lugano', + Mendrisio = 'Mendrisio', + Biasca = 'Biasca', + Chiasso = 'Chiasso', +} + +export const map: GameMap = { + name: 'SwitzerlandCustom', + cities: [ + { name: Cities.Geneva, region: Regions.Blue, x: 110, y: 950, stepSlots: [3, 3, 3] }, + { name: Cities.Nyon, region: Regions.Blue, x: 149, y: 837 }, + { name: Cities.Lausanne, region: Regions.Blue, x: 264, y: 779 }, + { name: Cities.Montreux, region: Regions.Blue, x: 373, y: 830 }, + { name: Cities.Sion, region: Regions.Blue, x: 512, y: 922 }, + { name: Cities.Zermatt, region: Regions.Blue, x: 640, y: 1023, alpine: true }, + { name: Cities.Yverdon, region: Regions.Blue, x: 276, y: 658 }, + { name: Cities.Neuchatel, region: Regions.Yellow, x: 368, y: 553 }, + { name: Cities.Biel, region: Regions.Yellow, x: 468, y: 476 }, + { name: Cities.Bern, region: Regions.Yellow, x: 543, y: 570 }, + { name: Cities.Fribourg, region: Regions.Yellow, x: 438, y: 650 }, + { name: Cities.Thun, region: Regions.Yellow, x: 551, y: 690 }, + { name: Cities.Interlaken, region: Regions.Yellow, x: 671, y: 698 }, + { name: Cities.Grindelwald, region: Regions.Yellow, x: 773, y: 761, alpine: true }, + { name: Cities.Basel, region: Regions.Purple, x: 539, y: 243 }, + { name: Cities.Liestal, region: Regions.Purple, x: 573, y: 359 }, + { name: Cities.Rheinfelden, region: Regions.Purple, x: 656, y: 266 }, + { name: Cities.Aarau, region: Regions.Purple, x: 691, y: 381 }, + { name: Cities.Brugg, region: Regions.Purple, x: 744, y: 154 }, + { name: Cities.Baden, region: Regions.Purple, x: 776, y: 270 }, + { name: Cities.Zofingen, region: Regions.Purple, x: 618, y: 476 }, + { name: Cities.Zurich, region: Regions.Red, x: 965, y: 420 }, + { name: Cities.Winterthur, region: Regions.Red, x: 997, y: 229 }, + { name: Cities.Kloten, region: Regions.Red, x: 911, y: 313 }, + { name: Cities.Uster, region: Regions.Red, x: 1051, y: 336 }, + { name: Cities.Dietikon, region: Regions.Red, x: 811, y: 385 }, + { name: Cities.Wadenswil, region: Regions.Red, x: 1064, y: 487 }, + { name: Cities.Bulach, region: Regions.Red, x: 873, y: 199 }, + { name: Cities.Schaffhausen, region: Regions.Green, x: 959, y: 115 }, + { name: Cities.Frauenfeld, region: Regions.Green, x: 1117, y: 224 }, + { name: Cities.StGallen, region: Regions.Green, x: 1217, y: 319 }, + { name: Cities.Appenzell, region: Regions.Green, x: 1169, y: 429 }, + { name: Cities.Chur, region: Regions.Green, x: 1223, y: 626 }, + { name: Cities.Davos, region: Regions.Green, x: 1340, y: 651, alpine: true }, + { name: Cities.StMoritz, region: Regions.Green, x: 1327, y: 793, alpine: true }, + { name: Cities.Lucerne, region: Regions.Cyan, x: 730, y: 518 }, + { name: Cities.Zug, region: Regions.Cyan, x: 868, y: 490 }, + { name: Cities.Schwyz, region: Regions.Cyan, x: 967, y: 558 }, + { name: Cities.Altdorf, region: Regions.Cyan, x: 1009, y: 670 }, + { name: Cities.Engelberg, region: Regions.Cyan, x: 889, y: 649, alpine: true }, + { name: Cities.Andermatt, region: Regions.Cyan, x: 930, y: 762, alpine: true }, + { name: Cities.Sarnen, region: Regions.Cyan, x: 771, y: 631 }, + { name: Cities.Airolo, region: Regions.Pink, x: 879, y: 871, alpine: true }, + { name: Cities.Bellinzona, region: Regions.Pink, x: 1103, y: 925 }, + { name: Cities.Locarno, region: Regions.Pink, x: 976, y: 943 }, + { name: Cities.Lugano, region: Regions.Pink, x: 1053, y: 1034 }, + { name: Cities.Mendrisio, region: Regions.Pink, x: 983, y: 1132 }, + { name: Cities.Biasca, region: Regions.Pink, x: 1026, y: 834 }, + { name: Cities.Chiasso, region: Regions.Pink, x: 1104, y: 1143 }, + ], + connections: [ + { nodes: [Cities.Geneva, Cities.Nyon], cost: 5 }, + { nodes: [Cities.Nyon, Cities.Lausanne], cost: 8 }, + { nodes: [Cities.Lausanne, Cities.Montreux], cost: 6 }, + { nodes: [Cities.Lausanne, Cities.Fribourg], cost: 13 }, + { nodes: [Cities.Montreux, Cities.Sion], cost: 10 }, + { nodes: [Cities.Montreux, Cities.Fribourg], cost: 11 }, + { nodes: [Cities.Sion, Cities.Zermatt], cost: 16 }, + { nodes: [Cities.Zermatt, Cities.Thun], cost: 29 }, // Lotschberg + { nodes: [Cities.Sion, Cities.Thun], cost: 18 }, // pass + { nodes: [Cities.Neuchatel, Cities.Biel], cost: 7 }, + { nodes: [Cities.Neuchatel, Cities.Bern], cost: 10 }, + { nodes: [Cities.Biel, Cities.Bern], cost: 7 }, + { nodes: [Cities.Bern, Cities.Fribourg], cost: 7 }, + { nodes: [Cities.Bern, Cities.Thun], cost: 6 }, + { nodes: [Cities.Thun, Cities.Interlaken], cost: 5 }, + { nodes: [Cities.Interlaken, Cities.Grindelwald], cost: 10 }, + { nodes: [Cities.Grindelwald, Cities.Andermatt], cost: 19 }, // Grimsel + { nodes: [Cities.Bern, Cities.Lucerne], cost: 17 }, + { nodes: [Cities.Biel, Cities.Liestal], cost: 13 }, + { nodes: [Cities.Basel, Cities.Rheinfelden], cost: 4 }, + { nodes: [Cities.Basel, Cities.Liestal], cost: 3 }, + { nodes: [Cities.Liestal, Cities.Rheinfelden], cost: 3 }, + { nodes: [Cities.Liestal, Cities.Aarau], cost: 6 }, + { nodes: [Cities.Rheinfelden, Cities.Brugg], cost: 8 }, + { nodes: [Cities.Aarau, Cities.Brugg], cost: 4 }, + { nodes: [Cities.Brugg, Cities.Baden], cost: 3 }, + { nodes: [Cities.Baden, Cities.Dietikon], cost: 3 }, + { nodes: [Cities.Aarau, Cities.Lucerne], cost: 11 }, + { nodes: [Cities.Dietikon, Cities.Zurich], cost: 3 }, + { nodes: [Cities.Zurich, Cities.Kloten], cost: 3 }, + { nodes: [Cities.Kloten, Cities.Winterthur], cost: 3 }, + { nodes: [Cities.Zurich, Cities.Uster], cost: 3 }, + { nodes: [Cities.Uster, Cities.Winterthur], cost: 4 }, + { nodes: [Cities.Zurich, Cities.Wadenswil], cost: 5 }, + { nodes: [Cities.Wadenswil, Cities.Zug], cost: 3 }, + { nodes: [Cities.Zurich, Cities.Zug], cost: 6 }, + { nodes: [Cities.Winterthur, Cities.Schaffhausen], cost: 6 }, + { nodes: [Cities.Winterthur, Cities.Frauenfeld], cost: 4 }, + { nodes: [Cities.Wadenswil, Cities.Schwyz], cost: 6 }, + { nodes: [Cities.Uster, Cities.StGallen], cost: 13 }, + { nodes: [Cities.Schaffhausen, Cities.Frauenfeld], cost: 6 }, + { nodes: [Cities.Frauenfeld, Cities.StGallen], cost: 10 }, + { nodes: [Cities.StGallen, Cities.Appenzell], cost: 3 }, + { nodes: [Cities.Appenzell, Cities.Chur], cost: 14 }, + { nodes: [Cities.StGallen, Cities.Chur], cost: 16 }, + { nodes: [Cities.Chur, Cities.Davos], cost: 12 }, + { nodes: [Cities.Davos, Cities.StMoritz], cost: 16 }, // Fluela + { nodes: [Cities.Chur, Cities.StMoritz], cost: 19 }, // Albula + { nodes: [Cities.Chur, Cities.Bellinzona], cost: 23 }, // San Bernardino + { nodes: [Cities.Chur, Cities.Andermatt], cost: 27, ignoreForRegions: true }, // Oberalp + { nodes: [Cities.Lucerne, Cities.Zug], cost: 5 }, + { nodes: [Cities.Zug, Cities.Schwyz], cost: 5 }, + { nodes: [Cities.Lucerne, Cities.Schwyz], cost: 7 }, + { nodes: [Cities.Schwyz, Cities.Altdorf], cost: 4 }, + { nodes: [Cities.Lucerne, Cities.Engelberg], cost: 13 }, + { nodes: [Cities.Engelberg, Cities.Altdorf], cost: 13 }, // Surenen + { nodes: [Cities.Altdorf, Cities.Andermatt], cost: 13 }, + { nodes: [Cities.Andermatt, Cities.Airolo], cost: 16 }, // Gotthard + { nodes: [Cities.Bellinzona, Cities.Locarno], cost: 4 }, + { nodes: [Cities.Bellinzona, Cities.Lugano], cost: 5 }, + { nodes: [Cities.Locarno, Cities.Lugano], cost: 6 }, + { nodes: [Cities.Lugano, Cities.Mendrisio], cost: 4 }, + { nodes: [Cities.Airolo, Cities.Biasca], cost: 14 }, + { nodes: [Cities.Biasca, Cities.Bellinzona], cost: 5 }, + { nodes: [Cities.Mendrisio, Cities.Chiasso], cost: 3 }, + { nodes: [Cities.Lugano, Cities.Chiasso], cost: 5 }, + { nodes: [Cities.Aarau, Cities.Zofingen], cost: 3 }, + { nodes: [Cities.Zofingen, Cities.Lucerne], cost: 10 }, + { nodes: [Cities.Liestal, Cities.Zofingen], cost: 9 }, // Hauenstein + { nodes: [Cities.Bern, Cities.Zofingen], cost: 13 }, + { nodes: [Cities.Kloten, Cities.Bulach], cost: 3 }, + { nodes: [Cities.Bulach, Cities.Schaffhausen], cost: 5 }, + { nodes: [Cities.Bulach, Cities.Baden], cost: 5 }, + { nodes: [Cities.Bulach, Cities.Winterthur], cost: 3 }, + { nodes: [Cities.Lucerne, Cities.Sarnen], cost: 4 }, + { nodes: [Cities.Sarnen, Cities.Interlaken], cost: 11 }, // Brunig + { nodes: [Cities.Sarnen, Cities.Engelberg], cost: 10 }, + { nodes: [Cities.Lausanne, Cities.Yverdon], cost: 7 }, + { nodes: [Cities.Yverdon, Cities.Neuchatel], cost: 8 }, + { nodes: [Cities.Yverdon, Cities.Fribourg], cost: 10 }, + { nodes: [Cities.Altdorf, Cities.Biasca], cost: 18 }, // Gotthard Base Tunnel + { nodes: [Cities.Biasca, Cities.Chur], cost: 19 }, // Lukmanier + { nodes: [Cities.Zurich, Cities.Winterthur], cost: 5 }, + { nodes: [Cities.Zurich, Cities.Baden], cost: 5 }, + { nodes: [Cities.Uster, Cities.Wadenswil], cost: 3 }, + { nodes: [Cities.Biel, Cities.Zofingen], cost: 14 }, + { nodes: [Cities.Winterthur, Cities.StGallen], cost: 13 }, + { nodes: [Cities.Dietikon, Cities.Zug], cost: 7 }, + { nodes: [Cities.Neuchatel, Cities.Fribourg], cost: 7 }, + { nodes: [Cities.Montreux, Cities.Interlaken], cost: 22 }, // GoldenPass + // Lake Geneva steamer: the shore road east of Geneva is French, so Geneva's second way out is the boat. + { nodes: [Cities.Geneva, Cities.Montreux], cost: 14, sea: true }, + // The Glacier Express (Zermatt - Furka - Andermatt). + { nodes: [Cities.Zermatt, Cities.Andermatt], cost: 18, rail: true, ignoreForRegions: true }, + // Helicopters: the outskirts only, never cross-country. + { nodes: [Cities.Zermatt, Cities.Mendrisio], cost: 20, air: true, ignoreForRegions: true }, + { nodes: [Cities.Mendrisio, Cities.StMoritz], cost: 20, air: true, ignoreForRegions: true, via: [1197, 1005] }, + { nodes: [Cities.Schaffhausen, Cities.Basel], cost: 20, air: true, ignoreForRegions: true, via: [708, 45] }, + ], + layout: 'Landscape', + // An expensive country: coal opens at $3, oil at $4, cheese at $6; uranium as usual. + startingResources: [18, 15, 9, 2], + mapSpecificRules: + 'Alpine cities (Zermatt, Grindelwald, Engelberg, Andermatt, Airolo, Davos, St. Moritz) are dear to reach, but hydro ' + + 'pays: each green (ecological) plant you fire powers one more city, but only as many of your green plants as you own ' + + 'Alpine cities get it. A plant never gets more than +1 (one green plant and seven Alpine cities is still +1). ' + + 'Fusion and fuel-burning plants never get it, ' + + 'and you still never power more cities than you own. It follows the plant type, so it works with every deck. ' + + 'Switzerland is expensive: coal opens at $3, oil at $4 and cheese at $6. ' + + 'Geneva is neutral ground: all three of its spaces are open from Step 1. ' + + 'The dotted blue link is the Lake Geneva steamer; the Glacier Express runs Zermatt to Andermatt.', +}; diff --git a/engine/src/switzerland-custom.spec.ts b/engine/src/switzerland-custom.spec.ts new file mode 100644 index 0000000..c34ceef --- /dev/null +++ b/engine/src/switzerland-custom.spec.ts @@ -0,0 +1,155 @@ +import { expect } from 'chai'; +import { alpineBonusLeft, availableMoves } from './available-moves'; +import { calculateMaxCitiesPowered, setup } from './engine'; +import { GameState, Phase, Player, PowerPlant, PowerPlantType } from './gamestate'; +import { map as switzerland } from './maps/switzerland'; +import { MoveName } from './move'; + +const wind = (number: number, citiesPowered: number): PowerPlant => ({ + number, + type: PowerPlantType.Wind, + cost: 0, + citiesPowered, +}); +const coal = (number: number, citiesPowered: number): PowerPlant => ({ + number, + type: PowerPlantType.Coal, + cost: 2, + citiesPowered, +}); + +/** A Bureaucracy-phase game with the whole Swiss board, and player 0 holding these plants and cities. */ +function bureaucracy(plants: PowerPlant[], cities: string[], coalLeft = 0): { G: GameState; player: Player } { + const G = setup(3, { map: 'SwitzerlandCustom', variant: 'original' }, 'swiss'); + G.map = JSON.parse(JSON.stringify(switzerland)); + G.phase = Phase.Bureaucracy; + const player = G.players[0]; + player.powerPlants = plants; + player.powerPlantsNotUsed = plants.map((p) => p.number); + player.cities = cities.map((name) => ({ name, position: 0 })); + player.coalLeft = coalLeft; + return { G, player }; +} +const offered = (G: GameState, player: Player) => + (availableMoves(G, player)[MoveName.UsePowerPlant] ?? []) as { powerPlant: number; citiesPowered: number }[]; +const powers = (G: GameState, player: Player, plant: number) => + offered(G, player).find((m) => m.powerPlant == plant)!.citiesPowered; + +describe('SwitzerlandCustom', () => { + it('is never dealt by Random', () => { + for (let s = 0; s < 300; s++) { + for (const variant of ['original', 'recharged'] as const) { + expect(setup(3, { map: 'Random', variant }, 'r' + s).map.name).to.not.equal('SwitzerlandCustom'); + } + } + }); + + it('has 49 cities, 7 per region, every city linked, no duplicate links', () => { + const byRegion = new Map(); + switzerland.cities.forEach((c) => byRegion.set(c.region, (byRegion.get(c.region) ?? 0) + 1)); + expect(switzerland.cities.length).to.equal(49); + expect([...byRegion.values()]).to.deep.equal([7, 7, 7, 7, 7, 7, 7]); + const names = new Set(switzerland.cities.map((c) => c.name)); + const seen = new Set(); + const degree = new Map(); + for (const l of switzerland.connections) { + l.nodes.forEach((n) => expect(names.has(n), n).to.equal(true)); + const k = [...l.nodes].sort().join('|'); + expect(seen.has(k), k).to.equal(false); + seen.add(k); + l.nodes.forEach((n) => degree.set(n, (degree.get(n) ?? 0) + 1)); + } + for (const n of names) expect(degree.get(n) ?? 0, n).to.be.at.least(2); + }); + + it('deals every player count a playable board', () => { + for (let players = 2; players <= 6; players++) { + for (let s = 0; s < 50; s++) { + const G = setup(players, { map: 'SwitzerlandCustom', variant: 'original' }, 'p' + s); + expect(G.map.name).to.equal('SwitzerlandCustom'); + expect(G.map.cities.length).to.be.greaterThan(0); + } + } + }); + + it('is an expensive country: coal from $3, oil from $4, cheese from $6, uranium as usual', () => { + for (const variant of ['original', 'recharged'] as const) { + const G = setup(4, { map: 'SwitzerlandCustom', variant }, 'prices'); + expect([G.coalMarket, G.oilMarket, G.garbageMarket, G.uraniumMarket], variant).to.deep.equal([ + 18, 15, 9, 2, + ]); + } + }); + + it("opens all three of Geneva's spaces from Step 1, and only Geneva's", () => { + for (const c of switzerland.cities) { + expect(c.stepSlots, c.name).to.deep.equal(c.name == 'Geneva' ? [3, 3, 3] : undefined); + } + }); + + it('marks the seven Alpine cities', () => { + expect( + switzerland.cities + .filter((c) => c.alpine) + .map((c) => c.name) + .sort() + ).to.deep.equal(['Airolo', 'Andermatt', 'Davos', 'Engelberg', 'Grindelwald', 'St. Moritz', 'Zermatt'].sort()); + }); + + describe('Alpine hydro: +1 per ecological plant, capped by Alpine cities owned', () => { + it('gives nothing without an Alpine city', () => { + const { G, player } = bureaucracy([wind(13, 1)], ['Bern', 'Thun']); + expect(powers(G, player, 13)).to.equal(1); + expect(calculateMaxCitiesPowered(G, player)).to.equal(1); + }); + + it('gives one ecological plant +1 with one Alpine city, and not the second', () => { + const { G, player } = bureaucracy([wind(13, 1), wind(18, 2)], ['Zermatt', 'Bern', 'Thun', 'Sion', 'Biel']); + expect(alpineBonusLeft(G, player)).to.equal(1); + expect(powers(G, player, 13)).to.equal(2); + expect(powers(G, player, 18)).to.equal(3); + // fire 18 with the bonus: the bonus is spent, 13 is back to its printed value + player.powerPlantsNotUsed = [13]; + expect(alpineBonusLeft(G, player)).to.equal(0); + expect(powers(G, player, 13)).to.equal(1); + // best case across both: 1 + 2 + one bonus + player.powerPlantsNotUsed = [13, 18]; + expect(calculateMaxCitiesPowered(G, player)).to.equal(4); + }); + + it('gives both ecological plants +1 with two Alpine cities', () => { + const { G, player } = bureaucracy( + [wind(13, 1), wind(18, 2)], + ['Zermatt', 'Davos', 'Bern', 'Thun', 'Sion', 'Biel'] + ); + expect(calculateMaxCitiesPowered(G, player)).to.equal(5); + player.powerPlantsNotUsed = [13]; + expect(powers(G, player, 13)).to.equal(2); + }); + + it('never boosts fuelled plants, and never powers more cities than owned', () => { + const { G, player } = bureaucracy([coal(10, 2), wind(13, 1)], ['Zermatt', 'Bern'], 2); + expect(powers(G, player, 10)).to.equal(2); + expect(powers(G, player, 13)).to.equal(2); + expect(calculateMaxCitiesPowered(G, player)).to.equal(2); + }); + + it('never boosts the fusion plant (John, 2026-11-19: 6 + 1 = 7 from one card is too strong)', () => { + const fusion: PowerPlant = { number: 50, type: PowerPlantType.Nuclear, cost: 0, citiesPowered: 6 }; + const cities = ['Zermatt', 'Bern', 'Thun', 'Sion', 'Biel', 'Lausanne', 'Nyon', 'Montreux']; + const { G, player } = bureaucracy([fusion, wind(13, 1)], cities); + expect(powers(G, player, 50)).to.equal(6); + // the one Alpine +1 goes to the green plant: 6 + (1 + 1) + expect(calculateMaxCitiesPowered(G, player)).to.equal(8); + player.powerPlantsNotUsed = [50]; + expect(powers(G, player, 50)).to.equal(6); + }); + + it('leaves every other map untouched', () => { + const { G, player } = bureaucracy([wind(13, 1)], ['Zermatt']); + G.map = setup(3, { map: 'Germany', variant: 'original' }, 'g').map; + expect(alpineBonusLeft(G, player)).to.equal(0); + expect(powers(G, player, 13)).to.equal(1); + }); + }); +}); diff --git a/viewer/src/components/Game.vue b/viewer/src/components/Game.vue index 6b2510b..cfaa04d 100644 --- a/viewer/src/components/Game.vue +++ b/viewer/src/components/Game.vue @@ -1070,7 +1070,7 @@ import { formatDuration } from '../util/time'; import { playerOrderForDisplay } from '../util/player-order'; import { freePlantMoves, canAutoFinishPowering, poweredCities } from '../util/powering'; import { bidRevision, canReopenPowering } from 'powergrid-engine/src/choice-revisions'; -import { availableMoves, canStoreFuel } from 'powergrid-engine/src/available-moves'; +import { alpineCitiesOwned, alpineEligible, availableMoves, canStoreFuel } from 'powergrid-engine/src/available-moves'; import { powerIncome, updatePlayerCapacity } from 'powergrid-engine/src/engine'; import { inactiveMapNetwork } from '../util/inactive-map'; import { desktopBoardLayout, PLAYER_SETTING_ROW_HEIGHT } from '../util/board-layout'; @@ -1439,7 +1439,13 @@ export default class Game extends Vue { !this.G.currentPlayers.includes(this.player) ) return undefined; - return this.G.players[this.player]?.powerPlants.reduce((total, plant) => total + plant.citiesPowered, 0); + const player = this.G.players[this.player]; + if (!player) return undefined; + return ( + player.powerPlants.reduce((total, plant) => total + plant.citiesPowered, 0) + + // SwitzerlandCustom: +1 per green plant, up to the Alpine cities owned. + (this.G.map ? Math.min(alpineCitiesOwned(this.G, player), player.powerPlants.filter(alpineEligible).length) : 0) + ); } get poweringPlayer() { @@ -2570,9 +2576,21 @@ export default class Game extends Vue { break; } + // Send the engine's own offer for a single-fuel plant: it can differ from the printed card + // (SwitzerlandCustom's Alpine +1 and aged cheese). Hybrids carry the mix the player picked. + const offered = + powerPlant.type == PowerPlantType.Hybrid || powerPlant.type == PowerPlantType.GarbageOilHybrid + ? undefined + : this.G!.players[this.player!].availableMoves?.[MoveName.UsePowerPlant]?.find( + (m) => m.powerPlant == powerPlant.number + ); this.sendMove({ name: MoveName.UsePowerPlant, - data: { powerPlant: powerPlant.number, resourcesSpent, citiesPowered: powerPlant.citiesPowered }, + data: offered ?? { + powerPlant: powerPlant.number, + resourcesSpent, + citiesPowered: powerPlant.citiesPowered, + }, }); this.disablePass = true; diff --git a/viewer/src/components/boards/Map.vue b/viewer/src/components/boards/Map.vue index 101a02c..d31bbe4 100644 --- a/viewer/src/components/boards/Map.vue +++ b/viewer/src/components/boards/Map.vue @@ -92,7 +92,7 @@ :d="linkPath(connection)" fill="none" stroke-width="10" - :stroke="connection.sea ? SEA_OUTER : 'black'" + :stroke="linkOuter(connection)" /> - + + + @@ -243,6 +255,27 @@ + + +