Cellular rules 7: percentage mutations, skilled budding, hunting wildlife (ADR-0137)
Foundation / checks (ecs) (push) Successful in 3m21s
Foundation / checks (deploy) (push) Successful in 5m39s
Foundation / checks (tsan) (push) Successful in 11m43s
Foundation / checks (network) (push) Successful in 22m3s
Foundation / checks (client) (push) Successful in 22m35s
Foundation / checks (checks) (push) Successful in 46m53s
Foundation / checks (postgres) (push) Successful in 48m22s
Foundation / postgres-tools (push) Successful in 1m17s
Foundation / image (push) Successful in 3m31s
Foundation / server-image (push) Successful in 6m7s

The region 6 playtest found a speed mutation adding 6,667 um/s (1/300 of the range,
33x a founder), so buds seemed to teleport; reproduction made buds bigger and dearer;
and wildlife never hunted. Rules 7:

- genome schema 4: a step is a tenth of the current value (at least 1); an acquired
  capability starts at the founder's value instead of a minimum it could never grow from;
- development 4: a bud is always half the body, and reproduction takes value/2000 off
  its construction energy (founders save a quarter; matter is never discounted);
- twins: a seeded roll (reproduction/2 per thousand) splits one affordable bud's
  investment into two quarter-size buds;
- wildlife engulfs a touching cell the region step lets it take, players' included.

Founder 3, owner format 6 (no new state), bundle v8 and schema v42; the cellular-v6
opening provisions it. The client's mutation callout shrinks to a "Mutation [E]" pill and
its candidate texts describe the new steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-16 22:41:55 -04:00
co-authored by Claude Opus 5.5
parent feac7aac4e
commit 86ee800f32
33 changed files with 786 additions and 137 deletions
+10 -2
View File
@@ -16,7 +16,10 @@ bool fits(const accounting::Inventory& part, const accounting::Inventory& whole)
std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, GrowthState parent_growth,
const accounting::Inventory& parent_reserve,
std::uint32_t temperature_millikelvin) {
std::uint32_t temperature_millikelvin,
std::uint32_t share) {
if (share == 0)
return std::unexpected{BuddingError::no_capability};
if (!genome.carries(Capability::reproduction))
return std::unexpected{BuddingError::no_capability};
if (parent_growth.realized_per_thousand != 1000 || parent_growth.damage_per_thousand != 0)
@@ -24,7 +27,12 @@ std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, Growth
const auto parent = metabolic_budget(genome, parent_growth, {temperature_millikelvin, {}});
if (!parent)
return std::unexpected{BuddingError::development};
const auto& investment = parent->reproduction_investment;
// ADR-0137 twins: each of `share` buds is funded from that fraction of the investment
// (rounded down; the remainder stays with the parent).
auto investment = parent->reproduction_investment;
investment.energy.value /= share;
for (auto& mass : investment.matter)
mass.value /= share;
std::uint64_t invested_matter = 0;
for (const auto& mass : investment.matter)
invested_matter += mass.value;
+3 -1
View File
@@ -67,7 +67,9 @@ std::expected<DevelopmentRules, DevelopmentError> rules_for(std::uint32_t develo
// Version 3 (rules 6, 2026-10-15 balance): version 2 with a third of the construction
// energy (13 pJ per 1000 fg built instead of 40). Construction is overhead paid into
// heat, so this changes no matter balance.
if (development_version == 3) {
// Version 4 (rules 7, ADR-0137) keeps version 3's rules; only what reproduction
// means changes (metabolism.cpp).
if (development_version == 3 || development_version == 4) {
return DevelopmentRules{1000, 1200, 10, 15, 13, 60'000, 293'150, 50};
}
return std::unexpected{DevelopmentError::unsupported_rules};
+15 -3
View File
@@ -2,6 +2,7 @@
#include "evo/accounting/rates.hpp"
#include <algorithm>
#include <limits>
namespace evo::biology {
@@ -108,7 +109,8 @@ metabolic_rules_for(std::uint32_t development_version) {
return MetabolicRules{structure_shares, membrane_shares, 20, 50'000};
}
// Version 2: per second; movement at 1000 um/s costs 50 pJ/s per 1000 fg (tunable).
if (development_version == 2 || development_version == 3) { // Version 3: same metabolism.
// Versions 3 and 4: the same metabolism.
if (development_version >= 2 && development_version <= 4) {
return MetabolicRules{structure_shares, membrane_shares, 50, 50'000};
}
return std::unexpected{DevelopmentError::unsupported_rules};
@@ -201,12 +203,22 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
break;
}
if (genome.carries(Capability::reproduction)) {
const auto fraction = *genome.parameter(Capability::reproduction);
const auto value = *genome.parameter(Capability::reproduction);
// Version 4 (ADR-0137): a bud is always half the body, and reproduction is skill:
// it takes up to half off the bud's construction energy (value / 2000). Matter is
// never discounted (ADR-0118). Earlier versions invest `value` per thousand.
const bool skill = genome.development_version() == 4;
const auto fraction = skill ? bud_body_per_thousand_v4 : value;
// A parent divides the body it has, so the investment keeps its composition.
budget.reproduction_investment = fraction_of(budget.body, fraction);
// Offspring tissue is priced at what the parent's own tissue costs.
budget.reproduction_investment.energy.value =
const auto construction =
scaled(matter_total(budget.reproduction_investment), shape->construction_per_kilogram);
// Discount = construction * skill / 2000, split to stay within 64 bits.
const std::uint64_t level = std::min<std::uint32_t>(value, 1000);
const auto discount = construction / 2000 * level + construction % 2000 * level / 2000;
budget.reproduction_investment.energy.value =
skill ? construction - discount : construction;
}
return budget;
}
+27 -4
View File
@@ -1,5 +1,6 @@
#include "evo/biology/mutation.hpp"
#include "evo/biology/founder.hpp"
#include "evo/core/random.hpp"
#include <algorithm>
@@ -32,14 +33,28 @@ constexpr std::array<MutationOperator, 4 * capability_count> catalog = [] {
// (rules 6, 2026-10-15 balance) takes a third of that step: successor bodies differ a
// third as much, so the matter a mutation needs falls with them (ADR-0118: the cost is
// the body difference, never a discount).
// Schema 4 (rules 7, ADR-0137) steps by a tenth of the current value instead (at least 1),
// so a trait changes by a percentage and a lineage compounds.
constexpr std::uint32_t adjustment_step(const std::array<CapabilitySpec, capability_count>& table,
Capability kind, std::uint32_t schema) noexcept {
Capability kind, std::uint32_t schema,
std::uint32_t current) noexcept {
if (schema == genome_schema_v4)
return current / 10 == 0 ? 1 : current / 10;
const auto& limits = table[static_cast<std::size_t>(kind)];
const auto span = limits.maximum - limits.minimum;
const std::uint32_t divisor = schema == genome_schema_v3 ? 300 : 100;
return span / divisor == 0 ? 1 : span / divisor;
}
std::uint32_t acquired_start(Capability kind, const CapabilitySpec& limits) noexcept {
const auto& p = primitive_founder_parameters;
const auto value = kind == Capability::movement ? p.movement
: kind == Capability::ingestion ? p.ingestion
: kind == Capability::reproduction ? p.reproduction
: limits.minimum;
return std::clamp(value, limits.minimum, limits.maximum);
}
std::uint64_t mix(std::uint64_t hash, std::uint64_t value) noexcept {
// Non-cryptographic combiner. No wall clock and no std::hash enters this.
return hash ^ (value + 0x9e3779b97f4a7c15ULL + (hash << 6U) + (hash >> 2U));
@@ -96,7 +111,8 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
if (!present) {
return std::nullopt;
}
const auto step = adjustment_step(table, entry.target, genome.schema_version());
const auto step =
adjustment_step(table, entry.target, genome.schema_version(), carried->parameter);
// Refused rather than clamped: a clamp would make two operators agree
// and would offer a no-op as a real choice.
if (carried->parameter > limits.maximum - step) {
@@ -109,7 +125,8 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
if (!present) {
return std::nullopt;
}
const auto step = adjustment_step(table, entry.target, genome.schema_version());
const auto step =
adjustment_step(table, entry.target, genome.schema_version(), carried->parameter);
if (carried->parameter < limits.minimum + step) {
return std::nullopt;
}
@@ -120,7 +137,13 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
if (present) {
return std::nullopt;
}
draft.capabilities.push_back({entry.target, limits.minimum, 0});
// Schema 4 starts an acquired capability at the founder's value (a percentage of
// the minimum, zero speed for instance, would never grow); otherwise the minimum.
draft.capabilities.push_back({entry.target,
genome.schema_version() == genome_schema_v4
? acquired_start(entry.target, limits)
: limits.minimum,
0});
break;
case MutationEffect::shed:
if (!present) {
@@ -168,6 +168,11 @@ provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects,
// ADR-0128: a rules-5 region starts on the v6 bundle with genome revisions.
manifest->cellular_versions = cellular_v6_versions;
manifest->history_profile = cellular_revision_history_profile;
} else if (manifest && opening.format_version() == server::cellular_lives_presence_format &&
opening.rules_version() == server::cellular_lives_reproduction_rules) {
// ADR-0137: a rules-7 region starts on the v8 bundle with genome revisions.
manifest->cellular_versions = cellular_v8_versions;
manifest->history_profile = cellular_revision_history_profile;
} else if (manifest && opening.format_version() == server::cellular_lives_presence_format &&
opening.rules_version() == server::cellular_lives_balance_rules) {
// 2026-10-15 balance: a rules-6 region starts on the v7 bundle with genome revisions.
+4 -2
View File
@@ -73,7 +73,8 @@ bool structural(const CheckpointManifest& m) noexcept {
m.cellular_versions != cellular_v4_versions &&
m.cellular_versions != cellular_v5_versions &&
m.cellular_versions != cellular_v6_versions &&
m.cellular_versions != cellular_v7_versions) ||
m.cellular_versions != cellular_v7_versions &&
m.cellular_versions != cellular_v8_versions) ||
(cellular && m.versions != environmental_v1_versions))
return false;
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
@@ -169,7 +170,8 @@ bool supported(const CheckpointManifest& m) noexcept {
m.cellular_versions == cellular_v4_versions ||
m.cellular_versions == cellular_v5_versions ||
m.cellular_versions == cellular_v6_versions ||
m.cellular_versions == cellular_v7_versions) &&
m.cellular_versions == cellular_v7_versions ||
m.cellular_versions == cellular_v8_versions) &&
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
}
+99 -56
View File
@@ -535,7 +535,8 @@ CellularLives::create(const PrimitiveLives& opening,
const auto world = nursery_config.world;
const auto region = nursery_config.region;
const auto frame = nursery_config.frame;
const bool balance = profile == CellularLivesProfile::balance; // Rules 6: presence plus.
const bool reproduction = profile == CellularLivesProfile::reproduction; // Rules 7.
const bool balance = profile == CellularLivesProfile::balance || reproduction; // Rules 6+.
const bool presence = profile == CellularLivesProfile::presence || balance;
const bool budding = profile == CellularLivesProfile::budding || presence;
const bool engulf = profile == CellularLivesProfile::engulf || budding;
@@ -549,14 +550,23 @@ CellularLives::create(const PrimitiveLives& opening,
: budding ? cellular_lives_bud_format
: engulf ? cellular_lives_engulf_format
: cellular_lives_format,
balance ? cellular_lives_balance_rules
: presence ? cellular_lives_presence_rules
: budding ? cellular_lives_bud_rules
: engulf ? cellular_lives_engulf_rules
: cellular_lives_rules);
reproduction ? cellular_lives_reproduction_rules
: balance ? cellular_lives_balance_rules
: presence ? cellular_lives_presence_rules
: budding ? cellular_lives_bud_rules
: engulf ? cellular_lives_engulf_rules
: cellular_lives_rules);
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
}
bool cellular_twin_bud(std::uint64_t world, std::uint64_t region, std::uint64_t parent_life,
std::uint64_t tick, std::uint32_t reproduction) noexcept {
// Its own stream: the parent and tick hashed with a twin-only salt ("twin").
constexpr std::uint64_t twin_stream = 0x7477696eULL;
const auto roll = mutation_seed(world, region, parent_life, tick ^ (twin_stream << 32U));
return roll % 1000 < std::min<std::uint32_t>(reproduction, 1000) / 2;
}
std::uint64_t CellularLives::world() const noexcept {
return state_->world;
}
@@ -969,11 +979,12 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
const bool offer_version = magic == cellular_lives_v2_magic &&
format_version == cellular_lives_format &&
rules_version == cellular_lives_rules;
// Format 6 carries rules 5 or rules 6 (founder 2, no new state).
// Format 6 carries rules 5, 6 (founder 2) or 7 (founder 3, ADR-0137); no new state.
const bool presence_version = magic == cellular_lives_v6_magic &&
format_version == cellular_lives_presence_format &&
(rules_version == cellular_lives_presence_rules ||
rules_version == cellular_lives_balance_rules);
rules_version == cellular_lives_balance_rules ||
rules_version == cellular_lives_reproduction_rules);
// Formats 5 and 6 carry the bud sequence and parent lives (rules 4 and 5).
const bool bud_version = presence_version || (magic == cellular_lives_v5_magic &&
format_version == cellular_lives_bud_format &&
@@ -1448,7 +1459,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
for (const auto& request : ordered) {
if (!bud_rules || !request.intent.bud)
continue;
const auto parent = std::ranges::lower_bound(
auto parent = std::ranges::lower_bound(
next_lives, request.life_id, {},
[](const CellularOwnedLife& value) { return value.identity.life; });
if (parent == next_lives.end() || parent->identity.life != request.life_id) {
@@ -1459,55 +1470,87 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
bud_results.push_back({request.life_id, 0, CellularBudResult::not_able});
continue; // Out of the world (ADR-0128).
}
const auto temperature = state_->config.ambient_temperature_millikelvin;
const auto genome = next_archive.find(parent->identity.genome);
const auto parent_budget = budget_for(next_archive, *parent, temperature);
if (!genome || !parent_budget)
return std::unexpected{CellularLivesError::archive};
const auto transition =
biology::fund_bud(*genome, parent->growth, parent->reserve, temperature);
if (!transition) {
if (transition.error() == biology::BuddingError::development)
// ADR-0137 (rules 7): on a twin roll the bud investment is split between two buds
// (each a quarter of the parent's body). The parent's reported result is the
// first bud's; a twin that finds no room is simply not made.
const bool twins = [&] {
if (state_->rules_version < cellular_lives_reproduction_rules)
return false;
const auto parent_genome = next_archive.find(parent->identity.genome);
if (!parent_genome)
return false;
const auto skill = parent_genome->parameter(biology::Capability::reproduction);
// Twins split one whole bud: the parent must afford that whole bud first.
return skill &&
cellular_twin_bud(state_->world, state_->region, request.life_id,
proposal->end_tick, *skill) &&
biology::fund_bud(*parent_genome, parent->growth, parent->reserve,
state_->config.ambient_temperature_millikelvin)
.has_value();
}();
for (int copy = 0; copy < (twins ? 2 : 1); ++copy) {
if (copy == 1)
// Appending the first bud may have moved the parent; find it again (buds
// sort after every existing life, so the order still holds).
parent = std::ranges::lower_bound(
next_lives, request.life_id, {},
[](const CellularOwnedLife& value) { return value.identity.life; });
const bool twin = copy == 1;
const auto temperature = state_->config.ambient_temperature_millikelvin;
const auto genome = next_archive.find(parent->identity.genome);
const auto parent_budget = budget_for(next_archive, *parent, temperature);
if (!genome || !parent_budget)
return std::unexpected{CellularLivesError::archive};
const auto transition = biology::fund_bud(*genome, parent->growth, parent->reserve,
temperature, twins ? 2U : 1U);
if (!transition) {
if (transition.error() == biology::BuddingError::development)
return std::unexpected{CellularLivesError::biology};
if (!twin)
bud_results.push_back(
{request.life_id, 0,
transition.error() == biology::BuddingError::insufficient_funding
? CellularBudResult::insufficient_funding
: CellularBudResult::not_able});
break;
}
const auto bud_budget =
biology::metabolic_budget(*genome, transition->growth, {temperature, {}});
if (!bud_budget || bud_budget->body.matter != transition->body.matter)
return std::unexpected{CellularLivesError::biology};
bud_results.push_back({request.life_id, 0,
transition.error() == biology::BuddingError::insufficient_funding
? CellularBudResult::insufficient_funding
: CellularBudResult::not_able});
continue;
const auto identity = cellular_bud_identity(state_->region, next_bud_sequence);
const auto position =
bud_position(*parent, parent_budget->phenotype.extent, bud_budget->phenotype.extent,
next_lives, next_archive, state_->config);
if (!position)
return std::unexpected{position.error()};
if (identity == 0 || !*position ||
next_lives.size() >= biology::max_cellular_tick_lives ||
next_archive.organism(identity)) {
if (!twin)
bud_results.push_back({request.life_id, 0, CellularBudResult::no_placement});
break;
}
if (!add_inventory(next_heat, accounting::Inventory{transition->heat, {}}) ||
!next_archive.record_birth(identity, parent->identity.genome, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive};
parent->reserve = transition->parent_reserve;
CellularOwnedLife bud{};
bud.identity = {
identity, identity, parent->identity.genome, identity, {proposal->end_tick}};
bud.source = parent->source;
bud.growth = transition->growth;
bud.position = **position;
bud.body = transition->body;
bud.reserve = transition->reserve;
bud.parent_life = parent->identity.life;
// Bud identities increase within the region and exceed every allocated identity,
// so the new life sorts after all existing ones.
next_lives.push_back(bud);
++next_bud_sequence;
if (!twin)
bud_results.push_back({request.life_id, identity, CellularBudResult::budded});
}
const auto bud_budget =
biology::metabolic_budget(*genome, transition->growth, {temperature, {}});
if (!bud_budget || bud_budget->body.matter != transition->body.matter)
return std::unexpected{CellularLivesError::biology};
const auto identity = cellular_bud_identity(state_->region, next_bud_sequence);
const auto position =
bud_position(*parent, parent_budget->phenotype.extent, bud_budget->phenotype.extent,
next_lives, next_archive, state_->config);
if (!position)
return std::unexpected{position.error()};
if (identity == 0 || !*position || next_lives.size() >= biology::max_cellular_tick_lives ||
next_archive.organism(identity)) {
bud_results.push_back({request.life_id, 0, CellularBudResult::no_placement});
continue;
}
if (!add_inventory(next_heat, accounting::Inventory{transition->heat, {}}) ||
!next_archive.record_birth(identity, parent->identity.genome, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive};
parent->reserve = transition->parent_reserve;
CellularOwnedLife bud{};
bud.identity = {
identity, identity, parent->identity.genome, identity, {proposal->end_tick}};
bud.source = parent->source;
bud.growth = transition->growth;
bud.position = **position;
bud.body = transition->body;
bud.reserve = transition->reserve;
bud.parent_life = parent->identity.life;
// Bud identities increase within the region and exceed every allocated identity,
// so the new life sorts after all existing ones and `parent` stays valid.
next_lives.push_back(bud);
++next_bud_sequence;
bud_results.push_back({request.life_id, identity, CellularBudResult::budded});
}
std::ranges::sort(next_lives, {},
[](const CellularOwnedLife& life) { return life.identity.life; });
+45 -1
View File
@@ -1,11 +1,13 @@
#include "evo/server/lifecycle/wildlife_controller.hpp"
#include "evo/biology/budding.hpp"
#include "evo/biology/cellular_motion.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <optional>
namespace evo::server {
@@ -20,6 +22,16 @@ std::uint64_t mix(std::uint64_t life, std::uint64_t phase) noexcept {
return value;
}
// The region step's engulf test (ADR-0124), without overflow: hunter * 1000 must reach
// prey * 1500 per micrometre of the prey's membrane.
bool can_engulf(std::uint64_t hunter, std::uint64_t prey, std::uint32_t membrane_um) noexcept {
const auto factor = biology::cellular_engulf_ratio_milli_per_membrane_um * membrane_um;
constexpr auto most = std::numeric_limits<std::uint64_t>::max();
if (factor != 0 && prey > most / factor)
return false;
return hunter <= most / 1000 ? hunter * 1000 >= prey * factor : true;
}
bool overlaps(std::uint64_t start, std::uint32_t extent, std::uint32_t patch) noexcept {
return start < std::uint64_t{patch} + biology::cellular_patch_pitch_um &&
start + extent > patch;
@@ -72,10 +84,42 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
intents.push_back({life.identity.life, intent});
continue;
}
const auto extent = budget->phenotype.extent;
// Rules 7 (ADR-0137): engulf a touching cell the region step would let it take
// (ADR-0124: mass at least 1.5 x the prey's per micrometre of prey membrane),
// players' cells included; otherwise feed.
if (state.rules_version() >= cellular_lives_reproduction_rules) {
bool prey = false;
for (const auto& other : state.lives()) {
if (other.identity.life == life.identity.life ||
other.presence == CellularPresence::suspended)
continue;
const auto other_genome = state.archive().find(other.identity.genome);
if (!other_genome)
return std::unexpected{CellularLivesError::archive};
const auto other_budget =
biology::metabolic_budget(*other_genome, other.growth, {temperature, {}});
const auto membrane = other_genome->parameter(biology::Capability::membrane);
if (!other_budget || !membrane)
return std::unexpected{CellularLivesError::biology};
if (!biology::cellular_footprints_contact(life.position, extent, other.position,
other_budget->phenotype.extent))
continue;
if (can_engulf(budget->phenotype.total_mass, other_budget->phenotype.total_mass,
*membrane)) {
prey = true;
break;
}
}
if (prey) {
intent.engulf = true;
intents.push_back({life.identity.life, intent});
continue;
}
}
const auto perceived = state.perceive(life.identity.life);
if (!perceived)
return std::unexpected{perceived.error()};
const auto extent = budget->phenotype.extent;
const auto centre_x = static_cast<std::int64_t>(life.position.x_um) + extent / 2;
const auto centre_y = static_cast<std::int64_t>(life.position.y_um) + extent / 2;
std::optional<biology::CellularPatchAddress> nearest;