feat(lifecycle): rules 13 mutation splits, stay-or-become and litter
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m22s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m21s
Foundation / image (push) Successful in 5m6s

Phase 4 of the cellular revamp build plan (ADR-0179), server half.

- A chosen mutation now splits the cell (Cellular_reproduction_plan.md section
  4): split_cell divides body and reserve per channel by the tuned share, each
  cell develops the largest body its own genome builds from its part, and the
  rest joins its reserve, conserving every channel. Both plans carry the
  mutation; only the offspring expresses it. A split is refused, spending
  nothing and keeping the offer, below the tuned growth, without room beside
  the cell or at the region's organism cap.
- Stay or become: a choice (trace mutation byte 34) or a bud (step intent bit 2
  of byte 13) can hand control to the offspring; the parent becomes wildlife.
  Ownership now follows the account under rules 13, so validation and plan
  history accept a founder that became wildlife (ADR-0163 succession).
- Buds under rules 13: litter replaces the 25% twin (whole hundreds plus a
  chance, up to the tuned maximum, sharing one investment), the tuned bud fee is
  charged once and reclaimed, and births stop at the organism cap.
- New results split_applied and split_refused; owners below rules 13 refuse a
  become.

The revamp tuning file gains the reproduction keys. Tests cover the split's
conservation and refusals, stay and become splits with exact restore, a refused
second split, the cap, become validation and the litter count. Refreshes the DEV
session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-22 22:19:48 -04:00
co-authored by Claude Opus 5.5
parent 7e5775b6f7
commit 9f117c9545
19 changed files with 540 additions and 71 deletions
+88
View File
@@ -1,6 +1,7 @@
#include "evo/biology/budding.hpp"
#include <limits>
#include <utility>
namespace evo::biology {
namespace {
@@ -98,6 +99,93 @@ fund_offspring(const Genome& genome, const Genome& offspring, GrowthState parent
return std::unexpected{BuddingError::insufficient_funding}; // Too little to build a cell.
}
namespace {
// The largest growth whose body `genome` builds within `matter` on every channel, its body,
// or nothing when even the smallest does not fit. Bodies grow with growth, so a binary search.
std::expected<std::optional<std::pair<GrowthState, accounting::Inventory>>, BuddingError>
largest_fit(const Genome& genome, const accounting::Inventory& matter, std::uint32_t temperature,
const BodyTuning& tuning) {
const auto body_at = [&](std::uint32_t realized)
-> std::expected<std::optional<accounting::Inventory>, BuddingError> {
const auto budget =
metabolic_budget(genome, {realized, 0}, {temperature, {}}, 1000, tuning);
if (!budget)
return std::unexpected{BuddingError::development};
auto body = budget->body;
body.energy = {};
auto only = matter;
only.energy = {};
if (!fits(body, only))
return std::optional<accounting::Inventory>{};
return std::optional{body};
};
std::uint32_t low = 1, high = 1000;
std::optional<std::pair<GrowthState, accounting::Inventory>> best;
while (low <= high) {
const auto mid = low + (high - low) / 2;
const auto body = body_at(mid);
if (!body)
return std::unexpected{body.error()};
const auto& fitted = *body;
if (fitted) {
best = std::pair{GrowthState{mid, 0}, *fitted};
low = mid + 1;
} else {
high = mid - 1;
}
}
return best;
}
} // namespace
std::expected<SplitTransition, BuddingError>
split_cell(const Genome& parent, const Genome& child, GrowthState growth,
const accounting::Inventory& body, const accounting::Inventory& reserve,
std::uint32_t temperature_millikelvin, std::uint32_t share_per_thousand,
std::uint32_t min_growth, const BodyTuning& tuning) {
if (parent.schema_version() != child.schema_version() ||
parent.development_version() != child.development_version())
return std::unexpected{BuddingError::incompatible_genome};
if (share_per_thousand == 0 || share_per_thousand >= 1000 || body.energy.value != 0)
return std::unexpected{BuddingError::no_capability};
if (growth.realized_per_thousand < min_growth || growth.damage_per_thousand != 0)
return std::unexpected{BuddingError::not_grown};
const auto part = [&](std::uint64_t value) {
return value / 1000 * share_per_thousand + value % 1000 * share_per_thousand / 1000;
};
accounting::Inventory child_matter{}, parent_matter{};
SplitTransition split{};
split.child_reserve.energy.value = part(reserve.energy.value);
split.parent_reserve.energy.value = reserve.energy.value - split.child_reserve.energy.value;
for (std::size_t c = 0; c < body.matter.size(); ++c) {
child_matter.matter[c].value = part(body.matter[c].value);
parent_matter.matter[c].value = body.matter[c].value - child_matter.matter[c].value;
split.child_reserve.matter[c].value = part(reserve.matter[c].value);
split.parent_reserve.matter[c].value =
reserve.matter[c].value - split.child_reserve.matter[c].value;
}
const auto parent_fit = largest_fit(parent, parent_matter, temperature_millikelvin, tuning);
const auto child_fit = largest_fit(child, child_matter, temperature_millikelvin, tuning);
if (!parent_fit || !child_fit)
return std::unexpected{BuddingError::development};
const auto& parent_part = *parent_fit;
const auto& child_part = *child_fit;
if (!parent_part || !child_part)
return std::unexpected{BuddingError::insufficient_funding}; // Too little for a cell.
split.parent_growth = parent_part->first;
split.parent_body = parent_part->second;
split.child_growth = child_part->first;
split.child_body = child_part->second;
// What each body's part does not build stays with that cell as reserve.
for (std::size_t c = 0; c < body.matter.size(); ++c) {
split.parent_reserve.matter[c].value +=
parent_matter.matter[c].value - split.parent_body.matter[c].value;
split.child_reserve.matter[c].value +=
child_matter.matter[c].value - split.child_body.matter[c].value;
}
return split;
}
std::optional<accounting::Inventory> bud_cost(const Genome& genome,
std::uint32_t temperature_millikelvin) {
return offspring_cost(genome, genome, temperature_millikelvin);
+17
View File
@@ -62,6 +62,23 @@ constexpr std::array fields{
amount_limit},
Field{"mutation.buds_for_adhesion", &CellularRevampTuning::mutation_buds_for_adhesion, 0,
1'000},
Field{"reproduction.split_share_per_mille",
&CellularRevampTuning::reproduction_split_share_per_mille, 1, 999},
Field{"reproduction.split_min_growth_per_mille",
&CellularRevampTuning::reproduction_split_min_growth_per_mille, 1, 1'000},
Field{"reproduction.bud_fee_e_pj", &CellularRevampTuning::reproduction_bud_fee_e_pj, 0,
amount_limit},
Field{"reproduction.bud_fee_c_fg", &CellularRevampTuning::reproduction_bud_fee_c_fg, 0,
amount_limit},
Field{"reproduction.bud_fee_n_fg", &CellularRevampTuning::reproduction_bud_fee_n_fg, 0,
amount_limit},
Field{"reproduction.bud_fee_p_fg", &CellularRevampTuning::reproduction_bud_fee_p_fg, 0,
amount_limit},
Field{"reproduction.bud_fee_o_fg", &CellularRevampTuning::reproduction_bud_fee_o_fg, 0,
amount_limit},
Field{"reproduction.bud_fee_scale_percent",
&CellularRevampTuning::reproduction_bud_fee_scale_percent, 0, 100},
Field{"reproduction.organism_cap", &CellularRevampTuning::reproduction_organism_cap, 1, 256},
};
// A per-mutation field's bounds, in cellular_mutation_tuning_fields order.