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