diff --git a/Cellular_Revamp_Build_Plan.md b/Cellular_Revamp_Build_Plan.md index 413a375..b1c9dcc 100644 --- a/Cellular_Revamp_Build_Plan.md +++ b/Cellular_Revamp_Build_Plan.md @@ -73,7 +73,7 @@ phase 1 body values. Verify: conservation per channel and energy across burning, the pool, kills and drips; no burn of excluded matter except for upkeep; replay determinism. -### Phase 3: mutation offers +### Phase 3: mutation offers - server done Server: - Catalog of the 49 mutations as data: effect, eligibility, triggers, base weight, @@ -86,7 +86,10 @@ Server: - Cost paid from the reserve (matter may stand in for energy) and reclaimed as seeded random bubbles, merging into the farthest bubble at the deposit limit. -Client: offer screen with name, pro, con, chance, cost and shortfall. +Until phase 4, a chosen mutation edits the offspring plan (as rules 10-12 do); phase 4 +turns the choice into the split. + +Client (session v14 step): offer screen with name, pro, con, chance, cost and shortfall. Verify: chances sum to the option count and respect floor and cap; the draw's marginal frequencies match the chances over a seed ensemble; triggers fire as diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index edf2ca5..285c521 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261022T224609-01218f90:1792723569"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261022T225821-fb28cb29:1792724301"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning b/deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning index e488e0d..fa6aed1 100644 --- a/deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning +++ b/deploy/kubernetes/region/dev/tuning/cellular-revamp.tuning @@ -7,6 +7,7 @@ tuning.version = 1 # Body (body and maintenance plan). body.essential_upkeep_per_mille = 250 # share of upkeep no upkeep-efficiency trait reduces body.reserve_load_per_mille = 1_000 # reserve matter carried as load (slower, costlier thrust) +body.growth_per_tick_centi_mille = 500 # 5 per mille of full size per tick at growth speed 100 # Energy (feeding and energy plan): what 1,000 fg of reserve matter stands in for when the # reserve's energy runs out. Bubbles carry ~17 pJ of energy per fg of matter, so 2 pJ per fg @@ -29,3 +30,26 @@ predation.kill_bubble_per_mille = 500 # a kill's remainder left as bubbles; th spent.drip_interval_ticks = 20 # once a second spent.drip_bubble_pj = 20_000_000 # largest energy bubble per drip spent.drip_bubble_fg = 1_000_000 # largest matter bubble per drip and channel + +# Mutation offers (mutation plan section 3). Chances in parts per million. +mutation.options = 3 +mutation.floor_ppm = 10 # 0.001%: anomalies always happen +mutation.cap_ppm = 700_000 # 70% +mutation.score_min = -1_000 +mutation.score_max = 1_000 +mutation.max_multiplier_per_mille = 10_000 # weight x10 at the top score +mutation.min_multiplier_per_mille = 0 # weight x0 at the bottom (the floor still applies) +mutation.offer_interval_ticks = 500 # an offer every 25 s of active play +mutation.min_points = 25 # trait bounds in reference points (founder 100) +mutation.max_points = 1_000 +mutation.recipe_min_share = 20 # per thousand of the body per channel +mutation.max_offspring = 10 # per bud, so litter at most 900 +mutation.carbon_for_light_fg = 20_000_000 # carbon burned before photosynthesis is offered +mutation.buds_for_adhesion = 5 # on-demand buds before Adhesion is offered + +# Per-mutation overrides are optional: `mutation.. = value`, with fields enabled, +# base_weight, increase_points, decrease_points, primary_step, paired_step, spread_step, +# increase_ticks, decrease_ticks, cost_e_pj, cost_c_fg, cost_n_fg, cost_p_fg, cost_o_fg and +# cost_scale_percent. Unset fields keep the catalog's defaults (costs 0). For example: +# mutation.strong_propulsion.cost_e_pj = 1_000_000 +# mutation.strong_propulsion.cost_scale_percent = 50 diff --git a/include/evo/biology/cellular_revamp_tuning.hpp b/include/evo/biology/cellular_revamp_tuning.hpp index c504768..119c9b0 100644 --- a/include/evo/biology/cellular_revamp_tuning.hpp +++ b/include/evo/biology/cellular_revamp_tuning.hpp @@ -1,7 +1,9 @@ #pragma once +#include "evo/biology/cellular_catalog.hpp" #include "evo/biology/cellular_tuning.hpp" +#include #include #include #include @@ -23,6 +25,8 @@ struct CellularRevampTuning { std::int64_t body_essential_upkeep_per_mille{}; // Body: share of reserve matter carried as load on handling and thrust costs. std::int64_t body_reserve_load_per_mille{}; + // Body: growth per tick at growth speed 100, in hundredths of a per mille. + std::int64_t body_growth_per_tick_centi_mille{}; // Energy: picojoules 1,000 fg of each matter channel stand in for (burn efficiency 100). std::int64_t energy_burn_carbon_pj_per_kfg{}, energy_burn_nitrogen_pj_per_kfg{}, energy_burn_phosphorus_pj_per_kfg{}, energy_burn_other_pj_per_kfg{}; @@ -33,8 +37,24 @@ struct CellularRevampTuning { predation_kill_bubble_per_mille{}; // The spent pool's drip back into the region. std::int64_t spent_drip_interval_ticks{}, spent_drip_bubble_pj{}, spent_drip_bubble_fg{}; + // Mutation offers (Cellular_mutation_plan.md section 3). + std::int64_t mutation_options{}, mutation_floor_ppm{}, mutation_cap_ppm{}; + std::int64_t mutation_score_min{}, mutation_score_max{}; + std::int64_t mutation_max_multiplier_per_mille{}, mutation_min_multiplier_per_mille{}; + std::int64_t mutation_offer_interval_ticks{}; + std::int64_t mutation_min_points{}, mutation_max_points{}, mutation_recipe_min_share{}; + std::int64_t mutation_max_offspring{}, mutation_carbon_for_light_fg{}, + mutation_buds_for_adhesion{}; + // Each catalog mutation's tunables, in catalog order. Optional keys + // `mutation..` override the defaults from its spec. + std::array mutations{}; auto operator<=>(const CellularRevampTuning&) const = default; }; +// A mutation's tunables as the file names them. +inline constexpr std::array cellular_mutation_tuning_fields{ + "enabled", "base_weight", "increase_points", "decrease_points", "primary_step", + "paired_step", "spread_step", "increase_ticks", "decrease_ticks", "cost_e_pj", + "cost_c_fg", "cost_n_fg", "cost_p_fg", "cost_o_fg", "cost_scale_percent"}; [[nodiscard]] std::expected parse_cellular_revamp_tuning(std::string_view text); diff --git a/include/evo/biology/cellular_step.hpp b/include/evo/biology/cellular_step.hpp index 988ef00..53eee29 100644 --- a/include/evo/biology/cellular_step.hpp +++ b/include/evo/biology/cellular_step.hpp @@ -61,6 +61,8 @@ struct CellularStepCandidate { // Rules 13 (ADR-0179): reserve matter burned in place of energy, for the region's spent // pool. Costs paid this way add no heat. accounting::Inventory spent{}; + // Rules 13: a collection limit held matter (or energy) back while food was left. + bool matter_limited{}, energy_limited{}; auto operator<=>(const CellularStepCandidate&) const = default; }; // Rules 12: liquid-relative motion inputs for one life (Cellular_Region_Movement_Plan.md). diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index ccdd3fd..19cce4c 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -74,6 +74,8 @@ inline constexpr std::uint32_t cellular_lives_revamp_rules = 13; rules == cellular_lives_revamp_rules; } inline constexpr std::uint32_t cellular_growth_per_tick = 5; // Per 50 ms; trial rate. +// Rules 13: a bud engulfed within this many ticks of birth reports to its parent (2 minutes). +inline constexpr std::uint64_t cellular_bud_early_ticks = 2'400; // The founder a region of these rules creates. [[nodiscard]] constexpr biology::FounderVersion cellular_founder_version(std::uint32_t rules) noexcept { @@ -136,6 +138,7 @@ struct CellularOwnedLife { std::uint64_t frozen_since{}; std::uint64_t offspring_genome{}; // Format 8; older formats retain zero. biology::CellularMotionState motion{}; // Format 10; older formats retain zero. + CellularRevampLife revamp{}; // Format 11 (rules 13): mutation state. auto operator<=>(const CellularOwnedLife&) const = default; }; struct CellularOwnedCorpse { diff --git a/include/evo/server/lifecycle/cellular_revamp.hpp b/include/evo/server/lifecycle/cellular_revamp.hpp index 284611d..faaacae 100644 --- a/include/evo/server/lifecycle/cellular_revamp.hpp +++ b/include/evo/server/lifecycle/cellular_revamp.hpp @@ -1,13 +1,18 @@ #pragma once +#include "evo/biology/cellular_catalog.hpp" #include "evo/biology/cellular_habitat.hpp" +#include "evo/biology/cellular_motion.hpp" +#include "evo/biology/cellular_offers.hpp" #include "evo/biology/cellular_region_step.hpp" #include "evo/biology/cellular_revamp_tuning.hpp" +#include "evo/biology/cellular_triggers.hpp" #include "evo/biology/development.hpp" #include #include #include +#include // Rules 13 (ADR-0179, Cellular_Revamp_Build_Plan.md): what a cellular owner declares when it // upgrades to owner format 11. Taken from the Git tuning file when the region opens and @@ -26,9 +31,61 @@ struct CellularRevampRules { // Share of reserve matter carried as load, per mille: it slows thrust and turning and makes // thrust costlier, in proportion to the body's mass. Upkeep stays on the body. std::uint32_t reserve_load_per_thousand{}; + // Growth per tick in hundredths of a per mille at growth speed 100 (trial 500: 5 per mille). + std::uint32_t growth_per_tick_centi_mille{500}; + // Mutation offers: the draw, the catalog's bounds and gates, the cadence in active ticks, + // and every catalog mutation's tunables in catalog order. + biology::CellularOfferRules offers{}; + biology::CellularCatalogBounds bounds{}; + std::uint32_t offer_interval_ticks{500}; + std::array mutations{}; auto operator<=>(const CellularRevampRules&) const = default; }; +// A rules-13 offer: the drawn mutations (catalog ids) and their chances, in catalog order. +inline constexpr std::size_t max_cellular_offer_options = 10; +struct CellularRevampOffer { + std::uint64_t event_index{}, offer_tick{}; + std::uint8_t count{}; + std::array ids{}; + std::array chances{}; + auto operator<=>(const CellularRevampOffer&) const = default; +}; +// A rules-13 life's mutation state: affinity, lineage progress, the cadence counter, the pending +// offer (count 0: none), the previous tick's brake (for presses) and the growth carry. +struct CellularRevampLife { + biology::CellularAffinity affinity{}; + biology::CellularLineageProgress progress{}; + std::uint32_t active_ticks{}; + std::uint8_t last_brake{}; + std::uint32_t growth_carry{}; + std::uint64_t events{}; // Offers made so far; the next offer's event index is events + 1. + CellularRevampOffer offer{}; + auto operator<=>(const CellularRevampLife&) const = default; +}; + +// The rules' offer settings as the catalog and offer code take them. +[[nodiscard]] bool cellular_revamp_offer_rules_valid(const CellularRevampRules& rules) noexcept; + +// Draws an offer from `plan`'s eligible mutations at its affinity, or nothing when fewer +// mutations are eligible than the cap can fill. Seeded by world, region, life and event, so a +// retry draws the same offer. +[[nodiscard]] std::optional +cellular_draw_offer(const biology::Genome& plan, const CellularRevampLife& life, + const CellularRevampRules& rules, std::uint64_t world, std::uint64_t region, + std::uint64_t life_id, std::uint64_t tick); + +// What choosing a mutation costs: its amounts times its scale. +[[nodiscard]] accounting::Inventory +cellular_mutation_cost(const biology::CellularMutationTuning& tuning) noexcept; + +// Returns `amount` to the region as bubbles at seeded random spots, one per non-empty channel; +// a habitat at its deposit limit merges each into the existing deposit farthest from `from`. +// False only on identity overflow. +[[nodiscard]] bool cellular_reclaim(biology::CellularHabitatConfig& config, + const accounting::Inventory& amount, std::uint64_t seed, + biology::CellularPosition from, std::uint64_t source); + [[nodiscard]] bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept; // The spent pool's drip for the tick ending at `tick`: on every `drip_interval_ticks`-th tick, // one bubble per non-empty channel of at most the declared size, taken from `spent`, at a diff --git a/src/biology/cellular_region_step.cpp b/src/biology/cellular_region_step.cpp index 76d2fa8..40c135d 100644 --- a/src/biology/cellular_region_step.cpp +++ b/src/biology/cellular_region_step.cpp @@ -272,6 +272,12 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area, cellular_pool_yield_per_thousand / 1000); auto& reserve = channel_of(result.reserve_after, channel); const auto take = std::min({stock, allowance, u64_max - reserve}); + if (stock > take) { + if (channel == 0) + result.energy_limited = true; + else + result.matter_limited = true; + } if (take == 0) continue; stock -= take; diff --git a/src/biology/cellular_revamp_tuning.cpp b/src/biology/cellular_revamp_tuning.cpp index ebed8e8..ad47491 100644 --- a/src/biology/cellular_revamp_tuning.cpp +++ b/src/biology/cellular_revamp_tuning.cpp @@ -1,6 +1,8 @@ #include "evo/biology/cellular_revamp_tuning.hpp" #include +#include +#include namespace evo::biology { namespace { @@ -20,6 +22,8 @@ constexpr std::array fields{ 0, 1'000}, Field{"body.reserve_load_per_mille", &CellularRevampTuning::body_reserve_load_per_mille, 0, 1'000}, + Field{"body.growth_per_tick_centi_mille", + &CellularRevampTuning::body_growth_per_tick_centi_mille, 1, 100'000}, Field{"energy.burn_carbon_pj_per_kfg", &CellularRevampTuning::energy_burn_carbon_pj_per_kfg, 0, rate_limit}, Field{"energy.burn_nitrogen_pj_per_kfg", &CellularRevampTuning::energy_burn_nitrogen_pj_per_kfg, @@ -39,8 +43,134 @@ constexpr std::array fields{ Field{"spent.drip_interval_ticks", &CellularRevampTuning::spent_drip_interval_ticks, 0, 72'000}, Field{"spent.drip_bubble_pj", &CellularRevampTuning::spent_drip_bubble_pj, 0, amount_limit}, Field{"spent.drip_bubble_fg", &CellularRevampTuning::spent_drip_bubble_fg, 0, amount_limit}, + Field{"mutation.options", &CellularRevampTuning::mutation_options, 1, 10}, + Field{"mutation.floor_ppm", &CellularRevampTuning::mutation_floor_ppm, 0, 1'000'000}, + Field{"mutation.cap_ppm", &CellularRevampTuning::mutation_cap_ppm, 1, 1'000'000}, + Field{"mutation.score_min", &CellularRevampTuning::mutation_score_min, -30'000, 0}, + Field{"mutation.score_max", &CellularRevampTuning::mutation_score_max, 0, 30'000}, + Field{"mutation.max_multiplier_per_mille", + &CellularRevampTuning::mutation_max_multiplier_per_mille, 1'000, 100'000}, + Field{"mutation.min_multiplier_per_mille", + &CellularRevampTuning::mutation_min_multiplier_per_mille, 0, 1'000}, + Field{"mutation.offer_interval_ticks", &CellularRevampTuning::mutation_offer_interval_ticks, 1, + 72'000}, + Field{"mutation.min_points", &CellularRevampTuning::mutation_min_points, 1, 1'000}, + Field{"mutation.max_points", &CellularRevampTuning::mutation_max_points, 100, 1'000}, + Field{"mutation.recipe_min_share", &CellularRevampTuning::mutation_recipe_min_share, 1, 250}, + Field{"mutation.max_offspring", &CellularRevampTuning::mutation_max_offspring, 1, 100}, + Field{"mutation.carbon_for_light_fg", &CellularRevampTuning::mutation_carbon_for_light_fg, 0, + amount_limit}, + Field{"mutation.buds_for_adhesion", &CellularRevampTuning::mutation_buds_for_adhesion, 0, + 1'000}, }; +// A per-mutation field's bounds, in cellular_mutation_tuning_fields order. +constexpr std::array, 15> mutation_field_bounds{{ + {0, 1}, + {0, 10'000}, + {-10'000, 10'000}, + {-10'000, 10'000}, + {0, 1'000}, + {0, 1'000}, + {0, 1'000}, + {0, 10'000'000}, + {0, 10'000'000}, + {0, amount_limit}, + {0, amount_limit}, + {0, amount_limit}, + {0, amount_limit}, + {0, amount_limit}, + {0, 100}, +}}; +std::int64_t get_field(const CellularMutationTuning& t, std::size_t field) { + switch (field) { + case 0: + return t.enabled ? 1 : 0; + case 1: + return t.base_weight; + case 2: + return t.increase_points; + case 3: + return t.decrease_points; + case 4: + return t.primary_step; + case 5: + return t.paired_step; + case 6: + return t.spread_step; + case 7: + return t.increase_ticks; + case 8: + return t.decrease_ticks; + case 9: + return static_cast(t.cost.energy.value); + case 14: + return t.cost_scale_percent; + default: + return static_cast(t.cost.matter[field - 10].value); + } +} +void set_field(CellularMutationTuning& t, std::size_t field, std::int64_t value) { + const auto u32 = static_cast(value); + switch (field) { + case 0: + t.enabled = value != 0; + break; + case 1: + t.base_weight = u32; + break; + case 2: + t.increase_points = static_cast(value); + break; + case 3: + t.decrease_points = static_cast(value); + break; + case 4: + t.primary_step = u32; + break; + case 5: + t.paired_step = u32; + break; + case 6: + t.spread_step = u32; + break; + case 7: + t.increase_ticks = u32; + break; + case 8: + t.decrease_ticks = u32; + break; + case 9: + t.cost.energy.value = static_cast(value); + break; + case 14: + t.cost_scale_percent = u32; + break; + default: + t.cost.matter[field - 10].value = static_cast(value); + break; + } +} +// `mutation..`: the catalog index and field index, or nothing. +std::optional> mutation_key(std::string_view key) { + constexpr std::string_view prefix = "mutation."; + if (!key.starts_with(prefix)) + return std::nullopt; + const auto rest = key.substr(prefix.size()); + const auto dot = rest.find('.'); + if (dot == std::string_view::npos) + return std::nullopt; + const auto name = rest.substr(0, dot); + const auto field = rest.substr(dot + 1); + const auto catalog = cellular_catalog(); + const auto spec = std::ranges::find(catalog, name, &CellularMutationSpec::key); + const auto slot = std::ranges::find(cellular_mutation_tuning_fields, field); + if (spec == catalog.end() || slot == cellular_mutation_tuning_fields.end()) + return std::nullopt; + return std::pair{static_cast(spec - catalog.begin()), + static_cast(slot - cellular_mutation_tuning_fields.begin())}; +} + CellularTuningError error(CellularTuningErrorKind kind, std::size_t line, std::string_view key) { return {kind, line, std::string{key}}; } @@ -52,8 +182,28 @@ parse_cellular_revamp_tuning(std::string_view text) { if (!lines) return std::unexpected{lines.error()}; CellularRevampTuning tuning{}; + const auto catalog = cellular_catalog(); + for (std::size_t i = 0; i < catalog.size(); ++i) + tuning.mutations.at(i) = cellular_default_tuning(catalog[i]); std::array seen{}; + std::set> overridden; for (const auto& [line_number, key, value_text] : *lines) { + // Optional per-mutation overrides; an unknown mutation or field is an unknown key. + if (const auto target = mutation_key(key)) { + if (!overridden.insert(*target).second) + return std::unexpected{ + error(CellularTuningErrorKind::duplicate_key, line_number, key)}; + const auto value = parse_tuning_integer(value_text); + if (!value) + return std::unexpected{ + error(CellularTuningErrorKind::invalid_value, line_number, key)}; + const auto [low, high] = mutation_field_bounds.at(target->second); + if (*value < low || *value > high) + return std::unexpected{ + error(CellularTuningErrorKind::out_of_range, line_number, key)}; + set_field(tuning.mutations.at(target->first), target->second, *value); + continue; + } std::size_t index{}; while (index < fields.size() && fields.at(index).key != key) ++index; @@ -77,6 +227,10 @@ parse_cellular_revamp_tuning(std::string_view text) { if (tuning.version != cellular_revamp_tuning_version) return std::unexpected{ error(CellularTuningErrorKind::unsupported_version, 0, "tuning.version")}; + if (tuning.mutation_floor_ppm > tuning.mutation_cap_ppm || + tuning.mutation_min_points >= tuning.mutation_max_points) + return std::unexpected{ + error(CellularTuningErrorKind::inconsistent, 0, "mutation.floor_ppm")}; // A drip needs a bubble size on both kinds of channel. if (tuning.spent_drip_interval_ticks != 0 && (tuning.spent_drip_bubble_pj == 0 || tuning.spent_drip_bubble_fg == 0)) @@ -93,6 +247,17 @@ std::string encode_cellular_revamp_tuning(const CellularRevampTuning& tuning) { text.append(std::to_string(tuning.*field.member)); text.push_back('\n'); } + const auto catalog = cellular_catalog(); + for (std::size_t i = 0; i < catalog.size(); ++i) + for (std::size_t f = 0; f < cellular_mutation_tuning_fields.size(); ++f) { + text.append("mutation."); + text.append(catalog[i].key); + text.push_back('.'); + text.append(cellular_mutation_tuning_fields.at(f)); + text.append(" = "); + text.append(std::to_string(get_field(tuning.mutations.at(i), f))); + text.push_back('\n'); + } return text; } } // namespace evo::biology diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index c7775c5..a5f8304 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -58,7 +58,19 @@ constexpr std::size_t cellular_life_motion_bytes = 20; // energy and matter (16), and the spent pool (40): 120 bytes. The word after the drip interval // is the reserve load share. Later build phases extend this // block before format 11 is deployed. -constexpr std::size_t cellular_lives_v11_header_bytes = cellular_lives_v10_header_bytes + 120; +// Then the growth rate and a reserved zero (8), the offer rules (seven 4-byte fields and a +// reserved zero, 32), the catalog bounds (five 4-byte fields, a reserved zero and the carbon +// gate, 32), the offer interval and a reserved zero (8), and 49 mutation tunables of 80 bytes. +constexpr std::size_t cellular_revamp_mutation_bytes = 80; +constexpr std::size_t cellular_lives_v11_header_bytes = + cellular_lives_v10_header_bytes + 120 + 8 + 32 + 32 + 8 + + biology::cellular_catalog_size * cellular_revamp_mutation_bytes; +// Each format-11 life adds its mutation state: 49 scores and a reserved zero (100), 98 trigger +// states of 24 bytes (2,352), lineage progress and the cadence counter (16), the last brake, +// three zeros and the growth carry (8), the offers made (8), and the pending offer (88). +constexpr std::size_t cellular_trigger_state_bytes = 24; +constexpr std::size_t cellular_life_revamp_bytes = + 100 + 2 * biology::cellular_catalog_size * cellular_trigger_state_bytes + 16 + 8 + 8 + 88; bool valid_motion(const biology::CellularMotionState& m) noexcept { constexpr std::int64_t carry = biology::cellular_velocity_q10_per_um_s * 1'000'000; @@ -180,6 +192,184 @@ bool subtract_inventory(accounting::Inventory& total, const accounting::Inventor return true; } +// Format 11: the revamp rules' offer settings and a life's mutation state. +void write_trigger(Writer& out, const biology::CellularTriggerState& s) { + out.put(s.first); + out.put(s.second); + out.put(s.ticks, 4); + out.put(s.heading, 2); + out.put(s.running, 1); + out.put(0, 1); +} +std::optional read_trigger(Reader& in) { + biology::CellularTriggerState s{}; + s.first = in.get(); + s.second = in.get(); + s.ticks = static_cast(in.get(4)); + s.heading = static_cast(in.get(2)); + const auto running = in.get(1); + if (running > 1 || in.get(1) != 0) + return std::nullopt; + s.running = static_cast(running); + return s; +} +void write_revamp_offers(Writer& out, const CellularRevampRules& r) { + out.put(r.growth_per_tick_centi_mille, 4); + out.put(0, 4); + const auto& o = r.offers; + for (const auto value : {o.options, o.floor_ppm, o.cap_ppm}) + out.put(value, 4); + out.put(static_cast(o.score_min), 4); + out.put(static_cast(o.score_max), 4); + out.put(o.max_multiplier_per_mille, 4); + out.put(o.min_multiplier_per_mille, 4); + out.put(0, 4); + const auto& b = r.bounds; + for (const auto value : + {b.min_points, b.max_points, b.recipe_min_share, b.max_litter, b.buds_for_adhesion}) + out.put(value, 4); + out.put(0, 4); + out.put(b.carbon_for_light); + out.put(r.offer_interval_ticks, 4); + out.put(0, 4); + for (const auto& m : r.mutations) { + out.put(m.enabled ? 1 : 0, 1); + out.zeros(3); + out.put(m.base_weight, 4); + out.put(static_cast(m.increase_points), 4); + out.put(static_cast(m.decrease_points), 4); + for (const auto value : {m.primary_step, m.paired_step, m.spread_step, m.increase_ticks, + m.decrease_ticks, m.cost_scale_percent}) + out.put(value, 4); + out.inventory(m.cost); + } +} +bool read_revamp_offers(Reader& in, CellularRevampRules& r) { + const auto u32 = [&in] { return static_cast(in.get(4)); }; + const auto i32 = [&in] { + return static_cast(static_cast(in.get(4))); + }; + bool zero = true; + r.growth_per_tick_centi_mille = u32(); + zero = zero && in.get(4) == 0; + auto& o = r.offers; + o.options = u32(); + o.floor_ppm = u32(); + o.cap_ppm = u32(); + o.score_min = i32(); + o.score_max = i32(); + o.max_multiplier_per_mille = u32(); + o.min_multiplier_per_mille = u32(); + zero = zero && in.get(4) == 0; + auto& b = r.bounds; + b.min_points = u32(); + b.max_points = u32(); + b.recipe_min_share = u32(); + b.max_litter = u32(); + b.buds_for_adhesion = u32(); + zero = zero && in.get(4) == 0; + b.carbon_for_light = in.get(); + r.offer_interval_ticks = u32(); + zero = zero && in.get(4) == 0; + for (auto& m : r.mutations) { + const auto enabled = in.get(1); + zero = zero && enabled <= 1 && in.get(3) == 0; + m.enabled = enabled == 1; + m.base_weight = u32(); + m.increase_points = i32(); + m.decrease_points = i32(); + m.primary_step = u32(); + m.paired_step = u32(); + m.spread_step = u32(); + m.increase_ticks = u32(); + m.decrease_ticks = u32(); + m.cost_scale_percent = u32(); + m.cost = in.inventory(); + } + return zero; +} +void write_revamp_life(Writer& out, const CellularRevampLife& life) { + for (const auto score : life.affinity.score) + out.put(static_cast(score), 2); + out.put(0, 2); + for (const auto& s : life.affinity.increase) + write_trigger(out, s); + for (const auto& s : life.affinity.decrease) + write_trigger(out, s); + out.put(life.progress.carbon_burned); + out.put(life.progress.buds, 4); + out.put(life.active_ticks, 4); + out.put(life.last_brake, 1); + out.zeros(3); + out.put(life.growth_carry, 4); + out.put(life.events); + const auto& offer = life.offer; + out.put(offer.event_index); + out.put(offer.offer_tick); + out.put(offer.count, 1); + out.zeros(7); + for (const auto id : offer.ids) + out.put(id, 2); + for (const auto chance : offer.chances) + out.put(chance, 4); + out.zeros(4); +} +std::optional read_revamp_life(Reader& in) { + CellularRevampLife life{}; + for (auto& score : life.affinity.score) + score = static_cast(static_cast(in.get(2))); + bool zero = in.get(2) == 0; + for (auto& s : life.affinity.increase) { + const auto read = read_trigger(in); + if (!read) + return std::nullopt; + s = *read; + } + for (auto& s : life.affinity.decrease) { + const auto read = read_trigger(in); + if (!read) + return std::nullopt; + s = *read; + } + life.progress.carbon_burned = in.get(); + life.progress.buds = static_cast(in.get(4)); + life.active_ticks = static_cast(in.get(4)); + const auto brake = in.get(1); + zero = zero && brake <= 1 && in.get(3) == 0; + life.last_brake = static_cast(brake); + life.growth_carry = static_cast(in.get(4)); + life.events = in.get(); + auto& offer = life.offer; + offer.event_index = in.get(); + offer.offer_tick = in.get(); + const auto count = in.get(1); + zero = zero && in.get(7) == 0 && count <= max_cellular_offer_options; + offer.count = static_cast(count); + for (auto& id : offer.ids) + id = static_cast(in.get(2)); + for (auto& chance : offer.chances) + chance = static_cast(in.get(4)); + zero = zero && in.get(4) == 0; + // A pending offer names catalog mutations once each, with chances, and nothing after them; + // no offer leaves every slot zero. + for (std::size_t k = 0; k < max_cellular_offer_options; ++k) { + const bool used = k < offer.count; + if (used != (offer.ids.at(k) != 0) || + (used && + (biology::cellular_mutation(offer.ids.at(k)) == nullptr || offer.chances.at(k) == 0 || + offer.chances.at(k) > biology::cellular_chance_whole)) || + (!used && offer.chances.at(k) != 0)) + return std::nullopt; + for (std::size_t j = 0; j < k && used; ++j) + if (offer.ids.at(j) == offer.ids.at(k)) + return std::nullopt; + } + if (!zero || (offer.count == 0 && (offer.event_index != 0 || offer.offer_tick != 0)) || + (offer.count != 0 && offer.event_index != life.events) || life.growth_carry >= 100) + return std::nullopt; + return life; +} + std::expected budget_for(const biology::LineageArchive& archive, const CellularOwnedLife& life, std::uint32_t temperature, @@ -1050,13 +1240,15 @@ std::vector CellularLives::snapshot() const { // Format 11 is format 10 with the revamp rules. const bool revamp = state_->format_version == cellular_lives_revamp_format; const bool liquid = revamp || state_->format_version == cellular_lives_liquid_format; - const auto life_bytes = liquid ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes - : inheritance ? cellular_life_v6_bytes + 8 - : state_->format_version == cellular_lives_legacy_format - ? cellular_life_v1_bytes - : presence ? cellular_life_v6_bytes - : parents ? cellular_life_v5_bytes - : cellular_life_v2_bytes; + const auto life_bytes = + revamp + ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + cellular_life_revamp_bytes + : liquid ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + : inheritance ? cellular_life_v6_bytes + 8 + : state_->format_version == cellular_lives_legacy_format ? cellular_life_v1_bytes + : presence ? cellular_life_v6_bytes + : parents ? cellular_life_v5_bytes + : cellular_life_v2_bytes; const bool causes = state_->format_version >= cellular_lives_engulf_format; const auto corpse_bytes = inheritance ? cellular_corpse_v5_bytes + 8 : parents ? cellular_corpse_v5_bytes @@ -1176,6 +1368,7 @@ std::vector CellularLives::snapshot() const { out.put(r.drip_bubble_pj); out.put(r.drip_bubble_fg); out.inventory(state_->spent); + write_revamp_offers(out, r); } for (const auto site : state_->nursery_config.sites) out.site(site); @@ -1245,6 +1438,8 @@ std::vector CellularLives::snapshot() const { out.put(static_cast(life.motion.remainder_x), 4); out.put(static_cast(life.motion.remainder_y), 4); } + if (revamp) + write_revamp_life(out, life.revamp); } for (const auto& corpse : state_->corpses) { out.put(corpse.life_id); @@ -1700,15 +1895,18 @@ CellularLives::restore(std::span bytes, std::uint64_t world, revamp.drip_bubble_pj = in.get(); revamp.drip_bubble_fg = in.get(); spent = in.inventory(); - if (reserved != 0 || !cellular_revamp_valid(revamp)) + if (!read_revamp_offers(in, revamp) || reserved != 0 || !cellular_revamp_valid(revamp)) return std::unexpected{CellularLivesError::format}; } - const auto life_bytes = liquid_version ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes - : inheritance_version ? cellular_life_v6_bytes + 8 - : legacy ? cellular_life_v1_bytes - : presence_version ? cellular_life_v6_bytes - : bud_version ? cellular_life_v5_bytes - : cellular_life_v2_bytes; + const auto life_bytes = + revamp_version + ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + cellular_life_revamp_bytes + : liquid_version ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + : inheritance_version ? cellular_life_v6_bytes + 8 + : legacy ? cellular_life_v1_bytes + : presence_version ? cellular_life_v6_bytes + : bud_version ? cellular_life_v5_bytes + : cellular_life_v2_bytes; const auto corpse_bytes = inheritance_version ? cellular_corpse_v5_bytes + 8 : bud_version ? cellular_corpse_v5_bytes : engulf_version ? cellular_corpse_v4_bytes @@ -1820,6 +2018,12 @@ CellularLives::restore(std::span bytes, std::uint64_t world, if (padding != 0 || !valid_motion(life.motion)) return std::unexpected{CellularLivesError::noncanonical}; } + if (revamp_version) { + const auto state = read_revamp_life(in); + if (!state) + return std::unexpected{CellularLivesError::noncanonical}; + life.revamp = *state; + } lives.push_back(life); } @@ -2014,6 +2218,21 @@ CellularLives::advance_tick_with_mutations(std::span i return std::unexpected{CellularLivesError::mutation}; continue; } + if (revamp_rules) { + // Rules 13: a choice names the life's own pending offer and one of its mutations. + const auto& pending = life->revamp.offer; + const auto ids = std::span{pending.ids}.first(pending.count); + if (pending.count == 0 || pending.event_index != selection.event_index || + pending.offer_tick != selection.offer_tick || + (selection.operator_id != 0 && + std::ranges::find(ids, selection.operator_id) == ids.end()) || + state_->archive.find(selection.successor_id)) + return std::unexpected{CellularLivesError::mutation}; + for (std::size_t j = 0; j < i; ++j) + if (selections[j].successor_id == selection.successor_id) + return std::unexpected{CellularLivesError::identity}; + continue; + } if (life->mutation.event_index != selection.event_index || life->mutation.offer_tick != selection.offer_tick) return std::unexpected{CellularLivesError::mutation}; @@ -2118,6 +2337,17 @@ CellularLives::advance_tick_with_mutations(std::span i if (!add_inventory(next_spent, proposal->spent)) return std::unexpected{CellularLivesError::overflow}; auto habitat_config = state_->habitat->config(); + // Rules 13: each owned life's activity this tick, gathered from every phase below and + // applied to its affinity at the end. Paid mutation costs wait to be reclaimed. + std::vector> activity; + const auto activity_of = [&activity](std::uint64_t life_id) -> biology::CellularActivity& { + const auto found = std::ranges::find( + activity, life_id, &std::pair::first); + if (found != activity.end()) + return found->second; + return activity.emplace_back(life_id, biology::CellularActivity{}).second; + }; + std::vector> reclaims; for (const auto& result : proposal->lives) { const auto found = std::ranges::lower_bound( next_lives, result.life_id, {}, [](const auto& life) { return life.identity.life; }); @@ -2129,9 +2359,80 @@ CellularLives::advance_tick_with_mutations(std::span i found->motion = result.candidate.motion; if (!add_inventory(next_heat, result.candidate.heat_after)) return std::unexpected{CellularLivesError::overflow}; + if (revamp_rules && found->account != LifeAccount{}) { + using S = biology::CellularSignal; + const auto& c = result.candidate; + auto& a = activity_of(result.life_id); + const bool thrust = c.movement_status == biology::CellularMovementStatus::moved || + c.movement_status == biology::CellularMovementStatus::blocked; + a[S::thrust] = thrust ? 1 : 0; + a[S::drifting] = thrust ? 0 : 1; + const auto request = + std::ranges::lower_bound(ordered, result.life_id, {}, &CellularLifeIntent::life_id); + const bool brake = request != ordered.end() && request->life_id == result.life_id && + request->intent.brake; + a[S::brake_press] = brake && found->revamp.last_brake == 0 ? 1 : 0; + found->revamp.last_brake = brake ? 1 : 0; + const auto acquired = c.intake ? c.intake->transfer.acquired : accounting::Inventory{}; + std::uint64_t collected{}, burned{}; + for (const auto& channel : acquired.matter) + collected += channel.value; + for (const auto& channel : c.spent.matter) + burned += channel.value; + a[S::fed] = collected != 0 || acquired.energy.value != 0 ? 1 : 0; + a[S::intake_limited] = c.matter_limited ? 1 : 0; + a[S::energy_limited] = c.energy_limited ? 1 : 0; + a[S::energy_collected] = acquired.energy.value; + a[S::collected_carbon] = acquired.matter[0].value; + a[S::collected_nitrogen] = acquired.matter[1].value; + a[S::collected_phosphorus] = acquired.matter[2].value; + a[S::collected_other] = acquired.matter[3].value; + a[S::collected_matter] = collected; + a[S::burned_carbon] = c.spent.matter[0].value; + a[S::burned_nitrogen] = c.spent.matter[1].value; + a[S::burned_phosphorus] = c.spent.matter[2].value; + a[S::burned_other] = c.spent.matter[3].value; + a[S::burned_matter] = burned; + a[S::burned_not_carbon] = burned - c.spent.matter[0].value; + a[S::energy_upkeep] = c.maintenance_cost.value; + a[S::energy_movement] = c.movement_cost.value; + a[S::energy_spent] = c.maintenance_cost.value + c.movement_cost.value; + const bool asked = request != ordered.end() && request->life_id == result.life_id && + request->intent.engulf; + a[S::engulf_attempt] = asked ? 1 : 0; + a[S::engulf_success] = result.engulf == biology::CellularEngulfStatus::engulfed ? 1 : 0; + const bool too_large = result.engulf == biology::CellularEngulfStatus::prey_too_large; + a[S::engulf_too_large] = too_large ? 1 : 0; + a[S::engulf_too_large_or_membrane] = + too_large || result.engulf == biology::CellularEngulfStatus::membrane_too_thick ? 1 + : 0; + a.heading = c.motion.heading; + found->revamp.progress.carbon_burned += c.spent.matter[0].value; + // Touching a cell over 1.5 times its own mass. + const auto own = std::ranges::lower_bound(inputs, result.life_id, {}, + &biology::CellularLifeStepInput::life_id); + if (own != inputs.end() && own->life_id == result.life_id) + for (const auto& other : proposal->lives) { + if (other.life_id == result.life_id) + continue; + const auto input = std::ranges::lower_bound( + inputs, other.life_id, {}, &biology::CellularLifeStepInput::life_id); + if (input == inputs.end() || input->life_id != other.life_id || + input->budget.phenotype.total_mass * 2 <= + own->budget.phenotype.total_mass * 3) + continue; + if (biology::cellular_footprints_contact(c.position, own->extent_um, + other.candidate.position, + input->extent_um)) { + a[S::larger_contact] = 1; + break; + } + } + } // Only owned lives earn mutation offers; wildlife never mutates in M11 (ADR-0098). + // Rules 13 earn them from active play instead (below). if (state_->format_version >= cellular_lives_format && result.candidate.intake && - found->account != LifeAccount{}) { + found->account != LifeAccount{} && !revamp_rules) { const auto acquired = result.candidate.intake->transfer.acquired.energy.value; if (acquired > std::numeric_limits::max() - found->mutation.fed_energy_credit_pj) @@ -2188,6 +2489,10 @@ CellularLives::advance_tick_with_mutations(std::span i state_->revamp.body); if (!corpse_budget) return std::unexpected{corpse_budget.error()}; + if (revamp_rules && dead.cause == biology::CellularDeathCause::engulfed && + found->parent_life != 0 && + proposal->end_tick - found->identity.born.value <= cellular_bud_early_ticks) + activity_of(found->parent_life)[biology::CellularSignal::bud_lost_early] += 1; next_corpses.push_back( {found->identity.life, found->identity.organism, found->source, proposal->end_tick, dead.position, found->growth, corpse_budget->phenotype.extent, dead.inventory, @@ -2206,6 +2511,72 @@ CellularLives::advance_tick_with_mutations(std::span i {selection.life_id, selection.successor_id, CellularMutationResult::life_died}); continue; } + if (revamp_rules) { + auto& pending = found->revamp.offer; + const auto plan = next_archive.find(cellular_offspring_genome(*found)); + const auto expressed = next_archive.find(found->identity.genome); + if (pending.count == 0 || !plan || !expressed) + return std::unexpected{CellularLivesError::mutation}; + const auto* spec = biology::cellular_mutation(selection.operator_id); + const auto draft = spec == nullptr + ? std::nullopt + : biology::apply_cellular_mutation( + *plan, *spec, state_->revamp.mutations.at(spec->id - 1u), + state_->revamp.bounds, found->revamp.progress, + selection.successor_id, selection.successor_id); + if (selection.operator_id == 0 || !draft) { + // A decline, or a mutation no longer available, consumes the offer. + pending = {}; + mutation_results.push_back( + {selection.life_id, selection.successor_id, CellularMutationResult::declined}); + continue; + } + // The cost comes from the reserve: matter channels directly, energy with matter + // standing in (except excluded channels). Unaffordable: the offer stays. + const auto cost = cellular_mutation_cost(state_->revamp.mutations.at(spec->id - 1u)); + auto reserve = found->reserve; + bool affordable = true; + for (std::size_t c = 0; c < reserve.matter.size(); ++c) { + if (reserve.matter[c].value < cost.matter[c].value) + affordable = false; + else + reserve.matter[c].value -= cost.matter[c].value; + } + const auto request = std::ranges::lower_bound(ordered, selection.life_id, {}, + &CellularLifeIntent::life_id); + const auto exclude = request != ordered.end() && request->life_id == selection.life_id + ? request->intent.exclude + : std::uint8_t{0}; + const auto& traits = expressed->cellular_traits(); + const auto burn = biology::cellular_burn( + state_->revamp.burn_pj_per_kfg, + traits ? traits->burn : std::array{100, 100, 100, 100}, exclude); + const auto payment = + affordable ? biology::cellular_pay(reserve, cost.energy.value, burn, false) + : std::nullopt; + if (!payment) { + mutation_results.push_back({selection.life_id, selection.successor_id, + CellularMutationResult::insufficient_funding}); + continue; + } + const auto successor = biology::Genome::create(*draft); + if (!successor || next_offspring_revisions.size() >= biology::max_archived_genomes || + !next_archive.admit(*successor)) + return std::unexpected{CellularLivesError::archive}; + next_offspring_revisions.push_back({selection.life_id, found->offspring_genome, + selection.successor_id, proposal->end_tick}); + found->offspring_genome = selection.successor_id; + found->reserve = reserve; + if (!add_inventory(next_spent, payment->spent)) + return std::unexpected{CellularLivesError::overflow}; + auto returned = cost; + returned.energy.value = payment->energy; + reclaims.emplace_back(returned, found->position); + pending = {}; + mutation_results.push_back({selection.life_id, selection.successor_id, + CellularMutationResult::offspring_plan_applied}); + continue; + } const auto parent = next_archive.find(cellular_offspring_genome(*found)); if (!parent || !found->mutation.offer.has_value()) return std::unexpected{CellularLivesError::mutation}; @@ -2317,8 +2688,28 @@ CellularLives::advance_tick_with_mutations(std::span i budget_for(next_archive, *parent, temperature, state_->revamp.body); if (!genome || !expressed || !parent_budget) return std::unexpected{CellularLivesError::archive}; + // Rules 13: a bud made with the reserve covering twice its cost. + bool surplus = false; + if (revamp_rules && !twin) { + const auto cost = biology::offspring_cost(*expressed, *genome, temperature); + surplus = + cost.has_value() && parent->reserve.energy.value / 2 >= cost->energy.value; + for (std::size_t c = 0; surplus && c < cost->matter.size(); ++c) + surplus = parent->reserve.matter[c].value / 2 >= cost->matter[c].value; + } const auto transition = biology::fund_offspring( *expressed, *genome, parent->growth, parent->reserve, temperature, twins ? 2U : 1U); + if (revamp_rules && !twin && parent->account != LifeAccount{}) { + using S = biology::CellularSignal; + auto& a = activity_of(request.life_id); + if (transition) { + a[S::bud_done] += 1; + a[S::bud_with_surplus] += surplus ? 1 : 0; + parent->revamp.progress.buds += 1; + } else if (transition.error() == biology::BuddingError::insufficient_funding) { + a[S::bud_refused] += 1; + } + } if (!transition) { if (transition.error() == biology::BuddingError::development) return std::unexpected{CellularLivesError::biology}; @@ -2361,6 +2752,11 @@ CellularLives::advance_tick_with_mutations(std::span i bud.parent_life = parent->identity.life; if (inheritance_rules) bud.offspring_genome = genome->id(); + if (revamp_rules) { + // Offspring start with the parent's scores and lineage progress. + bud.revamp.affinity.score = parent->revamp.affinity.score; + bud.revamp.progress = parent->revamp.progress; + } // Foreign residents can have a higher origin-region namespace. Keep // the sequence sorted even before the next parent's lookup/twin. const auto slot = std::ranges::lower_bound( @@ -2433,15 +2829,48 @@ CellularLives::advance_tick_with_mutations(std::span i const auto genome = next_archive.find(life.identity.genome); if (!genome) return std::unexpected(CellularLivesError::archive); + // Rules 13: growth speed scales the per-tick step; the fraction carries over. + auto step = cellular_growth_per_tick; + const auto& traits = genome->cellular_traits(); + if (revamp_rules && traits) { + const auto centi = + life.revamp.growth_carry + + state_->revamp.growth_per_tick_centi_mille * traits->growth_speed / 100; + step = centi / 100; + life.revamp.growth_carry = centi % 100; + if (step == 0) + continue; + } const auto budget = biology::metabolic_budget( *genome, life.growth, - {state_->config.ambient_temperature_millikelvin, life.reserve}, - cellular_growth_per_tick); + {state_->config.ambient_temperature_millikelvin, life.reserve}, step, + state_->revamp.body); if (!budget || budget->body != life.body) return std::unexpected(CellularLivesError::biology); const auto& move = budget->construction; - if (move.after == life.growth) + if (move.after == life.growth) { + if (revamp_rules && life.account != LifeAccount{}) { + // Which channels held the step back: what an ample reserve's step needs. + accounting::Inventory ample{{1ULL << 50U}, {}}; + for (auto& channel : ample.matter) + channel.value = 1ULL << 50U; + const auto full = biology::metabolic_budget( + *genome, life.growth, + {state_->config.ambient_temperature_millikelvin, ample}, step, + state_->revamp.body); + if (full) { + using S = biology::CellularSignal; + constexpr std::array blocked{S::blocked_carbon, S::blocked_nitrogen, + S::blocked_phosphorus, S::blocked_other}; + auto& a = activity_of(life.identity.life); + for (std::size_t c = 0; c < blocked.size(); ++c) + if (full->construction.intake.matter[c].value > + life.reserve.matter[c].value) + a[blocked.at(c)] = 1; + } + } continue; + } const auto grown = biology::metabolic_budget( *genome, move.after, {state_->config.ambient_temperature_millikelvin, {}}); if (!grown) @@ -2477,6 +2906,44 @@ CellularLives::advance_tick_with_mutations(std::span i life.body = grown->body; } } + // Rules 13: each owned, active life's activity moves its affinity; active play earns offers. + if (revamp_rules) { + using S = biology::CellularSignal; + for (auto& life : next_lives) { + const auto request = std::ranges::lower_bound(ordered, life.identity.life, {}, + &CellularLifeIntent::life_id); + if (life.account == LifeAccount{} || request == ordered.end() || + request->life_id != life.identity.life || request->intent.frozen || + life.presence != CellularPresence::active) + continue; // Wildlife, newborns, and frozen or absent cells. + auto a = activity_of(life.identity.life); + std::uint64_t reserve{}, body{}; + for (std::size_t c = 0; c < life.body.matter.size(); ++c) { + reserve += life.reserve.matter[c].value; + body += life.body.matter[c].value; + } + a[S::reserve_over_body] = reserve > body ? 1 : 0; + a[S::regrowing] = life.growth.realized_per_thousand < 1000 ? 1 : 0; + a[S::fully_grown] = life.growth.realized_per_thousand == 1000 ? 1 : 0; + biology::cellular_affinity_tick( + life.revamp.affinity, a, state_->revamp.mutations, + {state_->revamp.offers.score_min, state_->revamp.offers.score_max}); + if (life.revamp.offer.count != 0 || + ++life.revamp.active_ticks < state_->revamp.offer_interval_ticks) + continue; + life.revamp.active_ticks = 0; + const auto plan = next_archive.find(cellular_offspring_genome(life)); + if (!plan) + return std::unexpected{CellularLivesError::archive}; + const auto offer = + cellular_draw_offer(*plan, life.revamp, state_->revamp, state_->world, + state_->region, life.identity.life, proposal->end_tick); + if (offer) { + life.revamp.offer = *offer; + life.revamp.events = offer->event_index; + } + } + } std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism); if (proposal->heat_released.value > std::numeric_limits::max() - next_heat.energy.value) @@ -2512,6 +2979,13 @@ CellularLives::advance_tick_with_mutations(std::span i !cellular_drip_spent(habitat_config, next_spent, state_->revamp, state_->world, state_->region, proposal->end_tick, state_->nursery_config.source)) return std::unexpected{CellularLivesError::overflow}; + // Rules 13: paid mutation costs return as bubbles at seeded random spots. + for (std::size_t k = 0; k < reclaims.size(); ++k) + if (!cellular_reclaim(habitat_config, reclaims[k].first, + state_->world * 0x9e3779b97f4a7c15ULL ^ + proposal->end_tick * 0x94d049bbULL ^ k, + reclaims[k].second, state_->nursery_config.source)) + return std::unexpected{CellularLivesError::overflow}; if (deposits) std::erase_if(habitat_config.patches, [](const biology::CellularPatch& patch) { return patch.stock == accounting::Inventory{}; diff --git a/src/server/lifecycle/cellular_revamp.cpp b/src/server/lifecycle/cellular_revamp.cpp index 2cebd5f..48077c9 100644 --- a/src/server/lifecycle/cellular_revamp.cpp +++ b/src/server/lifecycle/cellular_revamp.cpp @@ -4,8 +4,35 @@ #include #include +#include namespace evo::server { +bool cellular_revamp_offer_rules_valid(const CellularRevampRules& rules) noexcept { + const auto& o = rules.offers; + const auto& b = rules.bounds; + constexpr std::uint64_t most = 1'000'000'000'000'000ULL; + if (o.options == 0 || o.options > max_cellular_offer_options || o.floor_ppm > o.cap_ppm || + o.cap_ppm > biology::cellular_chance_whole || o.score_min > 0 || o.score_max < 0 || + o.score_min < -30'000 || o.score_max > 30'000 || o.max_multiplier_per_mille > 100'000 || + o.min_multiplier_per_mille > 1'000 || b.min_points == 0 || b.min_points >= b.max_points || + b.max_points > biology::max_trait_points || b.recipe_min_share == 0 || + b.recipe_min_share > 250 || b.max_litter > biology::max_litter || + rules.offer_interval_ticks == 0 || rules.offer_interval_ticks > 72'000) + return false; + for (const auto& m : rules.mutations) { + if (m.base_weight > 10'000 || m.increase_points < -10'000 || m.increase_points > 10'000 || + m.decrease_points < -10'000 || m.decrease_points > 10'000 || m.primary_step > 1'000 || + m.paired_step > 1'000 || m.spread_step > 1'000 || m.cost_scale_percent > 100 || + m.increase_ticks > 10'000'000 || m.decrease_ticks > 10'000'000 || + m.cost.energy.value > most) + return false; + for (const auto& channel : m.cost.matter) + if (channel.value > most) + return false; + } + return true; +} + bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept { constexpr std::uint64_t most = 1'000'000'000'000'000ULL; const auto& step = rules.step; @@ -19,7 +46,8 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept { rules.drip_bubble_pj <= most && rules.drip_bubble_fg <= most && (rules.drip_interval_ticks == 0 || (rules.drip_bubble_pj != 0 && rules.drip_bubble_fg != 0)) && - rules.reserve_load_per_thousand <= 1'000; + rules.reserve_load_per_thousand <= 1'000 && + rules.growth_per_tick_centi_mille <= 100'000 && cellular_revamp_offer_rules_valid(rules); } biology::CellularHandling cellular_loaded_handling(const biology::CellularHandling& handling, @@ -87,6 +115,117 @@ bool cellular_drip_spent(biology::CellularHabitatConfig& config, accounting::Inv return true; } +std::optional cellular_draw_offer(const biology::Genome& plan, + const CellularRevampLife& life, + const CellularRevampRules& rules, + std::uint64_t world, std::uint64_t region, + std::uint64_t life_id, std::uint64_t tick) { + const auto catalog = biology::cellular_catalog(); + std::vector eligible; + std::vector weights; + for (std::size_t i = 0; i < catalog.size(); ++i) { + const auto& tuning = rules.mutations.at(i); + // A dry run with placeholder identities decides eligibility. + if (!biology::apply_cellular_mutation(plan, catalog[i], tuning, rules.bounds, life.progress, + plan.id() + 1, 1)) + continue; + eligible.push_back(catalog[i].id); + weights.push_back(biology::cellular_offer_weight(tuning.base_weight, + life.affinity.score.at(i), rules.offers)); + } + const auto chances = biology::cellular_offer_chances(weights, rules.offers); + if (!chances) + return std::nullopt; + const auto event = life.events + 1; + Random random{world * 0x9e3779b97f4a7c15ULL ^ region * 0xc2b2ae3d27d4eb4fULL ^ + life_id * 0x165667b19e3779f9ULL ^ event}; + std::uint64_t draw = random.next(); + constexpr auto whole = std::uint64_t{biology::cellular_chance_whole}; + while (draw >= std::numeric_limits::max() / whole * whole) + draw = random.next(); // Exactly uniform below one whole. + const auto picked = biology::cellular_systematic_draw(*chances, rules.offers.options, + static_cast(draw % whole)); + if (picked.size() != rules.offers.options) + return std::nullopt; + CellularRevampOffer offer{}; + offer.event_index = event; + offer.offer_tick = tick; + offer.count = static_cast(picked.size()); + for (std::size_t k = 0; k < picked.size(); ++k) { + offer.ids.at(k) = eligible.at(picked[k]); + offer.chances.at(k) = chances->at(picked[k]); + } + return offer; +} + +accounting::Inventory cellular_mutation_cost(const biology::CellularMutationTuning& t) noexcept { + const auto scaled = [&](std::uint64_t amount) { + return amount / 100 * t.cost_scale_percent + amount % 100 * t.cost_scale_percent / 100; + }; + accounting::Inventory cost{}; + cost.energy.value = scaled(t.cost.energy.value); + for (std::size_t c = 0; c < cost.matter.size(); ++c) + cost.matter[c].value = scaled(t.cost.matter[c].value); + return cost; +} + +bool cellular_reclaim(biology::CellularHabitatConfig& config, const accounting::Inventory& amount, + std::uint64_t seed, biology::CellularPosition from, std::uint64_t source) { + Random random{seed}; + const auto by_address = [](const biology::CellularPatch& patch) { return patch.address; }; + for (std::size_t channel = 0; channel < 5; ++channel) { + const auto value = channel == 0 ? amount.energy.value : amount.matter[channel - 1].value; + const auto x = random.next(); + const auto y = random.next(); + if (value == 0) + continue; + if (config.patches.size() >= biology::max_cellular_liquid_deposits) { + // Full: the deposit farthest from the paying cell (lowest address on a tie). + const auto distance = [&](const biology::CellularPatch& patch) { + const auto dx = static_cast(patch.address.x_um) - + static_cast(from.x_um); + const auto dy = static_cast(patch.address.y_um) - + static_cast(from.y_um); + return static_cast(dx * dx) + static_cast(dy * dy); + }; + auto farthest = config.patches.begin(); + for (auto it = config.patches.begin(); it != config.patches.end(); ++it) + if (distance(*it) > distance(*farthest)) + farthest = it; + if (farthest == config.patches.end()) + return false; + auto& target = channel == 0 ? farthest->stock.energy.value + : farthest->stock.matter[channel - 1].value; + if (value > std::numeric_limits::max() - target) + return false; + target += value; + continue; + } + biology::CellularPatchAddress address{static_cast(x % config.width_um), + static_cast(y % config.height_um)}; + auto at = std::ranges::lower_bound(config.patches, address, {}, by_address); + while (at != config.patches.end() && at->address == address) { + address.x_um = address.x_um + 1 < config.width_um ? address.x_um + 1 : 0; + at = std::ranges::lower_bound(config.patches, address, {}, by_address); + } + if (config.next_deposit == std::numeric_limits::max()) + return false; + biology::CellularPatch bubble{address, + source, + {}, + config.next_deposit++, + biology::cellular_mote_radius_um, + biology::CellularDepositKind::mote}; + bubble.merged = 1; + if (channel == 0) + bubble.stock.energy.value = value; + else + bubble.stock.matter[channel - 1].value = value; + config.patches.insert(at, bubble); + } + return true; +} + CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t) { const auto u32 = [](std::int64_t value) { return static_cast(value); }; const auto u64 = [](std::int64_t value) { return static_cast(value); }; @@ -103,6 +242,22 @@ CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t .drip_interval_ticks = u32(t.spent_drip_interval_ticks), .drip_bubble_pj = u64(t.spent_drip_bubble_pj), .drip_bubble_fg = u64(t.spent_drip_bubble_fg), - .reserve_load_per_thousand = u32(t.body_reserve_load_per_mille)}; + .reserve_load_per_thousand = u32(t.body_reserve_load_per_mille), + .growth_per_tick_centi_mille = u32(t.body_growth_per_tick_centi_mille), + .offers = {.options = u32(t.mutation_options), + .floor_ppm = u32(t.mutation_floor_ppm), + .cap_ppm = u32(t.mutation_cap_ppm), + .score_min = static_cast(t.mutation_score_min), + .score_max = static_cast(t.mutation_score_max), + .max_multiplier_per_mille = u32(t.mutation_max_multiplier_per_mille), + .min_multiplier_per_mille = u32(t.mutation_min_multiplier_per_mille)}, + .bounds = {.min_points = u32(t.mutation_min_points), + .max_points = u32(t.mutation_max_points), + .recipe_min_share = u32(t.mutation_recipe_min_share), + .max_litter = (u32(t.mutation_max_offspring) - 1) * 100, + .carbon_for_light = u64(t.mutation_carbon_for_light_fg), + .buds_for_adhesion = u32(t.mutation_buds_for_adhesion)}, + .offer_interval_ticks = u32(t.mutation_offer_interval_ticks), + .mutations = t.mutations}; } } // namespace evo::server diff --git a/tests/cellular_revamp_owner_tests.cpp b/tests/cellular_revamp_owner_tests.cpp index 1933a94..d704355 100644 --- a/tests/cellular_revamp_owner_tests.cpp +++ b/tests/cellular_revamp_owner_tests.cpp @@ -240,6 +240,131 @@ void a_long_run_keeps_closure_and_restores() { "format 11 did not restore the rules and spent pool exactly"); } +// Rules 13 offers: active play earns them, behaviour moves affinity, and a choice edits the +// plan (never the expressed body), pays and reclaims its cost, or keeps the offer when +// unaffordable; a decline clears it; a pending offer restores exactly. +const CellularOwnedLife& life_of(const CellularLives& state, std::uint64_t id) { + const auto found = std::ranges::find( + state.lives(), id, [](const CellularOwnedLife& l) { return l.identity.life; }); + require(found != state.lives().end(), "life missing"); + return *found; +} +Owner offering_region(std::uint64_t cost_pj) { + auto rules = revamp(); + rules.offer_interval_ticks = 40; + for (auto& m : rules.mutations) { + m.cost.energy.value = cost_pj; + m.cost_scale_percent = 100; + } + auto fresh = opening(7, true, 2, false); + checked(fresh->advance_tick({}), "genesis tick"); + fresh = checked(fresh->migration_upgrade_candidate(), "boundary upgrade"); + fresh = checked(fresh->maturation_upgrade_candidate(), "maturation upgrade"); + fresh = checked(fresh->inheritance_upgrade_candidate(), "inheritance upgrade"); + fresh = checked(fresh->photosynthesis_upgrade_candidate({0, 1, {0}}), "light upgrade"); + fresh = checked(fresh->liquid_upgrade_candidate(liquid()), "liquid upgrade"); + fresh = checked(fresh->birth_candidate({account(1), 1}, {100, 100, 100, 100, {fresh->tick()}}), + "founder 5 birth"); + fresh = checked(fresh->revamp_upgrade_candidate(rules), "revamp upgrade"); + fresh = checked(fresh->birth_candidate({account(2), 1}, {101, 101, 101, 101, {fresh->tick()}}), + "founder 6 birth"); + return fresh; +} + +void offers_come_from_active_play() { + auto state = offering_region(0); + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto& founder6 = life_of(*state, 101).revamp; + require(founder6.offer.count == 3 && founder6.offer.event_index == 1 && founder6.events == 1 && + founder6.active_ticks == 0, + "forty ticks of active play did not earn a founder 6 an offer"); + for (std::size_t k = 0; k < 3; ++k) + require(biology::cellular_mutation(founder6.offer.ids.at(k)) != nullptr && + founder6.offer.chances.at(k) >= 10 && founder6.offer.chances.at(k) <= 700'000, + "an offered mutation is unknown or its chance out of bounds"); + // A founder 5 plan (no traits) has no catalog: its life counts but is never offered. + require(life_of(*state, 100).revamp.offer.count == 0, "a founder 5 plan was offered"); + // Thrust moved affinity: forty ticks is short of the ten seconds Strong Propulsion counts. + require(founder6.affinity.score.at(0) == 0, "affinity moved too early"); + const auto copy = restore(*state); + require(copy->snapshot() == state->snapshot() && life_of(*copy, 101).revamp == founder6, + "a pending offer did not restore exactly"); +} + +std::vector choose(const CellularLives& state, std::uint64_t life_id, + std::uint16_t id, std::uint64_t successor) { + const auto& offer = life_of(state, life_id).revamp.offer; + return {{life_id, offer.event_index, offer.offer_tick, successor, id}}; +} + +void a_choice_edits_the_plan_and_pays() { + auto state = offering_region(1'000); + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto before = life_of(*state, 101); + const auto id = before.revamp.offer.ids.at(0); + const auto deposits = state->habitat().patches().size(); + const auto execution = checked( + state->advance_tick_with_mutations(swim(*state, {}), choose(*state, 101, id, 9'000)), + "choice tick"); + require(execution.mutations.size() == 1 && execution.mutations.front().result == + CellularMutationResult::offspring_plan_applied, + "the choice was not applied to the plan"); + const auto& after = life_of(*state, 101); + require(after.offspring_genome == 9'000 && after.identity.genome == before.identity.genome && + after.revamp.offer.count == 0, + "the choice changed the expressed body or left the offer"); + const auto plan = state->archive().find(9'000); + require(plan && plan->parents().size() == 1 && plan->parents()[0] == before.identity.genome, + "the successor plan is not the founder's child"); + // 1,000 pJ paid (upkeep and swimming aside) returned as one new bubble. + require(state->habitat().patches().size() >= deposits + 1, "the paid cost was not reclaimed"); + closed(*state); +} + +void unaffordable_choices_wait_and_declines_clear() { + auto state = offering_region(1'000'000'000'000); + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto offer = life_of(*state, 101).revamp.offer; + const auto execution = + checked(state->advance_tick_with_mutations(swim(*state, {}), + choose(*state, 101, offer.ids.at(1), 9'001)), + "unaffordable choice tick"); + require(execution.mutations.front().result == CellularMutationResult::insufficient_funding && + life_of(*state, 101).revamp.offer == offer && !state->archive().find(9'001), + "an unaffordable choice did not leave the offer waiting"); + const auto declined = + checked(state->advance_tick_with_mutations(swim(*state, {}), choose(*state, 101, 0, 9'002)), + "decline tick"); + require(declined.mutations.front().result == CellularMutationResult::declined && + life_of(*state, 101).revamp.offer.count == 0 && + life_of(*state, 101).offspring_genome == life_of(*state, 101).identity.genome, + "a decline did not clear the offer"); + // A choice naming something not offered fails the tick. + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto next = life_of(*state, 101).revamp.offer; + std::uint16_t absent = 1; + while (std::ranges::find(next.ids, absent) != next.ids.end()) + ++absent; + require( + !state->advance_tick_with_mutations(swim(*state, {}), choose(*state, 101, absent, 9'003)), + "a choice outside the offer was accepted"); + closed(*state); +} + +void thrust_moves_affinity() { + auto state = offering_region(0); + for (int tick = 0; tick < 200; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto& scores = life_of(*state, 101).revamp.affinity.score; + // Ten seconds of thrust: Strong Propulsion up, Light Propulsion down (catalog ids 1 and 7). + require(scores.at(0) == 100 && scores.at(6) == -100, + "ten seconds of thrust did not move propulsion affinity"); +} + // A recorded trace replays to the exact live result under rules 13. void trace_replays() { auto live = revamp_region(); @@ -272,6 +397,10 @@ int main() try { carried_matter_is_load(); exclusions_are_checked_and_replayed(); a_long_run_keeps_closure_and_restores(); + offers_come_from_active_play(); + a_choice_edits_the_plan_and_pays(); + unaffordable_choices_wait_and_declines_clear(); + thrust_moves_affinity(); trace_replays(); std::puts("PASS rules 13 owner: upgrade, founder 6, restore and replay"); return 0; diff --git a/tests/cellular_revamp_step_tests.cpp b/tests/cellular_revamp_step_tests.cpp index 4216410..149fd7f 100644 --- a/tests/cellular_revamp_step_tests.cpp +++ b/tests/cellular_revamp_step_tests.cpp @@ -137,6 +137,8 @@ void collection_per_channel_with_a_shared_limit() { reserve.matter[2].value == 50 && reserve.matter[3].value == 0); // 50 pJ drained, 40% kept, the rest heat. CHECK(reserve.energy.value == 20 && result->lives[0].candidate.heat_after.energy.value == 30); + // Food was left on every channel, so both limits held collection back. + CHECK(result->lives[0].candidate.matter_limited && result->lives[0].candidate.energy_limited); CHECK(total(*result, *map, lives) == before(*map, lives)); } diff --git a/tests/cellular_revamp_tuning_tests.cpp b/tests/cellular_revamp_tuning_tests.cpp index d9ddb71..93a75d8 100644 --- a/tests/cellular_revamp_tuning_tests.cpp +++ b/tests/cellular_revamp_tuning_tests.cpp @@ -18,20 +18,39 @@ void check(bool condition, std::source_location at = std::source_location::curre #define CHECK(expression) check(static_cast(expression)) CellularRevampTuning trial() { - return {.version = 1, - .body_essential_upkeep_per_mille = 250, - .body_reserve_load_per_mille = 1'000, - .energy_burn_carbon_pj_per_kfg = 2'000, - .energy_burn_nitrogen_pj_per_kfg = 2'000, - .energy_burn_phosphorus_pj_per_kfg = 2'000, - .energy_burn_other_pj_per_kfg = 2'000, - .feeding_membrane_collection_per_mille_per_point = 2, - .predation_engulf_ratio_milli = 1'500, - .predation_engulf_reserve_percent = 100, - .predation_kill_bubble_per_mille = 500, - .spent_drip_interval_ticks = 20, - .spent_drip_bubble_pj = 20'000'000, - .spent_drip_bubble_fg = 1'000'000}; + CellularRevampTuning t{.version = 1, + .body_essential_upkeep_per_mille = 250, + .body_reserve_load_per_mille = 1'000, + .body_growth_per_tick_centi_mille = 500, + .energy_burn_carbon_pj_per_kfg = 2'000, + .energy_burn_nitrogen_pj_per_kfg = 2'000, + .energy_burn_phosphorus_pj_per_kfg = 2'000, + .energy_burn_other_pj_per_kfg = 2'000, + .feeding_membrane_collection_per_mille_per_point = 2, + .predation_engulf_ratio_milli = 1'500, + .predation_engulf_reserve_percent = 100, + .predation_kill_bubble_per_mille = 500, + .spent_drip_interval_ticks = 20, + .spent_drip_bubble_pj = 20'000'000, + .spent_drip_bubble_fg = 1'000'000, + .mutation_options = 3, + .mutation_floor_ppm = 10, + .mutation_cap_ppm = 700'000, + .mutation_score_min = -1'000, + .mutation_score_max = 1'000, + .mutation_max_multiplier_per_mille = 10'000, + .mutation_min_multiplier_per_mille = 0, + .mutation_offer_interval_ticks = 500, + .mutation_min_points = 25, + .mutation_max_points = 1'000, + .mutation_recipe_min_share = 20, + .mutation_max_offspring = 10, + .mutation_carbon_for_light_fg = 20'000'000, + .mutation_buds_for_adhesion = 5}; + const auto catalog = cellular_catalog(); + for (std::size_t i = 0; i < catalog.size(); ++i) + t.mutations.at(i) = cellular_default_tuning(catalog[i]); + return t; } std::string with(std::string text, const std::string& key, const std::string& value) { @@ -47,6 +66,45 @@ CellularTuningErrorKind error_of(const std::string& text) { return parsed.error().kind; } +// Per-mutation overrides are optional, change only their field, and refuse unknown names, +// unknown fields, duplicates and out-of-range values. +void mutation_overrides() { + const auto base = encode_cellular_revamp_tuning(trial()); + // The canonical text lists every override; a file may omit them all. + std::string bare; + for (std::size_t at = 0; at < base.size();) { + const auto end = base.find('\n', at); + const auto line = base.substr(at, end - at); + if (!line.starts_with("mutation.") || line.find('.', 9) == std::string::npos || + line.find('.', 9) > line.find(' ')) + bare += line + "\n"; + at = end + 1; + } + CHECK(parse_cellular_revamp_tuning(bare) == trial()); + const auto tuned = + parse_cellular_revamp_tuning(bare + "mutation.strong_propulsion.cost_e_pj = 1_000\n" + "mutation.strong_propulsion.cost_scale_percent = 50\n" + "mutation.adhesion.enabled = 0\n"); + CHECK(tuned.has_value()); + if (!tuned) + return; + auto expected = trial(); + expected.mutations.at(0).cost.energy.value = 1'000; + expected.mutations.at(0).cost_scale_percent = 50; + expected.mutations.at(48).enabled = false; + CHECK(*tuned == expected); + CHECK(error_of(bare + "mutation.unknown_thing.enabled = 1\n") == + CellularTuningErrorKind::unknown_key); + CHECK(error_of(bare + "mutation.adhesion.colour = 1\n") == + CellularTuningErrorKind::unknown_key); + CHECK(error_of(bare + "mutation.adhesion.enabled = 1\nmutation.adhesion.enabled = 0\n") == + CellularTuningErrorKind::duplicate_key); + CHECK(error_of(bare + "mutation.adhesion.cost_scale_percent = 101\n") == + CellularTuningErrorKind::out_of_range); + CHECK(error_of(with(bare, "mutation.floor_ppm", "800000")) == + CellularTuningErrorKind::inconsistent); +} + void canonical_round_trip() { const auto text = encode_cellular_revamp_tuning(trial()); const auto parsed = parse_cellular_revamp_tuning(text); @@ -101,6 +159,7 @@ int main(int argc, char** argv) { try { canonical_round_trip(); refusals(); + mutation_overrides(); if (argc > 1) repository_file(argv[1]); } catch (const std::exception& error) {