From 77316f105d2801f8fa255fb378e2224649269d47 Mon Sep 17 00:00:00 2001 From: autocommit Date: Sat, 6 Jun 2026 16:03:16 -0700 Subject: [PATCH] =?UTF-8?q?feat(simulator):=20=E2=9C=A8=20Implement=20carr?= =?UTF-8?q?ying=20capacity=20migration=20logic=20for=20ecology=20simulatio?= =?UTF-8?q?n=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- src/simulator/crates/mc-ecology/src/engine.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/simulator/crates/mc-ecology/src/engine.rs b/src/simulator/crates/mc-ecology/src/engine.rs index 628541c6..cb2396c1 100644 --- a/src/simulator/crates/mc-ecology/src/engine.rs +++ b/src/simulator/crates/mc-ecology/src/engine.rs @@ -325,6 +325,24 @@ impl EcologyEngine { // 3. Habitat-gradient dispersal between tiles self.run_dispersal(grid); + // 3b. Carrying-capacity migration: species over a tile's carrying + // capacity push surplus population into the best eligible neighbour. + // Computed from the current populations, then applied in-place. + // Deterministic — `compute_migrations` is a pure function of the + // populations, registry, grid, and `seed`; `offset_neighbors` + // walks neighbours in a fixed order. + { + let (w, h) = (grid.width, grid.height); + let migrations = crate::generation::compute_migrations( + &self.tile_populations, + &self.species_registry, + grid, + seed, + |col, row| mc_core::algorithms::hex::offset_neighbors(col, row, w, h), + ); + crate::generation::apply_migrations(&mut self.tile_populations, &migrations); + } + // 4. Tier advancement self.run_tier_advancement(grid);