Bud unowned wildlife from the cellular owner under rules 4
Owner format 5 / rules 4 (ADR-0125) adds the bud intent: after the tick's mutations a parent pays fund_bud's investment and provision, and the bud is placed touching it with the next region-namespace identity, the parent's current genome and its parent life. Buds are wildlife with no account and never earn mutation offers; restore enforces the identity namespace and sequence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -587,6 +587,11 @@ void rules_three_owner_resolves_engulf_and_detritus() {
|
||||
both.intake_target = evo::biology::CellularPatchAddress{0, 0};
|
||||
const std::array conflicting{CellularLifeIntent{1, both}, CellularLifeIntent{2, {}}};
|
||||
CHECK(!owner.advance_tick(conflicting) && owner.tick() == 2);
|
||||
// Budding needs rules 4.
|
||||
evo::biology::CellularStepIntent bud{};
|
||||
bud.bud = true;
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, bud}, CellularLifeIntent{2, {}}})
|
||||
.error() == CellularLivesError::invalid_intents);
|
||||
|
||||
const auto patch_before = owner.habitat().patches()[0].stock;
|
||||
std::size_t steps{};
|
||||
@@ -629,6 +634,102 @@ void rules_three_owner_resolves_engulf_and_detritus() {
|
||||
CHECK(CellularLives::restore(bad_predator, 92, 1, 7, owner.tick()).error() ==
|
||||
CellularLivesError::noncanonical);
|
||||
}
|
||||
|
||||
// ADR-0125: a fed founder buds an unowned wildlife cell carrying its genome. The bud's
|
||||
// identity is in the region namespace, funding is conserved, and restore is exact.
|
||||
void rules_four_owner_buds_wildlife() {
|
||||
auto primitive = PrimitiveLives::create({93, 1, 7, 17, founder_price(1), {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 3;
|
||||
request.action = 1;
|
||||
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
|
||||
constexpr std::uint64_t rich = 10'000'000'000;
|
||||
evo::biology::CellularHabitatConfig habitat_config{
|
||||
93, 1, 7, 3'000, 2'000, {{{0, 0}, 29, {{rich}, {{{rich}, {rich}, {rich}, {rich}}}}}}};
|
||||
auto habitat = evo::biology::CellularHabitat::create(std::move(habitat_config));
|
||||
CHECK(habitat);
|
||||
auto created =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 1, 293'150},
|
||||
CellularLivesProfile::budding);
|
||||
CHECK(created);
|
||||
auto& owner = **created;
|
||||
CHECK(owner.format_version() == cellular_lives_bud_format &&
|
||||
owner.rules_version() == cellular_lives_bud_rules && owner.next_bud_sequence() == 1);
|
||||
|
||||
evo::biology::CellularStepIntent feed{};
|
||||
feed.intake_target = evo::biology::CellularPatchAddress{0, 0};
|
||||
evo::biology::CellularStepIntent bud{};
|
||||
bud.bud = true;
|
||||
// A bud is exclusive with feeding, and needs rules 4 (checked in the rules 3 test).
|
||||
auto feeding_bud = feed;
|
||||
feeding_bud.bud = true;
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, feeding_bud}}).error() ==
|
||||
CellularLivesError::invalid_intents);
|
||||
|
||||
const auto parent_genome = owner.lives().front().identity.genome;
|
||||
std::optional<CellularTickExecution> budded;
|
||||
std::size_t refused{};
|
||||
for (std::size_t round = 0; round < 400 && !budded; ++round) {
|
||||
for (int tick = 0; tick < 19; ++tick)
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, feed}}));
|
||||
const auto before = owner.lives().front().reserve;
|
||||
auto attempt = owner.advance_tick_with_mutations(
|
||||
std::array{CellularLifeIntent{1, bud}}, std::span<const CellularMutationSelection>{});
|
||||
CHECK(attempt && attempt->buds.size() == 1 && attempt->buds.front().parent_life == 1);
|
||||
CHECK(owner.current_total() == owner.opening_total());
|
||||
if (attempt->buds.front().result == CellularBudResult::budded) {
|
||||
budded = std::move(*attempt);
|
||||
} else {
|
||||
// A refusal spends nothing beyond the ordinary tick.
|
||||
CHECK(attempt->buds.front().result == CellularBudResult::insufficient_funding);
|
||||
CHECK(owner.lives().size() == 1 &&
|
||||
owner.lives().front().reserve.matter == before.matter);
|
||||
++refused;
|
||||
}
|
||||
}
|
||||
CHECK(budded.has_value() && refused > 0);
|
||||
const auto budding = budded.value_or(CellularTickExecution{});
|
||||
CHECK(budding.buds.size() == 1);
|
||||
const auto identity = cellular_bud_identity(1, 1);
|
||||
CHECK(budding.buds.front().bud_life == identity && owner.next_bud_sequence() == 2);
|
||||
CHECK(owner.lives().size() == 2);
|
||||
const auto& parent = owner.lives()[0];
|
||||
const auto& child = owner.lives()[1];
|
||||
CHECK(parent.identity.life == 1 && child.identity.life == identity);
|
||||
CHECK(child.account == LifeAccount{} && child.parent_life == 1 &&
|
||||
child.identity.genome == parent_genome && child.identity.organism == identity &&
|
||||
child.identity.born.value == owner.tick() &&
|
||||
child.mutation == CellularMutationProgress{});
|
||||
CHECK(child.growth.realized_per_thousand < 1000 && child.reserve.energy.value > 0);
|
||||
CHECK(owner.archive().living_carriers(parent_genome).value_or(0) == 2);
|
||||
CHECK(owner.last_tick_feedback().front().bud == CellularBudResult::budded &&
|
||||
owner.last_tick_feedback().front().bud_life == identity);
|
||||
CHECK(owner.current_total() == owner.opening_total());
|
||||
|
||||
// Wildlife feeds like any cell but never earns a mutation offer.
|
||||
const auto child_x = child.position.x_um / 1000;
|
||||
const auto child_y = child.position.y_um / 1000;
|
||||
evo::biology::CellularStepIntent child_feed{};
|
||||
child_feed.intake_target = evo::biology::CellularPatchAddress{
|
||||
static_cast<std::uint32_t>(child_x), static_cast<std::uint32_t>(child_y)};
|
||||
for (int tick = 0; tick < 40; ++tick)
|
||||
CHECK(owner.advance_tick(
|
||||
std::array{CellularLifeIntent{1, feed}, CellularLifeIntent{identity, child_feed}}));
|
||||
CHECK(owner.lives().size() == 2 && owner.lives()[1].mutation == CellularMutationProgress{});
|
||||
|
||||
const auto saved = owner.snapshot();
|
||||
auto recovered = CellularLives::restore(saved, 93, 1, 7, owner.tick());
|
||||
CHECK(recovered && (*recovered)->snapshot() == saved &&
|
||||
(*recovered)->next_bud_sequence() == 2 &&
|
||||
std::ranges::equal((*recovered)->lives(), owner.lives()));
|
||||
// A bud identity at or beyond the recorded sequence is refused on restore.
|
||||
auto rewound = saved;
|
||||
const auto sequence_at = std::size_t{212};
|
||||
rewound[sequence_at] = 1;
|
||||
refresh_checksum(rewound);
|
||||
CHECK(!CellularLives::restore(rewound, 93, 1, 7, owner.tick()));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
@@ -638,7 +739,9 @@ int main() {
|
||||
retained_feeding_earns_a_persistent_mutation_offer();
|
||||
owner_advances_and_closes_death_atomically();
|
||||
rules_three_owner_resolves_engulf_and_detritus();
|
||||
std::puts("PASS cellular lives: feeding, tick ownership, terminal closure, rules 3");
|
||||
rules_four_owner_buds_wildlife();
|
||||
std::puts(
|
||||
"PASS cellular lives: feeding, tick ownership, terminal closure, rules 3, budding");
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user