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);