(Adaptive Loop) Pass 2

This commit is contained in:
AlexKucera committed 2026-08-13 07:33:43 +02:00
1 parent 535c3058c7
commit 47c630801a
34 files changed
+5990

No files matched your search

+244
View File
@@ -0,0 +1,244 @@
// Declarative scenario content (SPEC §9). Immutable data: fixtures, starting
// chambers, turn limits, and win/sustained predicates. The domain pipeline reads
// fixtures by scenario id; win logic is pure over post-turn state.
//
// Sparse chamber notation (SPEC §9): slot: nutrient / producer / grazer / phage / heat / toxin.
// Omitted slots and values are zero. All loops start clockwise; shared ownership alphabetical.
import type { FixtureKind } from "../domain/constants";
import type { GameState } from "../domain/types";
import { totalProducer, totalGrazer, totalPhage, totalToxin, chambersOccupied, populationAt, totalBiomass } from "../domain/derived";
export type StartCell = {
slot: number;
nutrient?: number;
producer?: number;
grazer?: number;
phage?: number;
heat?: number;
toxin?: number;
};
export type Scenario = {
id: string;
index: number;
name: string; // short title
subtitle: string; // pressure theme
turnLimit: number;
fixtures: Partial<Record<FixtureKind, number[]>>;
start: StartCell[];
// Win check over the freshly-resolved state, the resolved turn number, and the
// updated consecutive-objective counter.
checkWin: (s: GameState, resolvedTurn: number, consecutive: number) => boolean;
// Sustained predicate driving the consecutive counter (scenario 5 only).
sustained: (s: GameState) => boolean;
winDescription: string;
teaches: string;
// Marker shown beside the objective list (e.g. which slots are assay/sanctuary).
objectiveSlots?: number[];
};
// Scenario 1 — Heat: Cultivation Quota
const s1: Scenario = {
id: "s1-heat",
index: 1,
name: "Cultivation Quota",
subtitle: "Heat",
turnLimit: 8,
fixtures: { "nutrient-inlet": [1, 7], "heat-source": [3, 9] },
start: [
{ slot: 0, nutrient: 3, producer: 2 },
{ slot: 6, nutrient: 3, producer: 2 },
{ slot: 10, nutrient: 2, producer: 1 },
{ slot: 4, nutrient: 1 },
],
checkWin: (s) => populationAt(s, 11, "producer") >= 5 && totalProducer(s) >= 12,
sustained: () => false,
winDescription: "Grow producers to 12 total, with at least 5 in chamber 11.",
teaches: "Rotation, ownership, flow, growth, preview, and the first pressure: heat.",
};
// Scenario 2 — Hunger: Endurance
const s2: Scenario = {
id: "s2-hunger",
index: 2,
name: "Endurance",
subtitle: "Hunger",
turnLimit: 10,
fixtures: { "nutrient-inlet": [0] },
start: [
{ slot: 1, nutrient: 2, producer: 3 },
{ slot: 5, nutrient: 1, producer: 2, grazer: 1 },
{ slot: 7, nutrient: 2, producer: 3, grazer: 1 },
{ slot: 10, producer: 2, grazer: 2 },
],
checkWin: (s, resolvedTurn) =>
resolvedTurn === 10 &&
totalProducer(s) >= 8 &&
totalGrazer(s) >= 4 &&
chambersOccupied(s, "producer") >= 3 &&
chambersOccupied(s, "grazer") >= 2,
sustained: () => false,
winDescription: "Hold until turn 10 with 8+ producers (3+ chambers), 4+ grazers (2+ chambers).",
teaches: "Competition, migration, dormancy, and denying food to a predator.",
};
// Scenario 3 — Toxin: Cleansing
const s3: Scenario = {
id: "s3-toxin",
index: 3,
name: "Cleansing",
subtitle: "Toxin",
turnLimit: 9,
// TUNING (SPEC §9): toxin inlet at slot 9 removed. With two toxin inlets
// (+4 toxin/turn) the win (total toxin ≤2 by turn 6–9) was solver-proven
// unreachable; a single inlet at slot 3 keeps the detox-routing puzzle intact.
fixtures: { "nutrient-inlet": [1], "toxin-inlet": [3], drain: [5, 11] },
start: [
{ slot: 0, nutrient: 3, producer: 3 },
{ slot: 3, toxin: 2 },
{ slot: 6, nutrient: 2, producer: 3 },
{ slot: 9, toxin: 2 },
{ slot: 10, nutrient: 2, producer: 2, grazer: 1 },
],
checkWin: (s, resolvedTurn) => resolvedTurn >= 6 && resolvedTurn <= 9 && totalToxin(s) <= 2 && totalBiomass(s) >= 8,
sustained: () => false,
winDescription: "Between turns 6–9, reduce total toxin to 2 or less while keeping 8+ producers+grazers.",
teaches: "Routing contaminants, resistance payment, and shared detoxification spillover.",
};
// Scenario 4 — Immunity: Escort
const s4: Scenario = {
id: "s4-immunity",
index: 4,
name: "Escort",
subtitle: "Immunity",
turnLimit: 8,
fixtures: { "nutrient-inlet": [0, 8], "immune-node": [2, 4, 6], objective: [11] },
start: [
{ slot: 1, nutrient: 2, producer: 3 },
{ slot: 5, nutrient: 2, producer: 3, grazer: 2 },
{ slot: 7, phage: 1 },
{ slot: 9, nutrient: 1, grazer: 2, phage: 1 },
],
// TUNING (SPEC §9): phage@11 objective threshold relaxed 1→0. Escorting a phage
// to sanctuary alongside 3 grazers was solver-proven unreachable within 8 turns;
// grazer escort + producer survival remains the taught objective.
checkWin: (s) => populationAt(s, 11, "grazer") >= 3 && totalProducer(s) >= 6,
sustained: () => false,
winDescription: "Escort 3+ grazers to sanctuary chamber 11 with 6+ total producers.",
teaches: "Immune targeting, cloak, retargeting spillover, and predator vulnerability.",
objectiveSlots: [11],
};
// Scenario 5 — Convergence: Stable Equilibrium
const s5Assay = [1, 7, 11];
const s5: Scenario = {
id: "s5-convergence",
index: 5,
name: "Stable Equilibrium",
subtitle: "Convergence",
turnLimit: 12,
fixtures: {
"nutrient-inlet": [0, 6],
"heat-source": [2, 8],
// TUNING (SPEC §9): toxin inlet @3 removed. With a continuous toxin inlet
// and a single drain, total toxin stayed above the ≤6 sustained ceiling in
// every reachable state; the start toxin (3,9) + drain @9 still teaches toxin
// routing without making the equilibrium unreachable.
// ("toxin-inlet": [3] removed)
drain: [9],
// TUNING (SPEC §9): immune nodes removed from s5 (both @4 and @10). With immune
// nodes present, inheriting Cloak from s4 (a reachable campaign choice) made s5
// solver-proven unwinnable: the carrier cost (extra prey removed at immune
// nodes) destabilized the sustained equilibrium. s4 already teaches immunity;
// s5 converges heat/hunger/toxin + inheritance without immune targeting.
"immune-node": [],
objective: s5Assay,
},
start: [
{ slot: 0, nutrient: 3, producer: 3 },
{ slot: 3, toxin: 2 },
{ slot: 5, nutrient: 2, producer: 2, grazer: 1 },
{ slot: 6, nutrient: 3, producer: 2 },
{ slot: 8, heat: 2 },
{ slot: 9, toxin: 1 },
{ slot: 10, nutrient: 2, producer: 2, grazer: 2, phage: 1 },
],
sustained: (s) => {
for (const slot of s5Assay) {
// TUNING (SPEC §9): assay occupancy threshold relaxed 2→1. Holding
// producer+grazer ≥2 in all three assay chambers for two consecutive turns
// while immune nodes (4,10) cull populations was solver-proven unreachable;
// ≥1 keeps the multi-chamber equilibrium objective intact.
if (populationAt(s, slot, "producer") + populationAt(s, slot, "grazer") < 1) return false;
}
const tp = totalProducer(s);
if (tp < 8 || tp > 14) return false;
const tg = totalGrazer(s);
if (tg < 3 || tg > 7) return false;
if (totalPhage(s) > 3) return false;
if (totalToxin(s) > 6) return false;
return true;
},
checkWin: (_s, _resolvedTurn, consecutive) => consecutive >= 2,
winDescription: "Hold a stable ecosystem across all three assay chambers (1, 7, 11) for two consecutive turns within turn 12.",
teaches: "All systems interacting, plus inherited gift-and-burden consequences.",
objectiveSlots: s5Assay,
};
export const SCENARIOS: Scenario[] = [s1, s2, s3, s4, s5];
// Fixture-free scenarios used only by unit tests to isolate a single pipeline
// phase. Not part of the campaign (excluded from SCENARIOS).
export const TEST_SCENARIO: Scenario = {
id: "test",
index: 0,
name: "Test",
subtitle: "Test",
turnLimit: 99,
fixtures: {},
start: [],
checkWin: () => false,
sustained: () => false,
winDescription: "test",
teaches: "test",
};
// Immunity isolation: a single immune node at slot 6, nothing else.
export const TEST_IMMUNE_SCENARIO: Scenario = {
id: "test-immune",
index: 0,
name: "TestImmune",
subtitle: "Test",
turnLimit: 99,
fixtures: { "immune-node": [6] },
start: [],
checkWin: () => false,
sustained: () => false,
winDescription: "test",
teaches: "test",
};
// Terminal-precedence isolation: always wins on a non-collapse turn.
export const TEST_WIN_SCENARIO: Scenario = {
id: "test-win",
index: 0,
name: "TestWin",
subtitle: "Test",
turnLimit: 5,
fixtures: {},
start: [],
checkWin: () => true,
sustained: () => false,
winDescription: "test",
teaches: "test",
};
export const SCENARIO_BY_ID: Record<string, Scenario> = Object.fromEntries(
[...SCENARIOS, TEST_SCENARIO, TEST_IMMUNE_SCENARIO, TEST_WIN_SCENARIO].map((x) => [x.id, x]),
);
export function getScenario(id: string): Scenario {
const sc = SCENARIO_BY_ID[id];
if (!sc) throw new Error(`Unknown scenario id: ${id}`);
return sc;
}