From 49c2a80f7efcfa701156cfd680b7617f892e78b0 Mon Sep 17 00:00:00 2001 From: goldjohn6 Date: Fri, 20 Nov 2026 11:19:34 -0800 Subject: [PATCH] SwitzerlandCustom: the cheese cellar (#174) * SwitzerlandCustom: the cheese cellar (garbage is cheese, and it ripens) Cheese kept in a garbage plant that rests through Bureaucracy (does not fire) ages; an aged cube burns as two, stays aged until burned, never ages again, and still takes one storage space. - Player.agedCheese (read through agedCheese(): never above garbageLeft, so cubes lost to storage go aged-first). - cheeseMix: the engine offers the thriftiest mix (least waste, then fewest cubes); UsePowerPlant.agedSpent records the aged cubes burned. - ripenCheese at the Bureaucracy pass: a resting plant ripens only the room it has left (aged cubes are counted in the plants that fired first). Logged. - calculateMaxCitiesPowered counts aged cheese as double. - Bots burn aged cheese first and fire fresh-cheese plants last, so spare cheese plants rest and ripen. - Viewer: "N aged" above the player's garbage count. Bot sims (150 games each, 3/4/5p): 3-5 cubes age per game, 18-25% of cheese runs use aged cheese; Step 3 is reached more often (4p 79%->89%, 5p 34%->45%). Co-Authored-By: Claude Opus 5.5 * Cheese cellar: an aged cube stays aged after its neighbour burns Found in John's local playtest (plant 6, two aged, used one): the aged count was read after the cubes left, so the cap by cubes held wiped the remaining aged cube. Count it before. The "N aged" label moves below the cheese count, clear of the plant cards, and the pass warning counts aged cheese as double. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- engine/src/available-moves.ts | 67 ++++++++++++++- engine/src/engine.ts | 36 +++++++- engine/src/gamestate.ts | 3 + engine/src/maps/switzerland.ts | 3 + engine/src/move.ts | 2 + engine/src/switzerland-custom.spec.ts | 114 +++++++++++++++++++++++++- viewer/src/components/Game.vue | 3 +- viewer/src/components/PlayerBoard.vue | 10 +++ 8 files changed, 230 insertions(+), 8 deletions(-) diff --git a/engine/src/available-moves.ts b/engine/src/available-moves.ts index 51cbd57..5d1917c 100644 --- a/engine/src/available-moves.ts +++ b/engine/src/available-moves.ts @@ -16,6 +16,51 @@ import { MoveName } from './move'; import prices from './prices'; import { minBy } from './utils'; +/** SwitzerlandCustom: garbage is cheese, and cheese kept in a plant that rests through Bureaucracy ages. */ +export function hasCheeseCellar(G: GameState): boolean { + return G.map.name === 'SwitzerlandCustom'; +} + +/** The player's aged cheese, never more than the cubes they hold. */ +export function agedCheese(player: Player): number { + return Math.min(player.agedCheese ?? 0, player.garbageLeft); +} + +/** + * The thriftiest way to burn `need` cheese from `fresh` fresh cubes and `aged` aged ones (each worth two): + * the least value wasted, then the fewest cubes. Undefined when there is not enough. + */ +export function cheeseMix(need: number, fresh: number, aged: number): { aged: number; fresh: number } | undefined { + let best: { aged: number; fresh: number; waste: number } | undefined; + for (let a = 0; a <= aged; a++) { + const f = Math.max(0, need - 2 * a); + if (f > fresh) continue; + const waste = 2 * a + f - need; + if (!best || waste < best.waste || (waste == best.waste && a + f < best.aged + best.fresh)) + best = { aged: a, fresh: f, waste }; + if (2 * a >= need) break; + } + return best && { aged: best.aged, fresh: best.fresh }; +} + +/** + * SwitzerlandCustom, when a player finishes Bureaucracy: fresh cheese in their cheese plants that rested (did not + * fire this round) ages. Aged cubes are counted in the plants that fired first, so a resting plant ripens only the + * room it has left. Returns how many cubes aged. + */ +export function ripenCheese(G: GameState, player: Player): number { + if (!hasCheeseCellar(G)) return 0; + const cheesePlants = player.powerPlants.filter((pp) => pp.type == PowerPlantType.Garbage); + const room = (pps: PowerPlant[]) => pps.reduce((t, pp) => t + 2 * pp.cost, 0); + const restedRoom = room(cheesePlants.filter((pp) => player.powerPlantsNotUsed.includes(pp.number))); + if (!restedRoom) return 0; + const aged = agedCheese(player); + const agedInRested = Math.max(0, aged - (room(cheesePlants) - restedRoom)); + const ripe = Math.min(player.garbageLeft - aged, restedRoom - agedInRested); + if (ripe > 0) player.agedCheese = aged + ripe; + return Math.max(0, ripe); +} + /** 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; @@ -71,6 +116,7 @@ export interface AvailableMoves { powerPlant: number; resourcesSpent: ResourceType[]; citiesPowered: number; + agedSpent?: number; }[]; [MoveName.ChooseRegion]?: string[]; [MoveName.ChooseColor]?: string[]; @@ -557,7 +603,12 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves { } case Phase.Bureaucracy: { - const toUse: { powerPlant: number; resourcesSpent: ResourceType[]; citiesPowered: number }[] = []; + const toUse: { + powerPlant: number; + resourcesSpent: ResourceType[]; + citiesPowered: number; + agedSpent?: number; + }[] = []; player.powerPlants.forEach((powerPlant) => { // Australia: uranium mines never power cities. They produce uranium @@ -593,6 +644,20 @@ export function availableMoves(G: GameState, player: Player): AvailableMoves { } case PowerPlantType.Garbage: { + if (hasCheeseCellar(G)) { + // SwitzerlandCustom: the engine picks the thriftiest mix of aged and fresh cheese. + const aged = agedCheese(player); + const mix = cheeseMix(powerPlant.cost, player.garbageLeft - aged, aged); + if (mix) { + toUse.push({ + powerPlant: powerPlant.number, + resourcesSpent: new Array(mix.aged + mix.fresh).fill(ResourceType.Garbage), + citiesPowered: powerPlant.citiesPowered, + ...(mix.aged ? { agedSpent: mix.aged } : {}), + }); + } + break; + } if (player.garbageLeft >= powerPlant.cost) { toUse.push({ powerPlant: powerPlant.number, diff --git a/engine/src/engine.ts b/engine/src/engine.ts index f775835..4046437 100644 --- a/engine/src/engine.ts +++ b/engine/src/engine.ts @@ -3,6 +3,7 @@ import { cloneDeep, isEqual, range } from 'lodash'; import seedrandom from 'seedrandom'; import { applyAnalysisMoney, isAnalysisMoneyCommand } from './analysis-money'; import { + agedCheese, alpineCitiesOwned, alpineEligible, availableMoves, @@ -11,9 +12,11 @@ import { computeRegionGraph, fuelOverCapacity, garbagePrice, + hasCheeseCellar, hasGarbageOilHybrid, maxStorable, regionPickable, + ripenCheese, } from './available-moves'; import { canReviseChoice, @@ -1358,6 +1361,16 @@ export function move( player.passed = true; const payment = powerIncome(G, player); + const ripe = ripenCheese(G, player); + if (ripe > 0) { + G.log.push({ + type: 'event', + event: `${player.name ?? `Player ${player.id}`}'s cheese ripens: ${ripe} cube${ + ripe > 1 ? 's' : '' + } aged (${agedCheese(player)} aged in all).`, + }); + } + player.money += payment; if (G.options.trackTotalSpent) { @@ -2037,6 +2050,8 @@ export function move( asserts(move); player.powerPlantsNotUsed = player.powerPlantsNotUsed.filter((x) => x != move.data.powerPlant); + // SwitzerlandCustom: count the aged cheese BEFORE the cubes leave (the count is capped by the cubes held). + const agedBefore = agedCheese(player); move.data.resourcesSpent.forEach((resourceType) => { switch (resourceType) { case ResourceType.Coal: @@ -2066,6 +2081,9 @@ export function move( } }); + // SwitzerlandCustom: aged cheese burned (already counted in the garbage cubes above). + if (agedBefore) player.agedCheese = Math.min(agedBefore - (move.data.agedSpent ?? 0), player.garbageLeft); + player.citiesPowered += move.data.citiesPowered; G.log.push({ @@ -2284,7 +2302,15 @@ export function moveAI(G: GameState, playerNumber: number): GameState { chosenMove = { name: MoveName.UsePowerPlant, // Sorted on a copy, for the same reason as Build above. - data: [...availableMoves.UsePowerPlant].sort((a, b) => a.citiesPowered - b.citiesPowered)[0], + data: [...availableMoves.UsePowerPlant].sort((a, b) => { + if (hasCheeseCellar(G)) { + // SwitzerlandCustom: burn aged cheese first; leave fresh cheese plants to rest and ripen. + const rank = (m: typeof a) => + m.agedSpent ? 0 : m.resourcesSpent.includes(ResourceType.Garbage) ? 2 : 1; + if (rank(a) != rank(b)) return rank(a) - rank(b); + } + return a.citiesPowered - b.citiesPowered; + })[0], }; } @@ -3234,9 +3260,11 @@ export function calculateMaxCitiesPowered(G: GameState, player: Player) { } const alpineOwned = alpineCitiesOwned(G, player); + // SwitzerlandCustom: each aged cheese cube burns as two. + const cheeseBonus = hasCheeseCellar(G) ? agedCheese(player) : 0; let max = 0; permutations.forEach((permutation) => { - if (isValid(player, permutation)) { + if (isValid(player, permutation, cheeseBonus)) { const citiesPowered = permutation.map((p) => p.citiesPowered).reduce((a, b) => a + b, 0) + // SwitzerlandCustom: +1 per ecological plant, capped by the Alpine cities owned. @@ -3248,7 +3276,7 @@ export function calculateMaxCitiesPowered(G: GameState, player: Player) { return Math.min(player.cities.length, max); } -function isValid(player: Player, powerPlants: PowerPlant[]) { +function isValid(player: Player, powerPlants: PowerPlant[], cheeseBonus = 0) { const coalUsed = powerPlants .filter((pp) => pp.type == PowerPlantType.Coal) .map((pp) => pp.cost) @@ -3273,7 +3301,7 @@ function isValid(player: Player, powerPlants: PowerPlant[]) { if ( coalUsed > player.coalLeft || oilUsed > player.oilLeft || - garbageUsed > player.garbageLeft || + garbageUsed > player.garbageLeft + cheeseBonus || uraniumUsed > player.uraniumLeft ) { return false; diff --git a/engine/src/gamestate.ts b/engine/src/gamestate.ts index ec676b4..824ab34 100644 --- a/engine/src/gamestate.ts +++ b/engine/src/gamestate.ts @@ -151,6 +151,9 @@ export interface Player { oilLeft: number; garbageCapacity: number; garbageLeft: number; + // SwitzerlandCustom (the cheese cellar): how many of garbageLeft are AGED cheese. An aged cube burns as two. + // Read it through agedCheese(player), which never exceeds garbageLeft (cubes lost to storage go aged-first). + agedCheese?: number; uraniumCapacity: number; uraniumLeft: number; hybridCapacity: number; diff --git a/engine/src/maps/switzerland.ts b/engine/src/maps/switzerland.ts index a2f03b0..5c559f0 100644 --- a/engine/src/maps/switzerland.ts +++ b/engine/src/maps/switzerland.ts @@ -229,6 +229,9 @@ export const map: GameMap = { '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. ' + + 'Garbage is cheese, and cheese ripens in the cellar: cheese kept in a garbage plant that does not fire in a ' + + 'Bureaucracy phase ages, and an aged cube burns as two. Aged cheese stays aged until burned and never ages ' + + 'again; it still takes one space of storage. The game burns the thriftiest mix for you. ' + '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/move.ts b/engine/src/move.ts index 3b79eb7..685f8c7 100644 --- a/engine/src/move.ts +++ b/engine/src/move.ts @@ -53,6 +53,8 @@ export declare namespace Moves { powerPlant: number; resourcesSpent: ResourceType[]; citiesPowered: number; + // SwitzerlandCustom: how many of the garbage cubes spent are aged cheese (each worth two). + agedSpent?: number; }; } diff --git a/engine/src/switzerland-custom.spec.ts b/engine/src/switzerland-custom.spec.ts index c34ceef..acd31b4 100644 --- a/engine/src/switzerland-custom.spec.ts +++ b/engine/src/switzerland-custom.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { alpineBonusLeft, availableMoves } from './available-moves'; -import { calculateMaxCitiesPowered, setup } from './engine'; +import { agedCheese, alpineBonusLeft, availableMoves, cheeseMix, ripenCheese } from './available-moves'; +import { calculateMaxCitiesPowered, move, moveAI, setup } from './engine'; import { GameState, Phase, Player, PowerPlant, PowerPlantType } from './gamestate'; import { map as switzerland } from './maps/switzerland'; import { MoveName } from './move'; @@ -153,3 +153,113 @@ describe('SwitzerlandCustom', () => { }); }); }); + +describe('SwitzerlandCustom cheese cellar', () => { + const cheese = (number: number, cost: number, citiesPowered: number): PowerPlant => ({ + number, + type: PowerPlantType.Garbage, + cost, + citiesPowered, + }); + const cityNames = (n: number) => + switzerland.cities + .filter((c) => !c.alpine) + .slice(0, n) + .map((c) => c.name); + + it('picks the thriftiest mix: least waste, then fewest cubes', () => { + expect(cheeseMix(3, 5, 0)).to.deep.equal({ aged: 0, fresh: 3 }); + expect(cheeseMix(3, 5, 2)).to.deep.equal({ aged: 1, fresh: 1 }); // plant 30: one aged + one fresh + expect(cheeseMix(2, 0, 1)).to.deep.equal({ aged: 1, fresh: 0 }); // plant 19 on one aged cube + expect(cheeseMix(3, 0, 2)).to.deep.equal({ aged: 2, fresh: 0 }); // overshoot is wasted, but it runs + expect(cheeseMix(3, 0, 1)).to.equal(undefined); + expect(cheeseMix(1, 1, 1)).to.deep.equal({ aged: 0, fresh: 1 }); // never burn an aged cube for one + }); + + it('ripens fresh cheese only in a plant that rested, and an aged cube burns as two', () => { + const { G, player } = bureaucracy([cheese(19, 2, 3)], cityNames(3)); + player.garbageLeft = 2; + // plant 19 rests this round: both cubes age + expect(ripenCheese(G, player)).to.equal(2); + expect(agedCheese(player)).to.equal(2); + // next round: one aged cube is a full run, twice over + player.powerPlantsNotUsed = [19]; + const move = offered(G, player).find((m) => m.powerPlant == 19) as any; + expect(move.agedSpent).to.equal(1); + expect(move.resourcesSpent.length).to.equal(1); + expect(calculateMaxCitiesPowered(G, player)).to.equal(3); + }); + + it('does not ripen cheese in a plant that fired, and aged cheese never ages again', () => { + const { G, player } = bureaucracy([cheese(19, 2, 3)], cityNames(3)); + player.garbageLeft = 4; + player.powerPlantsNotUsed = []; // 19 fired + expect(ripenCheese(G, player)).to.equal(0); + player.powerPlantsNotUsed = [19]; + player.agedCheese = 4; + expect(ripenCheese(G, player)).to.equal(0); + expect(agedCheese(player)).to.equal(4); + }); + + it('a resting plant ripens only the room it has left', () => { + // 19 (holds 4) fired, 24 (holds 4) rested; 6 cubes held, 4 already aged + const { G, player } = bureaucracy([cheese(19, 2, 3), cheese(24, 2, 4)], cityNames(5)); + player.garbageLeft = 6; + player.agedCheese = 4; + player.powerPlantsNotUsed = [24]; + // the 4 aged fill 19's room first, so 24 has all 4 of its room: the 2 fresh ripen + expect(ripenCheese(G, player)).to.equal(2); + expect(agedCheese(player)).to.equal(6); + }); + + it('spends aged cheese when the plant fires, through the real move', () => { + const G = setup(3, { map: 'SwitzerlandCustom', variant: 'original' }, 'cellar-move'); + // Play to the first Bureaucracy, then hand the current player a cheese plant with aged cheese. + let state = G; + for (let i = 0; i < 400 && state.phase != Phase.Bureaucracy; i++) + state = moveAI(state, state.currentPlayers[0]); + expect(state.phase).to.equal(Phase.Bureaucracy); + const p = state.players[state.currentPlayers[0]]; + p.powerPlants = [cheese(19, 2, 3)]; + p.powerPlantsNotUsed = [19]; + p.garbageLeft = 3; + p.agedCheese = 2; + p.cities = cityNames(3).map((name) => ({ name, position: 0 })); + p.availableMoves = availableMoves(state, p); + const use = (p.availableMoves[MoveName.UsePowerPlant] as any[]).find((m) => m.powerPlant == 19); + state = move(state, { name: MoveName.UsePowerPlant, data: use }, state.currentPlayers[0]); + const after = state.players[state.players.indexOf(state.players.find((x) => x.id == p.id)!)]; + expect(after.garbageLeft).to.equal(2); + expect(agedCheese(after)).to.equal(1); + }); + + it('keeps the other aged cube aged after burning one (John, 2026-11-19: plant 6, two aged, used one)', () => { + const G = setup(3, { map: 'SwitzerlandCustom', variant: 'original' }, 'cellar-six'); + let state = G; + for (let i = 0; i < 400 && state.phase != Phase.Bureaucracy; i++) + state = moveAI(state, state.currentPlayers[0]); + const p = state.players[state.currentPlayers[0]]; + p.powerPlants = [cheese(6, 1, 1)]; + p.powerPlantsNotUsed = [6]; + p.garbageLeft = 2; + p.agedCheese = 2; + p.cities = cityNames(1).map((name) => ({ name, position: 0 })); + p.availableMoves = availableMoves(state, p); + const use = (p.availableMoves[MoveName.UsePowerPlant] as any[]).find((m) => m.powerPlant == 6); + expect(use.agedSpent).to.equal(1); + state = move(state, { name: MoveName.UsePowerPlant, data: use }, state.currentPlayers[0]); + const after = state.players.find((x) => x.id == p.id)!; + expect(after.garbageLeft).to.equal(1); + expect(agedCheese(after)).to.equal(1); + }); + + it('leaves garbage alone on every other map', () => { + const { G, player } = bureaucracy([cheese(19, 2, 3)], ['Bern']); + G.map = setup(3, { map: 'Germany', variant: 'original' }, 'g').map; + player.garbageLeft = 2; + expect(ripenCheese(G, player)).to.equal(0); + const m = offered(G, player).find((x) => x.powerPlant == 19) as any; + expect(m.agedSpent).to.equal(undefined); + expect(m.resourcesSpent.length).to.equal(2); + }); +}); diff --git a/viewer/src/components/Game.vue b/viewer/src/components/Game.vue index cfaa04d..15efe23 100644 --- a/viewer/src/components/Game.vue +++ b/viewer/src/components/Game.vue @@ -2985,7 +2985,8 @@ export default class Game extends Vue { if ( coalUsed > player.coalLeft || oilUsed > player.oilLeft || - garbageUsed > player.garbageLeft || + // SwitzerlandCustom: an aged cheese cube burns as two. + garbageUsed > player.garbageLeft + Math.min(player.agedCheese ?? 0, player.garbageLeft) || uraniumUsed > player.uraniumLeft ) { return false; diff --git a/viewer/src/components/PlayerBoard.vue b/viewer/src/components/PlayerBoard.vue index ccc244b..b6fc274 100644 --- a/viewer/src/components/PlayerBoard.vue +++ b/viewer/src/components/PlayerBoard.vue @@ -224,6 +224,11 @@ @click="clickResource('garbage')" /> {{ player.garbageLeft }} + + + {{ agedCheese }} aged cheese: each burns as two + {{ agedCheese }} aged + {{ player.uraniumLeft }} @@ -405,6 +410,11 @@ export default class PlayerBoard extends Vue { } // The fuel a hybrid plant can burn besides oil: coal for the standard hybrid, + /** SwitzerlandCustom: aged cheese among the garbage held (never more than the cubes held). */ + get agedCheese(): number { + return Math.min(this.player.agedCheese ?? 0, this.player.garbageLeft); + } + // garbage for the alternate deck's garbage/oil hybrid. Undefined for other plants. hybridFuel(powerPlant: PowerPlant): ResourceType.Coal | ResourceType.Garbage | undefined { if (powerPlant.type == PowerPlantType.Hybrid) return ResourceType.Coal;