// Rôle : garde l'équilibre des Expéditions Sokko TCG avec le simulateur (seuils du document de conception). // En cas d'échec après un ajout de cartes ou un changement de réglages : lancer `node scripts/simulate-expeditions.mjs` pour le détail. import assert from "node:assert/strict"; import { test } from "node:test"; import { loadCardsCatalog } from "../services/cards/catalog.js"; import { loadExpeditionDestinations } from "../services/cards/expedition-content.js"; import { DEFAULT_EXPEDITION_SETTINGS, mergeExpeditionSettings } from "../services/cards/expedition-settings.js"; import { buildCommons, simulate, simulationCards, soloBuildShares } from "../services/cards/expedition-simulation.js"; const catalog = loadCardsCatalog("website/public/data/cards/catalog.json"); const destinations = loadExpeditionDestinations("services/cards/content/expedition-destinations.json", catalog); const settings = mergeExpeditionSettings(DEFAULT_EXPEDITION_SETTINGS, destinations.map((destination) => destination.id)); const report = simulate(catalog, destinations, settings); const row = (level, rarity, stars) => report.byRarity.find((item) => item.level === level && item.rarity === rarity && item.stars === stars); test("every rare or better card reaches Réussite at 2 stars somewhere at level 0", () => { const weak = report.cardBest.filter((card) => card.scorePct < settings.score.successPct); assert.deepEqual(weak.map((card) => `${card.cardId} (${card.rarity}) ${card.scorePct.toFixed(0)} %`), []); }); test("expected loot per hour is the same for every duration", () => { for (const { stars, tier, perHour } of report.lootPerHour) { assert.ok(perHour.every((value) => Math.abs(value - perHour[0]) < 1e-9), `${stars} ★ ${tier}`); } }); test("a rare and a mythic end within 5 % of each other at the cap", () => { const { rare, mythic } = report.rareVsMythicAtMax; assert.ok(Math.abs(rare - mythic) / mythic <= 0.05); }); test("rarer cards never score lower than commoner ones at the same level and stars", () => { const order = ["rare", "epic", "legendary", "mythic"]; for (let stars = 1; stars <= 5; stars += 1) { const medians = order.map((rarity) => row("niveau 0", rarity, stars).median); for (let index = 1; index < medians.length; index += 1) assert.ok(medians[index] >= medians[index - 1], `${order[index]} ${stars} ★`); } }); test("4 stars stay out of reach for level 0 rares", () => { assert.ok(row("niveau 0", "rare", 4).max < settings.score.successPct, "a level 0 rare reaches Réussite at 4 stars"); }); // Builds réfléchis : une carte sur deux, pour garder le test rapide (les raretés restent toutes représentées). const cards = simulationCards(catalog).filter((_, index) => index % 2 === 0); const commons = buildCommons(catalog); const share = (value) => `${(value * 100).toFixed(0)} %`; test("the highest difficulties need equipment, and a reflected build clears them at the cap", () => { const { bare, built } = soloBuildShares(cards, destinations, settings.power.cap, 5, commons, settings); assert.ok(bare <= 0.3, `without equipment, capped cards clear ${share(bare)} of 5 star situations alone`); assert.ok(built >= 0.8, `with a reflected build, capped cards clear only ${share(built)} of 5 star situations alone`); }); test("3 stars open to a reflected build before the second equipment slot", () => { const { built } = soloBuildShares(cards, destinations, 55, 3, commons, settings); assert.ok(built >= 0.5, `at Power 55, a reflected build clears only ${share(built)} of 3 star situations alone`); });