Almaatla commited on
Commit
56d13d7
·
unverified ·
2 Parent(s): 65c0a374979046

Merge pull request #91: an in-app AI editor

Browse files

The genome was always meant to be something a player owns, not only something a
search breeds, and until now owning one meant editing JSON by hand.

The whole form generates itself from GENOME_SCHEMA, so the screen cannot drift
out of step with what the engine reads -- add a gene there and it appears here
with the right control and the right limits -- and an illegal AI cannot be built
through this UI at all, because the bounds ARE the schema's.

The feature that justifies a real screen over a text box is that dials nothing is
currently reading go grey and say why. Tick "never initiates" and the whole
Attacking group dims, because under that flag the engine never commits a wave.
Junk DNA is useful to a search and hostile to a person: someone tuning a muster
size for ten minutes under a switch that makes it meaningless gets no feedback at
all. Inert rows are dimmed rather than hidden or disabled -- the value is still
real and still saved, so hiding it would lose their work and disabling it would
imply it is broken.

inertGenes() is pure and schema-driven in tools/genome.js, so the greying derives
from the same source the engine reads rather than a hand-maintained copy.

Save to roster makes an AI duellable immediately; Download writes the same
candidate format the bench and Import AI already use, so a hand-built AI, a
bench-bred one and a player mirror are one artifact.

Suite 2490 -> 2494.

Files changed (4) hide show
  1. competition.js +256 -1
  2. style.css +20 -0
  3. test/genome.test.js +58 -1
  4. tools/genome.js +45 -0
competition.js CHANGED
@@ -83,7 +83,8 @@ import {
83
  } from "./competitionLedger.js";
84
  // The genome whitelist (GENOME_SCHEMA) — the same validator addRosterEntry applies, run here
85
  // too so a bad file is reported to the player rather than silently becoming an empty AI.
86
- import { sanitizeGenome } from "./tools/genome.js";
 
87
 
88
  /* ============================================================
89
  PURE — job construction, seed derivation, table/Elo shaping, roster/standings shaping. No DOM,
@@ -1284,6 +1285,7 @@ const COMP_TABS = [
1284
  { key: "duel", label: "🏆 Quick Duel" },
1285
  { key: "tournament", label: "🏟 Tournament" },
1286
  { key: "roster", label: "📋 Roster" },
 
1287
  { key: "standings", label: "📈 Standings" },
1288
  { key: "gauntlet", label: "🎯 Gauntlet" },
1289
  ];
@@ -1331,6 +1333,7 @@ function refreshCompView() {
1331
  renderCompTabs(wrapEl);
1332
 
1333
  if (compScreen === "roster") renderRosterScreen(wrapEl);
 
1334
  else if (compScreen === "standings") renderStandingsScreen(wrapEl);
1335
  else if (compScreen === "tournament") renderTournamentScreen(wrapEl);
1336
  else if (compScreen === "gauntlet") renderGauntletScreen(wrapEl);
@@ -2507,6 +2510,258 @@ function renderAddRosterEntryForm(container) {
2507
  container.appendChild(card);
2508
  }
2509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2510
  function renderRosterScreen(container) {
2511
  const activeLedger = ensureLedger();
2512
 
 
83
  } from "./competitionLedger.js";
84
  // The genome whitelist (GENOME_SCHEMA) — the same validator addRosterEntry applies, run here
85
  // too so a bad file is reported to the player rather than silently becoming an empty AI.
86
+ import { sanitizeGenome, GENOME_SCHEMA, MIX_ALPHABET, geneKeys, genomeFrom, inertGenes, toCandidate }
87
+ from "./tools/genome.js";
88
 
89
  /* ============================================================
90
  PURE — job construction, seed derivation, table/Elo shaping, roster/standings shaping. No DOM,
 
1285
  { key: "duel", label: "🏆 Quick Duel" },
1286
  { key: "tournament", label: "🏟 Tournament" },
1287
  { key: "roster", label: "📋 Roster" },
1288
+ { key: "editor", label: "🧬 AI Editor" },
1289
  { key: "standings", label: "📈 Standings" },
1290
  { key: "gauntlet", label: "🎯 Gauntlet" },
1291
  ];
 
1333
  renderCompTabs(wrapEl);
1334
 
1335
  if (compScreen === "roster") renderRosterScreen(wrapEl);
1336
+ else if (compScreen === "editor") renderAiEditorScreen(wrapEl);
1337
  else if (compScreen === "standings") renderStandingsScreen(wrapEl);
1338
  else if (compScreen === "tournament") renderTournamentScreen(wrapEl);
1339
  else if (compScreen === "gauntlet") renderGauntletScreen(wrapEl);
 
2510
  container.appendChild(card);
2511
  }
2512
 
2513
+ /* ============================================================
2514
+ THE AI EDITOR — build an opponent by hand (docs/ai-evolution-design.md)
2515
+
2516
+ The genome was always meant to be a thing a PLAYER owns, not only something a search breeds.
2517
+ Until now owning one meant editing JSON by hand, which is a fine format for a bench and a poor
2518
+ one for a person.
2519
+
2520
+ THE WHOLE FORM IS GENERATED FROM GENOME_SCHEMA. Every control's kind, bounds, grouping and label
2521
+ come from the schema row, so this screen cannot drift out of step with what the engine actually
2522
+ reads: add a gene there and it appears here, with the right widget and the right limits, and it
2523
+ is impossible to build an illegal AI through this UI because the bounds ARE the schema's.
2524
+
2525
+ IT SHOWS WHAT IS INERT, which is the feature that justifies a real screen over a text box. The
2526
+ genome is full of epistatic switches — under "never initiates" every offense dial is read by
2527
+ nothing, matchBuffer/matchFloor are dead unless force-matching is on, the whole diplomacy group
2528
+ is dead outside Odyssey. Junk DNA is useful to a search and hostile to a person: someone tuning
2529
+ a muster size for ten minutes under a flag that makes it meaningless gets no feedback at all.
2530
+ inertGenes() (tools/genome.js) names them and the rows grey out live as you toggle.
2531
+ ============================================================ */
2532
+
2533
+ // The genome currently on the bench. Null until the screen is first opened, then kept across tab
2534
+ // switches so a half-built AI survives a trip to the Roster and back.
2535
+ let editorGenome = null;
2536
+ let editorName = "";
2537
+ let editorError = "";
2538
+ let editorSaved = "";
2539
+
2540
+ const EDITOR_GENES = () => geneKeys({ layers: ["strategy", "archetype"], odyssey: true });
2541
+
2542
+ // Module -> the plain-English heading a player reads, since "linkage group" is a search concept.
2543
+ const MODULE_LABELS = {
2544
+ offense: "Attacking", economy: "Economy", defense: "Defence", diplomacy: "Diplomacy (Odyssey)",
2545
+ adaptation: "Reading the opponent", macro: "Expansion & build-out", tempo: "Attack timing",
2546
+ composition: "What it builds",
2547
+ };
2548
+
2549
+ // One-line explanations, keyed by gene. Written for someone who has played the game, not for
2550
+ // someone who has read the engine.
2551
+ const GENE_HELP = {
2552
+ attackTimeoutMult: "Lower = commits to an attack sooner.",
2553
+ armyAttackSizeMult: "Lower = attacks with a smaller force.",
2554
+ garrisonMult: "Higher = keeps more units home when it attacks.",
2555
+ neverInitiates: "Never starts a fight. Still defends, and still answers a provocation in Odyssey.",
2556
+ useBombOffensively: "Walks a built Helium Bomb to the target instead of keeping it as a home trap.",
2557
+ workerTargetMult: "Higher = a bigger worker economy.",
2558
+ capsArmy: "Hold the standing army at a fixed size and spend the rest on economy.",
2559
+ standingArmyCap: "How many combat units it keeps while capped.",
2560
+ warFootingMult: "How far the cap lifts once it is attacked.",
2561
+ warFootingTime: "How long that surge lasts, in seconds.",
2562
+ wantsIndustryAlways: "Climbs the deep factory chain even when its temperament wouldn't.",
2563
+ turretCountMult: "Higher = more static defence.",
2564
+ matchEnemyForce: "Size its army to mirror whatever it has seen of yours.",
2565
+ matchBuffer: "How far above parity it aims.",
2566
+ matchFloor: "The smallest home guard it keeps regardless.",
2567
+ graceMult: "How long the opening peace lasts.",
2568
+ grievanceMult: "How fast it sours when you hurt it.",
2569
+ forgiveness: "How fast it cools off again.",
2570
+ punishPosture: "How economy-heavy you must look before it raids you.",
2571
+ punishConfidence: "How much of you it must have scouted before acting on that.",
2572
+ adaptRateMult: "How fast its stance shifts as it learns about you.",
2573
+ adaptBandMult: "How big a change it takes to shift at all. Higher = more stubborn.",
2574
+ defenceSwingMult: "How far its stance swings turret spending.",
2575
+ workerTarget: "Base worker count before multipliers.",
2576
+ expandWhenNodesBelow: "Expands once home ore drops below this fraction. 0 = never expands.",
2577
+ maxBarracks: "How many production buildings it will run.",
2578
+ wantsRefinery: "Builds a Refinery and researches its doctrine.",
2579
+ armyAttackSize: "Base wave size before multipliers.",
2580
+ attackTimeout: "Base seconds before it commits anyway.",
2581
+ garrison: "Base home guard before multipliers.",
2582
+ turretCount: "Base turret count before multipliers.",
2583
+ unitMix: "Its repeating production cycle. Order matters — the first entry is built first.",
2584
+ doctrine: "Which upgrade path it researches.",
2585
+ faction: "Its faction bonuses.",
2586
+ };
2587
+
2588
+ function renderAiEditorScreen(container) {
2589
+ const genes = EDITOR_GENES();
2590
+ if (!editorGenome) editorGenome = genomeFrom({ strategy: "default", archetype: "balanced", genes });
2591
+
2592
+ container.appendChild(mk("p", "setup-hint comp-intro",
2593
+ "Build an opponent dial by dial. Every control here comes from the AI's own schema, so anything "
2594
+ + "you can set is something the engine really reads and within limits it really accepts — you "
2595
+ + "cannot build a broken AI from this screen. Greyed rows are dials that nothing is currently "
2596
+ + "reading, and each says why."));
2597
+
2598
+ // START FROM — the shipped strategies and archetypes are far better starting points than a blank
2599
+ // form, and "modify a Rusher" is a much more approachable task than "invent an AI".
2600
+ const seedRow = mk("div", "comp-io-row");
2601
+ seedRow.appendChild(mk("span", "setup-hint", "Start from: "));
2602
+ for (const key of Object.keys(STRATEGIES)) {
2603
+ const b = mk("button", "btn", STRATEGIES[key].name || key);
2604
+ b.type = "button";
2605
+ b.addEventListener("click", () => {
2606
+ editorGenome = genomeFrom({ strategy: key, archetype: "balanced", genes });
2607
+ editorSaved = ""; editorError = ""; refreshCompView();
2608
+ });
2609
+ seedRow.appendChild(b);
2610
+ }
2611
+ container.appendChild(seedRow);
2612
+
2613
+ const inert = inertGenes(editorGenome, { genes, odyssey: false });
2614
+
2615
+ // One block per linkage group, in schema order.
2616
+ const modules = [...new Set(genes.map(g => g.module))];
2617
+ for (const mod of modules) {
2618
+ const rows = genes.filter(g => g.module === mod);
2619
+ if (!rows.length) continue;
2620
+ container.appendChild(mk("h4", "comp-entrant-heading", MODULE_LABELS[mod] || mod));
2621
+ const card = mk("div", "comp-entrant");
2622
+ for (const g of rows) card.appendChild(renderGeneRow(g, inert[g.key]));
2623
+ container.appendChild(card);
2624
+ }
2625
+
2626
+ // SAVE — straight onto the roster, where it is duellable immediately.
2627
+ container.appendChild(mk("h4", "comp-entrant-heading", "Save to roster"));
2628
+ const saveCard = mk("div", "comp-entrant");
2629
+ const nameInput = document.createElement("input");
2630
+ nameInput.type = "text";
2631
+ nameInput.className = "comp-name-input";
2632
+ nameInput.placeholder = "Name this AI";
2633
+ nameInput.maxLength = 40;
2634
+ nameInput.value = editorName;
2635
+ nameInput.addEventListener("input", () => { editorName = nameInput.value; });
2636
+ saveCard.appendChild(nameInput);
2637
+
2638
+ const saveBtn = mk("button", "btn", "Save to roster");
2639
+ saveBtn.type = "button";
2640
+ saveBtn.addEventListener("click", () => {
2641
+ try {
2642
+ const name = (editorName || "").trim();
2643
+ if (!name) throw new Error("give it a name first");
2644
+ // sanitizeGenome again on the way out, even though every control is schema-bounded: the save
2645
+ // path is the one that reaches the live AI tables, and it should not depend on the UI having
2646
+ // been the only writer.
2647
+ addRosterEntry(ensureLedger(), { name, genome: sanitizeGenome(editorGenome), createdAt: Date.now() });
2648
+ saveLedgerToStorage(ensureLedger());
2649
+ editorSaved = `Saved “${name}” — pick it as an entrant in Quick Duel.`;
2650
+ editorError = "";
2651
+ } catch (err) {
2652
+ editorError = err.message;
2653
+ editorSaved = "";
2654
+ }
2655
+ refreshCompView();
2656
+ });
2657
+ saveCard.appendChild(saveBtn);
2658
+
2659
+ const dlBtn = mk("button", "btn", "⭳ Download");
2660
+ dlBtn.type = "button";
2661
+ dlBtn.title = "Save as a candidate file — the same format the bench and Import AI use.";
2662
+ dlBtn.addEventListener("click", () => {
2663
+ const name = (editorName || "Custom AI").trim();
2664
+ const blob = new Blob([JSON.stringify(toCandidate(editorGenome, name, { genes }), null, 2)],
2665
+ { type: "application/json" });
2666
+ const url = URL.createObjectURL(blob);
2667
+ const a = document.createElement("a");
2668
+ a.href = url;
2669
+ a.download = `${name.replace(/[^a-z0-9]+/gi, "-").toLowerCase()}.json`;
2670
+ a.click();
2671
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
2672
+ });
2673
+ saveCard.appendChild(dlBtn);
2674
+ container.appendChild(saveCard);
2675
+
2676
+ if (editorError) container.appendChild(mk("p", "comp-error", editorError));
2677
+ if (editorSaved) container.appendChild(mk("p", "setup-hint", editorSaved));
2678
+ }
2679
+
2680
+ // One control, chosen by the gene's KIND. Bounds come from the schema row, never from here.
2681
+ function renderGeneRow(g, inertWhy) {
2682
+ const row = mk("div", "comp-gene-row" + (inertWhy ? " comp-gene-inert" : ""));
2683
+ const label = mk("label", "comp-gene-label", g.key);
2684
+ row.appendChild(label);
2685
+ const bag = editorGenome[g.layer];
2686
+
2687
+ if (g.kind === "flag") {
2688
+ const cb = document.createElement("input");
2689
+ cb.type = "checkbox";
2690
+ cb.checked = bag[g.key] === true;
2691
+ // A flag can turn other rows inert, so the whole screen re-renders rather than just this row.
2692
+ cb.addEventListener("change", () => { bag[g.key] = cb.checked; refreshCompView(); });
2693
+ row.appendChild(cb);
2694
+ } else if (g.kind === "choice") {
2695
+ const sel = document.createElement("select");
2696
+ for (const opt of g.of) {
2697
+ const o = document.createElement("option");
2698
+ o.value = o.textContent = opt;
2699
+ if (bag[g.key] === opt) o.selected = true;
2700
+ sel.appendChild(o);
2701
+ }
2702
+ sel.addEventListener("change", () => { bag[g.key] = sel.value; });
2703
+ row.appendChild(sel);
2704
+ } else if (g.kind === "mix") {
2705
+ row.appendChild(renderMixEditor(g, bag));
2706
+ } else {
2707
+ const isCount = g.kind === "count";
2708
+ const slider = document.createElement("input");
2709
+ slider.type = "range";
2710
+ slider.min = String(g.min);
2711
+ slider.max = String(g.max);
2712
+ slider.step = isCount ? "1" : String(Math.max(0.001, +((g.max - g.min) / 200).toFixed(3)));
2713
+ slider.value = String(bag[g.key]);
2714
+ const out = mk("span", "comp-gene-value", String(bag[g.key]));
2715
+ slider.addEventListener("input", () => {
2716
+ const v = isCount ? Math.round(Number(slider.value)) : +Number(slider.value).toFixed(3);
2717
+ bag[g.key] = v;
2718
+ out.textContent = String(v);
2719
+ });
2720
+ row.appendChild(slider);
2721
+ row.appendChild(out);
2722
+ }
2723
+
2724
+ // The reason it is inert outranks the ordinary help text: it is the more actionable fact.
2725
+ row.appendChild(mk("span", "setup-hint comp-gene-help", inertWhy || GENE_HELP[g.key] || ""));
2726
+ return row;
2727
+ }
2728
+
2729
+ // The production cycle: an ordered list, because order decides what gets built first. Kept simple —
2730
+ // add a type, remove a slot — rather than drag-and-drop, which is a lot of code for a nine-slot list.
2731
+ function renderMixEditor(g, bag) {
2732
+ const wrap = mk("div", "comp-mix");
2733
+ const mix = Array.isArray(bag[g.key]) ? bag[g.key] : [];
2734
+ mix.forEach((type, i) => {
2735
+ const chip = mk("button", "btn comp-mix-chip", `${i + 1}. ${type} ✕`);
2736
+ chip.type = "button";
2737
+ chip.title = "Remove this slot";
2738
+ chip.addEventListener("click", () => {
2739
+ // Two entries is the shortest thing that is still a cycle (tools/genome.js MIX_MIN_LEN).
2740
+ if (mix.length <= 2) { editorError = "a production cycle needs at least two entries"; }
2741
+ else { mix.splice(i, 1); editorError = ""; }
2742
+ refreshCompView();
2743
+ });
2744
+ wrap.appendChild(chip);
2745
+ });
2746
+ const add = document.createElement("select");
2747
+ const blank = document.createElement("option");
2748
+ blank.value = ""; blank.textContent = "+ add…";
2749
+ add.appendChild(blank);
2750
+ for (const t of MIX_ALPHABET) {
2751
+ const o = document.createElement("option");
2752
+ o.value = o.textContent = t;
2753
+ add.appendChild(o);
2754
+ }
2755
+ add.addEventListener("change", () => {
2756
+ if (!add.value) return;
2757
+ if (mix.length >= 10) { editorError = "a production cycle is capped at ten entries"; }
2758
+ else { mix.push(add.value); editorError = ""; }
2759
+ refreshCompView();
2760
+ });
2761
+ wrap.appendChild(add);
2762
+ return wrap;
2763
+ }
2764
+
2765
  function renderRosterScreen(container) {
2766
  const activeLedger = ensureLedger();
2767
 
style.css CHANGED
@@ -1710,3 +1710,23 @@ body.panel-collapsed #selectionPanel { display: none; }
1710
  .scenario-btn.disabled { opacity: 0.5; cursor: not-allowed; }
1711
  .scenario-btn.disabled:hover { border-color: var(--border); color: var(--text); }
1712
  .scenario-btn.hidden { display: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1710
  .scenario-btn.disabled { opacity: 0.5; cursor: not-allowed; }
1711
  .scenario-btn.disabled:hover { border-color: var(--border); color: var(--text); }
1712
  .scenario-btn.hidden { display: none; }
1713
+
1714
+ /* --- AI Editor (competition.js renderAiEditorScreen) — a schema-generated form, so the layout has
1715
+ to work for any gene the schema grows, not just today's list. --- */
1716
+ .comp-gene-row {
1717
+ display: grid;
1718
+ grid-template-columns: 190px 1fr 52px;
1719
+ align-items: center;
1720
+ gap: 10px;
1721
+ padding: 4px 0;
1722
+ }
1723
+ .comp-gene-row > .comp-gene-help { grid-column: 1 / -1; margin: 0 0 4px 190px; font-size: 11px; }
1724
+ .comp-gene-label { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
1725
+ .comp-gene-value { font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }
1726
+ /* INERT: a dial nothing is currently reading. Dimmed rather than hidden or disabled — the value is
1727
+ still real and still saved (it matters again the moment its switch flips back), so hiding it
1728
+ would lose work and disabling it would suggest it is broken. */
1729
+ .comp-gene-inert { opacity: 0.45; }
1730
+ .comp-gene-inert .comp-gene-help { font-style: italic; }
1731
+ .comp-mix { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
1732
+ .comp-mix-chip { width: auto; padding: 2px 8px; font-size: 11px; }
test/genome.test.js CHANGED
@@ -25,7 +25,7 @@ import { readFileSync, readdirSync } from "node:fs";
25
  import assert from "node:assert/strict";
26
  import {
27
  GENOME_SCHEMA, MODULES, MIX_ALPHABET, geneKeys, genomeFrom, randomGenome, mutate, mutateMix,
28
- cross, crossMix, cloneGenome, emptyGenome, toOverrides, toCandidate, diffGenes, rngFor, sanitizeGenome,
29
  } from "../tools/genome.js";
30
  import { STRATEGIES } from "../engine/aiStrategy.js";
31
  import { ARCHETYPES } from "../engine/aiArchetypes.js";
@@ -416,3 +416,60 @@ test("garbage that is not an object at all returns null rather than throwing", (
416
  for (const bad of [null, undefined, 42, "genome", [], true])
417
  assert.equal(sanitizeGenome(bad), null, `${String(bad)} must return null`);
418
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  import assert from "node:assert/strict";
26
  import {
27
  GENOME_SCHEMA, MODULES, MIX_ALPHABET, geneKeys, genomeFrom, randomGenome, mutate, mutateMix,
28
+ cross, crossMix, cloneGenome, emptyGenome, toOverrides, toCandidate, diffGenes, rngFor, sanitizeGenome, inertGenes,
29
  } from "../tools/genome.js";
30
  import { STRATEGIES } from "../engine/aiStrategy.js";
31
  import { ARCHETYPES } from "../engine/aiArchetypes.js";
 
416
  for (const bad of [null, undefined, 42, "genome", [], true])
417
  assert.equal(sanitizeGenome(bad), null, `${String(bad)} must return null`);
418
  });
419
+
420
+ /* ---------- inertGenes: the epistasis, made visible ----------
421
+
422
+ Junk DNA is useful to a SEARCH (an inert gene drifts, giving a lineage somewhere new to land when
423
+ its switch flips back) and actively hostile to a PERSON tuning a dial that nothing reads. The
424
+ editor greys those rows out, so this has to agree with the rules the engine actually applies.
425
+ ---------- */
426
+
427
+ test("neverInitiates makes every offence dial inert, and says so", () => {
428
+ const genes = geneKeys({ layers: ["strategy", "archetype"], odyssey: true });
429
+ const g = genomeFrom({ genes });
430
+ g.strategy.neverInitiates = true;
431
+ const inert = inertGenes(g, { genes });
432
+ for (const k of ["attackTimeoutMult", "armyAttackSizeMult", "garrisonMult", "armyAttackSize", "garrison"])
433
+ assert.ok(inert[k], `${k} is read by nothing under neverInitiates and must be marked`);
434
+ assert.match(inert.attackTimeoutMult, /never initiates/i, "the reason must name the switch responsible");
435
+ // …and turning it off brings them back.
436
+ g.strategy.neverInitiates = false;
437
+ const live = inertGenes(g, { genes });
438
+ assert.ok(!live.attackTimeoutMult, "with the switch off the offence dials must be live again");
439
+ });
440
+
441
+ test("the force-parity and army-cap switches gate their own dials", () => {
442
+ const genes = geneKeys({ layers: ["strategy", "archetype"], odyssey: true });
443
+ const g = genomeFrom({ genes });
444
+ g.strategy.matchEnemyForce = false;
445
+ g.strategy.capsArmy = false;
446
+ const inert = inertGenes(g, { genes });
447
+ assert.ok(inert.matchBuffer && inert.matchFloor, "parity dials are dead without the switch");
448
+ assert.ok(inert.standingArmyCap, "the cap value is dead without the cap switch");
449
+ // warFooting only ever lifts a standingArmyCap, so with no cap there is nothing for it to lift.
450
+ assert.ok(inert.warFootingMult && inert.warFootingTime,
451
+ "the war-footing surge is dead when there is no cap to surge from");
452
+ g.strategy.matchEnemyForce = true;
453
+ g.strategy.capsArmy = true;
454
+ const live = inertGenes(g, { genes });
455
+ assert.ok(!live.matchBuffer && !live.standingArmyCap && !live.warFootingMult);
456
+ });
457
+
458
+ test("Odyssey-only genes are inert in a skirmish and live in an Odyssey", () => {
459
+ const genes = geneKeys({ layers: ["strategy", "archetype"], odyssey: true });
460
+ const g = genomeFrom({ genes });
461
+ const skirmish = inertGenes(g, { genes, odyssey: false });
462
+ for (const k of ["graceMult", "grievanceMult", "forgiveness", "wantsIndustryAlways", "useBombOffensively"])
463
+ assert.ok(skirmish[k], `${k} is Odyssey-gated and must be marked inert in a skirmish`);
464
+ const odyssey = inertGenes(g, { genes, odyssey: true });
465
+ assert.ok(!odyssey.graceMult, "…and live once the target really is an Odyssey match");
466
+ });
467
+
468
+ test("a plain genome with no switches set marks nothing beyond the Odyssey group", () => {
469
+ const genes = geneKeys(); // strategy layer, skirmish-relevant genes only
470
+ const g = genomeFrom({ strategy: "default", genes });
471
+ g.strategy.neverInitiates = false;
472
+ g.strategy.matchEnemyForce = true;
473
+ g.strategy.capsArmy = true;
474
+ assert.deepEqual(inertGenes(g, { genes }), {}, "an ordinary aggressive genome has no dead dials");
475
+ });
tools/genome.js CHANGED
@@ -633,3 +633,48 @@ export function restoreTables(snap) {
633
  DIFFICULTY_OPTIONS.length = 0;
634
  DIFFICULTY_OPTIONS.push(...snap.difficulties);
635
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633
  DIFFICULTY_OPTIONS.length = 0;
634
  DIFFICULTY_OPTIONS.push(...snap.difficulties);
635
  }
636
+
637
+ /* ============================================================
638
+ INERT GENES — which dials are currently read by NOTHING
639
+
640
+ The genome is full of epistatic switches (see the KINDS note in this file's header): under
641
+ `neverInitiates` every offense dial is dead, `matchBuffer`/`matchFloor` are dead unless
642
+ `matchEnemyForce` is on, `standingArmyCap` is not even emitted unless `capsArmy` is, and the
643
+ whole diplomacy group is dead outside Odyssey.
644
+
645
+ That is deliberate and useful for a SEARCH — inert genes drift as junk DNA and give a lineage
646
+ somewhere new to land when a switch flips back. It is actively hostile to a PERSON. Someone
647
+ tuning `armyAttackSizeMult` for ten minutes while `neverInitiates` is checked is getting no
648
+ feedback at all, and nothing on screen tells them why.
649
+
650
+ So the editor asks this function and greys those rows out. Pure and schema-driven, so it can be
651
+ tested on its own and cannot drift from the rules the engine actually applies.
652
+ ============================================================ */
653
+
654
+ /**
655
+ * The gene keys that `genome` currently renders meaningless, with the reason for each.
656
+ * @param {Genome} genome @param {{ genes?: Gene[], odyssey?: boolean }} [opts]
657
+ * odyssey true when the target is an Odyssey match; false (default) means a skirmish, where the
658
+ * whole Odyssey-gated group is read by nothing.
659
+ * @returns {Object.<string, string>} gene key -> why it is inert
660
+ */
661
+ export function inertGenes(genome, { genes = geneKeys({ layers: ["strategy", "archetype"], odyssey: true }), odyssey = false } = {}) {
662
+ const out = {};
663
+ const s = genome.strategy || {};
664
+ for (const g of genes) {
665
+ if (g.odysseyOnly && !odyssey) out[g.key] = "Odyssey only — read by nothing in a skirmish or duel";
666
+ }
667
+ if (s.neverInitiates)
668
+ for (const k of ["attackTimeoutMult", "armyAttackSizeMult", "garrisonMult", "armyAttackSize", "attackTimeout", "garrison"])
669
+ if (genes.some(g => g.key === k)) out[k] = "inert while “never initiates” is on — it never commits a wave";
670
+ if (!s.matchEnemyForce)
671
+ for (const k of ["matchBuffer", "matchFloor"])
672
+ if (genes.some(g => g.key === k)) out[k] = "inert unless “match enemy force” is on";
673
+ if (!s.capsArmy) {
674
+ if (genes.some(g => g.key === "standingArmyCap")) out.standingArmyCap = "inert unless “cap the standing army” is on";
675
+ // warFooting only ever lifts a standingArmyCap, so with no cap there is nothing for it to lift.
676
+ for (const k of ["warFootingMult", "warFootingTime"])
677
+ if (genes.some(g => g.key === k)) out[k] = "inert without a standing-army cap — there is nothing to lift";
678
+ }
679
+ return out;
680
+ }