#pragma once #include "evo/biology/metabolism.hpp" #include #include #include #include // M11.5 budding (ADR-0098 decision 1, ADR-0125): a funded proposal, detached from any // owner. The parent pays its ADR-0032 reproduction investment and a starting provision // from its reserve; nothing is drawn from its body. namespace evo::biology { // Seconds of the bud's full demand (maintenance plus full-speed movement) the parent // provides as starting reserve energy: the founder's reserve rule (ADR-0100). Trial. inline constexpr std::uint64_t bud_provision_seconds = 30; struct BudTransition { GrowthState growth{}; // the bud's, the largest the investment matter builds accounting::Inventory body{}; // the bud's developed body accounting::Inventory reserve; // the bud's: leftover matter and the provision accounting::Inventory parent_reserve; // the parent's reserve after paying accounting::Picojoules heat{}; // the investment's construction energy auto operator<=>(const BudTransition&) const = default; }; enum class BuddingError : std::uint8_t { no_capability, // The genome cannot reproduce. not_grown, // The parent is not fully realized, or is damaged. insufficient_funding, // Some channel of investment plus provision is missing. development, // The genome's rules cannot develop it. incompatible_genome // Distinct schema/development laws, or conflicting same-ID contents. }; // Pure and deterministic. On every channel the parent's reserve before equals its reserve // after plus the bud's body and reserve, plus heat in energy. A refusal spends nothing. // `share` > 1 (ADR-0137 twins) funds one of that many buds from the same investment: each // gets the investment divided by `share`, so twins are smaller, not extra. [[nodiscard]] std::expected fund_bud(const Genome& genome, GrowthState parent_growth, const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin, std::uint32_t share = 1); // ADR-0164: the expressed parent pays its own investment; the distinct inherited // genome determines the newborn body/growth and its own provision. Both records // must use the same schema/development versions. Inputs and parent anatomy are // unchanged. This proposal confers no identity, placement, ancestry or control authority. [[nodiscard]] std::expected fund_offspring(const Genome& parent, const Genome& offspring, GrowthState parent_growth, const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin, std::uint32_t share = 1); // Exact charge for that pair and share from a full-grown, undamaged parent. [[nodiscard]] std::optional offspring_cost(const Genome& parent, const Genome& offspring, std::uint32_t temperature_millikelvin, std::uint32_t share = 1); // Rules 13 (ADR-0179; Cellular_reproduction_plan.md section 4): a mutation split. The parent's // body and reserve divide per channel, the offspring taking `share_per_thousand` (rounded // down); each cell then develops the largest growth its own genome builds from its part of the // body, and matter beyond that joins its reserve. Nothing is built, burned or lost: on every // channel the two bodies and reserves sum to the parent's. Refused, changing nothing, when // the parent is below `min_growth` or damaged, or either part builds no cell at all. struct SplitTransition { GrowthState parent_growth{}, child_growth{}; accounting::Inventory parent_body{}, parent_reserve{}, child_body{}, child_reserve{}; auto operator<=>(const SplitTransition&) const = default; }; [[nodiscard]] std::expected 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 = default_body_tuning); // Rules 13: the largest growth whose body `genome` builds within `matter` on every channel and // that body; nothing when even the smallest does not fit. [[nodiscard]] std::expected>, BuddingError> largest_growth_within(const Genome& genome, const accounting::Inventory& matter, std::uint32_t temperature_millikelvin, const BodyTuning& tuning = default_body_tuning); // What one bud takes from a fully grown, undamaged parent of this genome at this temperature // (ADR-0129 amendment): investment matter per channel, and construction energy plus the // bud's provision; exactly what `fund_bud` charges such a parent. Nullopt when the genome // cannot bud or cannot build a cell from its investment. [[nodiscard]] std::optional bud_cost(const Genome& genome, std::uint32_t temperature_millikelvin); } // namespace evo::biology