Run 15: known-nodes exploration (addendum stage 1), per-town debug, O(n^2) fix

Exploration addendum stage 1: per-NPC known-nodes. NPCs gather only from
resources they've personally sensed (radius 22) or been told about;
founders seed with home ground, children inherit parents' maps, node
knowledge diffuses between neighbors like skills. Starving NPCs venture
outward and sense as they go - non-random needs-driven exploration, the
seed of first contact. Repopulation preserved (seeding + survival food
fallback): all towns fed, population stable 86-109 over 240 days.

Debug screen rebuilt: the ~68-row per-villager roster (overflowing at
four-town scale) replaced with a per-town summary - pop, fed%, knowledge,
debris, state breakdown, buildings, culture-colored, plus world
births/deaths. Scales to any population.

Performance: added phase timers and measured instead of guessing - npc.Tick
was 94% of cost, O(n^2) via TickResting calling RestingOccupancy (full
population scan) per building per resting NPC. Fixed with a once-per-tick
occupancy cache on Building. npc phase ~4x faster and now linear; full
240-day four-town run in 180s, faster than the pre-exploration baseline.
Profiling scaffolding removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 21:17:24 -04:00
parent 6cbe4bcf83
commit 10e772d087
7 changed files with 378 additions and 66 deletions
+33 -2
View File
@@ -331,8 +331,39 @@ debris — selfishness now literally fails to sustain a population.** A
town that won't share or cooperate can't feed its people or raise a next
generation. The most damning verdict the sim has produced.
**Next:** crisis-recovery experiment (North's resilience); save/load;
then the player pivot.
## Run 15 — Known-nodes exploration (addendum §4) + the O(n²) hunt
**Built (stage 1 of the exploration addendum):** per-NPC known-nodes — an
NPC gathers only from resource nodes it has personally sensed (radius 22)
or been told about. Founders seed with their home ground; children
inherit their parents' map; node knowledge diffuses between neighbors by
the same proximity rule as skills. When nothing known qualifies, a
starving NPC ventures outward (biased away from town anchor) and senses
as it goes — the non-random, needs-driven venture-out the addendum wants,
and the seed of first contact. Repopulation explicitly preserved: seeding
+ a survival food fallback keep towns fed (verified: all four 0.560.78
fed, population stable 86109 over 240 days).
**Debug screen rebuilt:** the per-villager roster (one line per soul,
~68 rows overflowing the panel at four-town scale) replaced with a
per-town summary — population, fed%, knowledge, debris, state breakdown,
buildings, colored by culture, plus world births/deaths. Scales to any
population.
**The performance lesson, earned properly this time:** the sim slowed to
a crawl and I burned four rounds guessing (node index — no; periodic
sensing — barely; node cell-index — barely; gated diffusion — barely).
Then I added phase timers and *measured*: `npc.Tick` was 94% of cost and
grew O(n²) with population. The culprit was `TickResting` calling
`RestingOccupancy` (a full-population scan) once per building per resting
NPC — O(buildings × NPCs²) per tick. Fixed with a once-per-tick occupancy
cache on Building. Result: npc phase ~4× faster and now linear; full
240-day four-town run in **180s, faster than the pre-exploration
baseline** despite all the new systems. Lesson restated: profile first;
the bottleneck is never where you guess.
**Next:** stage 2 (soul-weighted venture-out + first contact); crisis-
recovery experiment; save/load; then the player pivot.
---