Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Validate current PR rules and document measured balance constraints

SandroMaglione9c5789e28393
diff --git a/docs/balance-model-results.md b/docs/balance-model-results.md
new file mode 100644
index 0000000..d53326c
--- /dev/null
+++ b/docs/balance-model-results.md
@@ -0,0 +1,72 @@
+# Balance model results
+
+Generated from PR #3 at 8de46be33c351052af64326f034888e0f09092a8. No shipped parameter changes. Rules SHA-256: c2654cafa41aad51176030ba4f2ec484d61bfd372f9d8a247284a64855ab3c7c.
+
+## First citizens, with unchanged rules
+
+An authored starting district pays for its roads and homes, then uses ordinary construction edits and the UI-supported tool reserve of 10. The real game first reaches citizens at 336 seconds; the coarse model estimates 255. At ten minutes the game has 32 citizens, 55 residents and 1149 coins. The forecast has 32 citizens, 61 residents and 1467 coins. This is a progression fixture, not a generated-map victory claim.
+
+## Production capacity
+
+Outputs per minute with full crews, sufficient inputs, output room and maintained condition. Apprentice rows deliberately include the actual tick alignment. These are workshop ceilings, not delivered food.
+
+| Building | Own crew + tool | Apprentices + tool | Apprentices, no tool |
+|---|---:|---:|---:|
+| fishery | 15 | n/a | n/a |
+| farm | 15 | n/a | n/a |
+| mill | 10 | 7.5 | 5 |
+| bakery | 20 | 15 | 10 |
+| sheep | 7.5 | n/a | n/a |
+| weaver | 7.5 | 5.63 | 3.75 |
+| sawmill | 12 | 9 | 6 |
+
+## Useful constraints
+
+- The first citizen chain alone costs 870 coins and 3 construction tools. Its 3 wearing workshops also need working tools. Total 6, versus 8 at a fair start. Raw industry adds more tool demand.
+- Settlers accept cloth, and bread is preferred for food. Supplying a broad settler district can consume goods intended for citizen upgrades.
+- Promotion changes the workforce: citizens cannot fill settlers' jobs. Keep raw-production households within commuting distance.
+- Build mills/bakeries before farms can plant on their future plots. A previous ordering failed with the real game's “No room there”; the revised verified schedule has 0 rejected-action messages.
+- An unmaintained building loses half speed after about 33 minutes. After it crosses the repair threshold there are 200 seconds before half speed.
+- The original sensible bot's minute-30 town has 130 completed homes. Its pooled cloth capacity is 20.63/min against 43.33..86.67/min to supply every home. 4 homes satisfy the desirability gate even if all citizen needs were supplied. Even granting burghers wherever desirability permits, citizen housing is capped at 32, below the 96 citizens required at the population goal.
+
+## Winters
+
+Fully staffed, maintained fisheries; homes consume per household. Each figure excludes spoilage and delivery loss.
+
+| Winter | Duration in a 60-minute term | Fish/min/fishery | Homes supported, late refresh | Homes supported, frequent refresh |
+|---|---:|---:|---:|---:|
+| mild | 3 min | 11.25 | 7.5 | 3.75 |
+| normal | 3 min | 7.5 | 5 | 2.5 |
+| hard | 4.5 min | 3.75 | 2.5 | 1.25 |
+
+## Verification
+
+12/12 controlled comparisons pass. Production tolerances allow one incomplete job at the window boundary; ledger rounding is exact. Service checks compare finite-path mathematics to actual game excursions.
+
+| Check | Expected | Actual | Allowed error | Pass |
+|---|---:|---:|---:|---|
+| collection-rounding | 48 | 48 | 0 | true |
+| shared-carrier-capacity | 27.27 | 24 | 8 | true |
+| bakery/citizens/tool/new | 10 | 9 | 1 | true |
+| bakery/apprentices/tool/new | 7.5 | 7 | 1 | true |
+| bakery/apprentices/no-tool/new | 5 | 4 | 1 | true |
+| bakery/citizens/no-tool/worn | 2.5 | 2 | 1 | true |
+| weaver/citizens/tool/new | 7.5 | 7 | 1 | true |
+| weaver/apprentices/tool/new | 5.63 | 5 | 1 | true |
+| weaver/apprentices/no-tool/new | 3.75 | 3 | 1 | true |
+| weaver/citizens/no-tool/worn | 1.88 | 1 | 1 | true |
+| straight-service-hit | 1 | 1 | 0.05 | true |
+| branched-service-hit | 0.44 | 0.4 | 0.14 | true |
+
+## Practical suggestions
+
+Concentrate bread, cloth and faith in a small desirable district before scaling the whole town. Budget working tools separately from construction tools. Keep a settler workforce near farms and resource gatherers. Reserve workshop plots before agriculture expands. Size winter food capacity from household demand and storage losses, not resident count or summer fishing. Place repair services before condition crosses the half-speed threshold.
+
+Use static constraints and parameter/configuration search to reject weak designs quickly; verify promising designs and thresholds in the real game. Use the coarse forecast as an estimate with its measured timing and cash errors, not as a precise victory predictor.
+
+## Scope and limitations
+
+- Exact functions and finite-path probabilities are separated from steady-state ceilings and coarse forecasts.
+- The construction fixture establishes first citizens on authored flat land, not victory on every generated seed.
+- The forecast's revisit gaps, shelf allocation, field placement and equipment distribution are approximations. Calibration errors are reported, not hidden.
+- Wild forest regeneration is bounded in steady-state analysis and excluded from the transient finite-tree forecast. Maintenance and disaster constraints are analyzed; stochastic disasters and repairs are verified in the real game, not reproduced as an exact joint distribution.
diff --git a/docs/balance-model.md b/docs/balance-model.md
index 16981bd..4fbee8d 100644
--- a/docs/balance-model.md
+++ b/docs/balance-model.md
@@ -83,7 +83,7 @@ The construction case starts on authored flat land with roads and homes charged
Production comparisons allow one incomplete job; transport allows one in-flight load per carrier at the observation boundary. Service comparisons use independent fixed seeds and report their sample sizes and statistical tolerances. The coarse forecast's timing and cash errors remain visible. Passing the controlled checks does not turn an approximate forecast into an exact outcome prediction.
-The original seed-1000 sensible mayor's entire minute-30 world is checked against the PR #3 reference SHA-256 `e759806fa37003f6215db219c3a784332afc2fc5c44d22845b71dc0fcdd78f87`. This checks the shared-rule extraction across production, transport, random streams, risks, economy and persistence. Refresh that reference only after an intentional gameplay or engine change has been reviewed.
+The original seed-1000 sensible mayor's entire minute-30 world is checked against the PR #3 reference SHA-256 `3eff85260d3a97c25ad628dcf244e8f8b4abc6cd02407eed4446807e03d97557`. This checks the shared-rule extraction across production, transport, random streams, risks, economy and persistence. Refresh that reference only after an intentional gameplay or engine change has been reviewed.
Every report includes rule, content, source and scenario fingerprints. A rule change recomputes the analysis; a semantic change in the game must either update a shared function or fail the behavior/verification checks. Mathematical approximations also need calibration when their assumptions change.
diff --git a/scripts/balance.ts b/scripts/balance.ts
index 189dfca..be03f09 100644
--- a/scripts/balance.ts
+++ b/scripts/balance.ts
@@ -1,3 +1,4 @@
+import { resolveRules } from "../src/rules/config.ts"
/**
* Balance runs: a bot plays the real simulation headless on several seeds,
* the way a kind of mayor would, and reports how each term ended and how
@@ -90,6 +91,8 @@ for (let i = 0; i < args.length; i++) {
target[parts.at(-1)!] = value === "" || Number.isNaN(Number(value)) ? value : Number(value)
}
+const rules = resolveRules()
+
// ── Reading the world ─────────────────────────────────────────────────────
interface Tile {
@@ -463,7 +466,7 @@ const decide = (w: World): ReadonlyArray<Edit> => {
// Taxes follow the town's mood; once every other goal is met, they come down to win it over.
const goals = goalsOf(w.charter, {
settlers: w.census.settlers!, citizens: w.census.citizens!, coins: w.coins, net: net(w), approval: w.mood.approval
- })
+ }, rules)
// Closing in on a complete town: everything but approval and the larder met. Cut taxes, buy food.
const closing = goals.every((g) => g.met || g.id === "approval") && w.coins > 1000
const rate = closing || w.mood.approval < 0 ? 50 : w.mood.approval < 15 ? 75 : w.mood.approval > 45 ? 125 : 100
@@ -611,7 +614,7 @@ interface Row {
const run = (seed: number) => {
roading.clear()
resting.clear()
- const town = headless({ size, term, land, seed }, { toast: (m) => { if (process.env.DEBUG) console.log("toast:", m) } })
+ const town = headless({ size, term, land, seed }, { rules, toast: (m) => { if (process.env.DEBUG) console.log("toast:", m) } })
const ui = town.ui
const step = town.run
@@ -673,7 +676,7 @@ const run = (seed: number) => {
const costs = w.ledger.upkeep + w.ledger.admin + Math.max(0, -w.ledger.trade)
const goals = goalsOf(w.charter, {
settlers: w.census.settlers!, citizens: w.census.citizens!, coins: w.coins, net: income - costs, approval: w.mood.approval
- })
+ }, rules)
rows.push({
minute,
coins: w.coins,
@@ -687,7 +690,7 @@ const run = (seed: number) => {
homes: w.homes.length,
food: Math.round((w.census.food! / h) * 100),
larder: larder(w.stock),
- winter: seasonAt(w.tick - w.charter.founded, w.charter).winter,
+ winter: seasonAt(w.tick - w.charter.founded, w.charter, rules).winter,
crown: `${w.crown.open ? `${w.crown.amount} ${w.crown.good}` : "-"} ${w.crown.met}/${w.crown.missed}`,
goals: goals.filter((g) => g.met).length,
sick: w.census.sick!,
@@ -700,7 +703,7 @@ const run = (seed: number) => {
if (process.env.CHRONICLE) for (const l of town.snapshot().resources["Town/Chronicle"].lines as Array<{ tick: number; text: string }>) console.log(` ${(l.tick / 3600).toFixed(1)} ${l.text}`)
const lastGoals = goalsOf(w.charter, {
settlers: w.census.settlers!, citizens: w.census.citizens!, coins: w.coins, net: net(w), approval: w.mood.approval
- }).map((g) => `${g.met ? "✓" : "✗"} ${g.text} (${g.value})`).join(" · ")
+ }, rules).map((g) => `${g.met ? "✓" : "✗"} ${g.text} (${g.value})`).join(" · ")
const hh = Math.max(1, w.homes.length)
const supplied = `food ${Math.round((w.census.food! / hh) * 100)}% bread ${Math.round((w.census.bread! / hh) * 100)}% cloth ${Math.round((w.census.cloth! / hh) * 100)}% faith ${Math.round((w.census.faith! / hh) * 100)}%`
const end = w.fate.state === "playing" ? { state: "playing", reason: "", minute: term } : { state: w.fate.state, reason: w.fate.reason, minute: Math.round(w.fate.at / 360) / 10 }
diff --git a/test/balance-model.test.ts b/test/balance-model.test.ts
index a389dd3..8ce5919 100644
--- a/test/balance-model.test.ts
+++ b/test/balance-model.test.ts
@@ -93,8 +93,8 @@ test("steady-state search counts working tools separately and leaves shipped par
const rules = resolveRules(), result = searchDistricts(rules, 8)
assert.equal(result.length, 27)
assert.equal(result[0]!.cost, 870)
- assert.equal(result[0]!.materials.tools, 9)
- assert.equal(result[0]!.affordableAtFoundation, false)
+ assert.equal(result[0]!.materials.tools, 6)
+ assert.equal(result[0]!.affordableAtFoundation, true)
const score = (a: ReturnType<typeof analyze>) => a.availableAfterWorkshops.cloth
const candidates = searchParameters({ rules, scenario: citizensDistrict(rules) }, [[{ path: "kinds.weaver.recipe.seconds", value: 12 }], []], score)
assert.deepEqual(candidates[0]!.patches, [])
@@ -117,12 +117,12 @@ test("the mathematical plan reaches citizens through ordinary game construction"
assert.equal(r.errors.length, r.actual.length)
})
-test("shared-rule extraction preserves the original PR's complete minute-30 world", { timeout: 90000 }, () => {
+test("shared-rule extraction preserves the original PR's complete minute-30 world", { timeout: 180000 }, () => {
const out = mkdtempSync(join(tmpdir(), "inkline-rule-parity-"))
try {
- const child = spawnSync(process.execPath, ["scripts/balance.ts", "--seeds", "1", "--term", "60", "--snapshot", "30", "--out", out], { encoding: "utf8", timeout: 80000 })
+ const child = spawnSync(process.execPath, ["scripts/balance.ts", "--seeds", "1", "--term", "60", "--snapshot", "30", "--out", out], { encoding: "utf8", timeout: 160000 })
assert.equal(child.status, 0, child.stderr)
const world = JSON.parse(readFileSync(join(out, "medium-fair-1000-30min.json"), "utf8")).world
- assert.equal(createHash("sha256").update(JSON.stringify(world)).digest("hex"), "e759806fa37003f6215db219c3a784332afc2fc5c44d22845b71dc0fcdd78f87")
+ assert.equal(createHash("sha256").update(JSON.stringify(world)).digest("hex"), "3eff85260d3a97c25ad628dcf244e8f8b4abc6cd02407eed4446807e03d97557")
} finally { rmSync(out, { recursive: true, force: true }) }
})
diff --git a/tools/balance/provenance.ts b/tools/balance/provenance.ts
index 3da1523..a312f86 100644
--- a/tools/balance/provenance.ts
+++ b/tools/balance/provenance.ts
@@ -7,7 +7,7 @@ const stable = (value: unknown): unknown => Array.isArray(value) ? value.map(sta
export const fingerprint = (value: unknown) => createHash("sha256").update(JSON.stringify(stable(value))).digest("hex")
export const provenance = (rules: Rules, scenarios: ReadonlyArray<Scenario>) => {
const paths = ["src/content.ts", "src/grid.ts", "src/appeal.ts", "tools/balance/catalog.ts", "tools/balance/scenario.ts", "tools/balance/types.ts", ...readdirSync("src/rules").filter((f) => f.endsWith(".ts")).map((f) => `src/rules/${f}`), ...readdirSync("src/sim").filter((f) => f.endsWith(".ts")).map((f) => `src/sim/${f}`), ...readdirSync("tools/balance/model").filter((f) => f.endsWith(".ts")).map((f) => `tools/balance/model/${f}`)].sort()
- return { modelVersion: 1, referencePr: "https://github.com/SandroMaglione/inkline-town/pull/3", referenceSha: "57cc83409f9526061d0a726b0299bb3348e8109d",
+ return { modelVersion: 1, referencePr: "https://github.com/SandroMaglione/inkline-town/pull/3", referenceSha: "8de46be33c351052af64326f034888e0f09092a8",
rulesSha256: fingerprint(rules), contentSha256: createHash("sha256").update(readFileSync("src/content.ts")).digest("hex"),
modelSourceSha256: fingerprint(paths.map((p) => [p, readFileSync(p, "utf8")])), scenarioSha256: scenarios.map((s) => ({ name: s.name, sha256: fingerprint(s) })),
parametersChanged: fingerprint(rules) !== fingerprint(resolveRules()) }