Spaces:
Paused
Diplomacy (5/N): development keeps the peace
Browse filesTies the new industrial AI to war/peace, as requested ("develop β¦ that may avoid war").
War onset is scarcity-driven (target = 0.6 β depletionΒ·1.6); now a neighbour investing in
its OWN industry β Reactors, factories, a Plasma Rig, a Datacenter, and researched tech
nodes β makes its own goods instead of fighting you for the last surface seam, so each such
asset lifts its war target (bounded at +0.4).
So a self-sufficient developer coexists markedly longer than a bare strip-miner at the same
depletion, and can hold off war entirely on a world you don't strip-mine β but development
only DELAYS war: past the cap, scarcity and the late-game creep still bite (a fully-mined
world tips hostile even at full development), and the charging-Gate finale still overrides
regardless. Zero for a bare early neighbour and for the whole skirmish path (no diplomacy),
so the stance maths is unchanged until the AI actually develops.
- engine/diplomacy.js: aiDevelopment(state) + a bounded softening term on the scarcity
target; imports BUILDINGS + TECHS.
- test/devDiplomacy.test.js: a developed neighbour holds the peace where a bare one goes to
war at equal depletion; a maxed-out developer still tips hostile on a dead world.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AEQUVetLk31Jj7niDQAsXL
- engine/diplomacy.js +32 -0
- test/devDiplomacy.test.js +47 -0
|
@@ -19,10 +19,37 @@
|
|
| 19 |
"use strict";
|
| 20 |
|
| 21 |
import { chargingPlayerWonder } from "./wonder.js";
|
|
|
|
|
|
|
| 22 |
|
| 23 |
// Above this stance the neighbour holds its fire (peace); at or below it, war.
|
| 24 |
export const PEACE_THRESHOLD = -0.15;
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const START_STANCE = 0.35; // a new neighbour starts Cordial
|
| 27 |
const DRIFT_RATE = 0.05; // how fast stance chases its scarcity target (per second)
|
| 28 |
const GRIEVANCE_PER_KILL = 0.04; // stance lost per enemy ship you destroy on this world
|
|
@@ -128,6 +155,11 @@ export function updateDiplomacy(state, dt) {
|
|
| 128 |
// cordial during the opening grace window regardless of how fast you strip-mine.
|
| 129 |
let target = 0.6 - dip.depletion * 1.6;
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
// LATE-GAME CREEP: past grace, resentment grows linearly and without bound, so the
|
| 132 |
// hostility curve never plateaus. Zero at grace-end (onset stays scarcity-driven),
|
| 133 |
// it only bites deep into a long game β an overstay turns lethal, a mined-out world
|
|
|
|
| 19 |
"use strict";
|
| 20 |
|
| 21 |
import { chargingPlayerWonder } from "./wonder.js";
|
| 22 |
+
import { BUILDINGS } from "./entities.js";
|
| 23 |
+
import { TECHS } from "./techtree.js";
|
| 24 |
|
| 25 |
// Above this stance the neighbour holds its fire (peace); at or below it, war.
|
| 26 |
export const PEACE_THRESHOLD = -0.15;
|
| 27 |
|
| 28 |
+
// DEVELOPMENT keeps the peace (Odyssey): a neighbour investing in its OWN industry β Reactors,
|
| 29 |
+
// factories, a Plasma Rig, a Datacenter, and the research it completes (engine/ai.js aiIndustry) β
|
| 30 |
+
// makes its own goods instead of fighting you for the last surface seam, so it's less pressured as
|
| 31 |
+
// the world mines out. Each such asset lifts its war target, bounded β so development can DELAY and
|
| 32 |
+
// soften war, or hold it off on a world you don't strip-mine, but never force unconditional permanent
|
| 33 |
+
// peace: past the cap, scarcity and the late-game creep still bite, and the Gate finale still overrides.
|
| 34 |
+
const DEV_SOFT_PER = 0.05; // stance-target lifted per industrial building / researched tech node
|
| 35 |
+
const DEV_SOFT_CAP = 0.4; // ...capped, so a fully-mined world still tips to war even at full development
|
| 36 |
+
|
| 37 |
+
// How developed the neighbour is: its completed industrial buildings (power, factories, the Plasma
|
| 38 |
+
// Rig, the Datacenter) plus the tech nodes it has researched. Deterministic β reads only entity and
|
| 39 |
+
// upgrade state. Zero for a bare early neighbour (and for the whole skirmish path, which never calls
|
| 40 |
+
// this), so the stance maths is unchanged until the AI actually starts to develop.
|
| 41 |
+
function aiDevelopment(state) {
|
| 42 |
+
let n = 0;
|
| 43 |
+
for (const b of state.buildings.values()) {
|
| 44 |
+
if (b.owner !== "ai" || b.constructing) continue;
|
| 45 |
+
const def = BUILDINGS[b.type];
|
| 46 |
+
if (def && (def.energyGrants || def.recipe || def.rig || b.type === "datacenter")) n++;
|
| 47 |
+
}
|
| 48 |
+
const ups = state.players.ai && state.players.ai.upgrades;
|
| 49 |
+
if (ups) for (const k in TECHS) if (ups[k]) n++;
|
| 50 |
+
return n;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
const START_STANCE = 0.35; // a new neighbour starts Cordial
|
| 54 |
const DRIFT_RATE = 0.05; // how fast stance chases its scarcity target (per second)
|
| 55 |
const GRIEVANCE_PER_KILL = 0.04; // stance lost per enemy ship you destroy on this world
|
|
|
|
| 155 |
// cordial during the opening grace window regardless of how fast you strip-mine.
|
| 156 |
let target = 0.6 - dip.depletion * 1.6;
|
| 157 |
|
| 158 |
+
// DEVELOPMENT keeps the peace: lift the war target by how developed the neighbour is (bounded), so a
|
| 159 |
+
// self-sufficient industrial neighbour coexists markedly longer than a bare strip-miner at the same
|
| 160 |
+
// depletion. Applied to the SCARCITY target before creep/grace/finale, so those still layer on top.
|
| 161 |
+
target += Math.min(DEV_SOFT_CAP, aiDevelopment(state) * DEV_SOFT_PER);
|
| 162 |
+
|
| 163 |
// LATE-GAME CREEP: past grace, resentment grows linearly and without bound, so the
|
| 164 |
// hostility curve never plateaus. Zero at grace-end (onset stays scarcity-driven),
|
| 165 |
// it only bites deep into a long game β an overstay turns lethal, a mined-out world
|
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { test } from "node:test";
|
| 2 |
+
import assert from "node:assert/strict";
|
| 3 |
+
import { createGameState, makeBuilding } from "../engine/state.js";
|
| 4 |
+
import { updateDiplomacy, PEACE_THRESHOLD } from "../engine/diplomacy.js";
|
| 5 |
+
|
| 6 |
+
// Drift a world's stance to equilibrium at a FIXED depletion and a FIXED time just past the opening
|
| 7 |
+
// grace (so the grace floor is off but the late-game creep is still negligible), isolating the effect
|
| 8 |
+
// of the neighbour's own development on whether it turns hostile.
|
| 9 |
+
function settleStance(build) {
|
| 10 |
+
const s = createGameState({ planetId: "ferros", endless: true });
|
| 11 |
+
s.diplomacy = { stance: 0.35, depletion: 0, tributes: 0, lastAiUnits: 0 };
|
| 12 |
+
for (const n of s.map.nodes) n.amount = n.max * 0.5; // ~50% mined out on both worlds
|
| 13 |
+
s.time = 430; // just past GRACE_TIME (420) β creep β 0
|
| 14 |
+
build(s); // stand up whatever industry this world's AI has
|
| 15 |
+
for (let i = 0; i < 400; i++) updateDiplomacy(s, 1.0); // drift to equilibrium (DRIFT_RATE 0.05/s)
|
| 16 |
+
return s.diplomacy.stance;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
test("a developed neighbour keeps the peace where a bare strip-miner goes to war (same depletion)", () => {
|
| 20 |
+
const bare = settleStance(() => {}); // just its seeded colony ship / CC β no industry
|
| 21 |
+
const developed = settleStance(s => {
|
| 22 |
+
// A self-sufficient industrial neighbour: power, the factory chain, a rig, a datacenter + research.
|
| 23 |
+
const kit = [["reactor", 700, 440], ["reactor", 700, 480], ["smelter", 740, 440], ["assembler", 740, 480],
|
| 24 |
+
["chipfab", 780, 440], ["machineworks", 780, 480], ["datacenter", 820, 440], ["plasmarig", 820, 480]];
|
| 25 |
+
for (const [t, x, y] of kit) { const b = makeBuilding(t, "ai", x, y); s.buildings.set(b.id, b); }
|
| 26 |
+
Object.assign(s.players.ai.upgrades, { metallurgy: true, electronics: true, machining: true });
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
assert.ok(bare <= PEACE_THRESHOLD, `the bare strip-miner turned hostile (${bare.toFixed(2)})`);
|
| 30 |
+
assert.ok(developed > PEACE_THRESHOLD, `the developed neighbour held the peace (${developed.toFixed(2)})`);
|
| 31 |
+
assert.ok(developed > bare + 0.2, `development markedly softened the stance (${developed.toFixed(2)} vs ${bare.toFixed(2)})`);
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
test("development delays war but never prevents it β a fully-mined world still tips hostile", () => {
|
| 35 |
+
const s = createGameState({ planetId: "ferros", endless: true });
|
| 36 |
+
s.diplomacy = { stance: 0.35, depletion: 0, tributes: 0, lastAiUnits: 0 };
|
| 37 |
+
for (const n of s.map.nodes) n.amount = 0; // fully stripped
|
| 38 |
+
s.time = 430;
|
| 39 |
+
for (const [t, x, y] of [["reactor", 700, 440], ["smelter", 740, 440], ["assembler", 740, 480],
|
| 40 |
+
["chipfab", 780, 440], ["machineworks", 780, 480], ["datacenter", 820, 440],
|
| 41 |
+
["plasmarig", 820, 480], ["antimatterforge", 860, 440]]) {
|
| 42 |
+
const b = makeBuilding(t, "ai", x, y); s.buildings.set(b.id, b);
|
| 43 |
+
}
|
| 44 |
+
Object.assign(s.players.ai.upgrades, { metallurgy: true, electronics: true, machining: true, antimatter: true });
|
| 45 |
+
for (let i = 0; i < 400; i++) updateDiplomacy(s, 1.0);
|
| 46 |
+
assert.ok(s.diplomacy.stance <= PEACE_THRESHOLD, `even a maxed-out developer goes to war on a dead world (${s.diplomacy.stance.toFixed(2)})`);
|
| 47 |
+
});
|