Run the cellular owner on rules 3 with corpse causes
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (deploy) (push) Successful in 4m21s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 10m41s
Foundation / checks (postgres) (push) Canceled after 10m38s
Foundation / checks (tsan) (push) Canceled after 8m19s
Foundation / checks (client) (push) Canceled after 10m48s
Foundation / checks (checks) (push) Canceled after 10m53s

ADR-0124's engulf profile starts a region on owner format 4 and rules 3,
with the revision-format archive. Ticks pass genome membrane thickness and
source to the region step, record each corpse's cause and predator, insert
detritus patches and validate rules-3 corpses as empty. Format-4 snapshots
carry the cause and predator and refuse an unknown cause, a predator on a
starvation corpse or a non-empty corpse. Mutation selection accepts both
genome-revision formats (3 and 4).

Persistence (version bundle, schema 34), protocol v11 and provisioning
follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-13 18:54:03 -04:00
co-authored by Claude Opus 5.5
parent 0fb67c3257
commit 02adc35fa2
9 changed files with 217 additions and 37 deletions
@@ -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-20261013T224748-73224:1791942468"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261013T225403-26545:1791942843"}
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
ports:
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
+8
View File
@@ -420,6 +420,14 @@ scoped change before starting the next segment.
is unchanged and ignores engulf. Owner, protocol, persistence and recovery
wiring remain.
- 11.3f-2 (ADR-0124): `CellularLives` gains the engulf profile (owner format
4, rules 3, revision archive). Ticks pass genome membrane thickness and source
to the resolver, record each corpse's cause and predator, insert new detritus
patches, and require empty rules-3 corpses. Format-4 snapshots carry the cause
and refuse an unknown cause, a predator on a starvation corpse or a corpse
inventory. Mutation selection accepts formats 3 and 4. Persistence, protocol
and provisioning remain.
## Exit boundary
11.3 closes only when the documented segments have evidence and the player-facing
+18 -1
View File
@@ -7221,4 +7221,21 @@ Executed locally: MSVC Debug full build and `ctest -R cellular` (6/6, with five
new region-step cases: capacity split and region-wide conservation, size,
membrane and contact refusal, one prey per predator per tick, empty-cell
detritus, rules-2 no-op and invalid rules-3 intents); g++-14 `-Werror`,
clang-tidy-19 and clang-format 19.1.5 on the changed files.
clang-tidy-19 and clang-format 19.1.5 on the changed files.
## 2026-10-13 — M11.3f-2 rules-3 cellular owner (CI pending)
`CellularLives::create(..., CellularLivesProfile::engulf)` starts a region on
owner format 4 / rules 3 with the revision-format archive. Rules-3 ticks feed
membrane thickness and source to the resolver, keep each corpse's cause and
predator, add detritus patches, and validate rules-3 corpses as empty (rules 2
keeps the body-matter floor). Format 4 snapshots append a cause byte, seven zero
bytes and the predator id to each corpse record; restore refuses an unknown
cause, a predator on a starvation corpse or a non-empty corpse. Mutation
selection now accepts formats 3 and 4.
Executed locally: MSVC Debug full build and `ctest` (68/68, including a new
owner case: engulf-profile genesis, equal-founder `no_eligible_prey`, refused
engulf-plus-intake tick, starvation detritus into the patch, per-tick
conservation, format-4 round trip and tampered corpse causes); g++-14
`-Werror`, clang-tidy-19 (the one remaining `cellular_session_batch.cpp:110`
report predates this change) and clang-format 19.1.5.
+2 -1
View File
@@ -55,7 +55,8 @@ struct CellularPatchStockUpdate {
accounting::Inventory stock;
auto operator<=>(const CellularPatchStockUpdate&) const = default;
};
enum class CellularDeathCause : std::uint8_t { starved = 1, engulfed = 2 };
// Unrecorded: a corpse from a checkpoint format that kept no cause (before format 4).
enum class CellularDeathCause : std::uint8_t { unrecorded = 0, starved = 1, engulfed = 2 };
struct CellularCorpseCandidate {
std::uint64_t life_id{};
CellularPosition position;
@@ -18,6 +18,10 @@ inline constexpr std::uint32_t cellular_lives_legacy_format = 1;
inline constexpr std::uint32_t cellular_lives_format = 2;
inline constexpr std::uint32_t cellular_lives_revision_format = 3;
inline constexpr std::uint32_t cellular_lives_rules = 2;
// ADR-0124: format 4 adds each corpse's cause and predator; rules 3 add engulfment and
// corpse detritus. They are used together, with the revision-format archive.
inline constexpr std::uint32_t cellular_lives_engulf_format = 4;
inline constexpr std::uint32_t cellular_lives_engulf_rules = 3;
inline constexpr std::size_t max_cellular_lives_bytes = std::size_t{16} * 1024 * 1024;
inline constexpr std::uint64_t cellular_mutation_surplus_seconds = 60;
inline constexpr std::uint16_t cellular_mutation_candidate_count = 3;
@@ -50,7 +54,9 @@ struct CellularOwnedCorpse {
biology::CellularPosition position{};
biology::GrowthState growth{};
std::uint32_t extent_um{};
accounting::Inventory inventory{};
accounting::Inventory inventory{}; // Empty under rules 3: it became detritus.
biology::CellularDeathCause cause{biology::CellularDeathCause::unrecorded};
std::uint64_t predator_life{}; // Engulfed only.
auto operator<=>(const CellularOwnedCorpse&) const = default;
};
struct CellularLifeIntent {
@@ -79,8 +85,13 @@ struct CellularLifeTickFeedback {
accounting::Picojoules maintenance_cost{}, movement_cost{};
biology::CellularMovementStatus movement{biology::CellularMovementStatus::not_requested};
biology::CellularIntakeStatus intake{biology::CellularIntakeStatus::not_requested};
biology::CellularEngulfStatus engulf{biology::CellularEngulfStatus::not_requested};
std::uint64_t prey_life{};
auto operator<=>(const CellularLifeTickFeedback&) const = default;
};
// Which owner version a new region starts on. Offers: format 2, rules 2 (the M11.3/11.4
// trial, upgraded by the no-tick migrations). Engulf: format 4, rules 3 (ADR-0124).
enum class CellularLivesProfile : std::uint8_t { offers, engulf };
struct CellularLivesConfig {
biology::CellularArea area{};
std::uint64_t tick{};
@@ -117,7 +128,7 @@ class CellularLives {
public:
[[nodiscard]] static std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
create(const PrimitiveLives& opening, std::unique_ptr<biology::CellularHabitat> habitat,
CellularLivesConfig config);
CellularLivesConfig config, CellularLivesProfile profile = CellularLivesProfile::offers);
CellularLives(const CellularLives&) = delete;
CellularLives& operator=(const CellularLives&) = delete;
~CellularLives();
+1 -1
View File
@@ -543,7 +543,7 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
const auto life =
std::ranges::find(predecessor.lives(), action.account, &CellularOwnedLife::account);
if (life == predecessor.lives().end() ||
(predecessor.format_version() != cellular_lives_revision_format))
(predecessor.format_version() < cellular_lives_revision_format))
return std::unexpected{CellularActionBlockError::mismatch};
const auto tick_index = static_cast<std::size_t>(action.tick - batch.header.begin_tick - 1);
const auto& mutations = batch.ticks[tick_index].mutations;
+90 -29
View File
@@ -13,11 +13,14 @@ namespace {
constexpr std::uint64_t cellular_lives_v1_magic = 0x3130564C43564541ULL; // AEVCLV01
constexpr std::uint64_t cellular_lives_v2_magic = 0x3230564C43564541ULL; // AEVCLV02
constexpr std::uint64_t cellular_lives_v3_magic = 0x3330564C43564541ULL; // AEVCLV03
constexpr std::uint64_t cellular_lives_v4_magic = 0x3430564C43564541ULL; // AEVCLV04
constexpr std::size_t cellular_lives_header_bytes = 212;
constexpr std::size_t cellular_site_bytes = 8;
constexpr std::size_t cellular_life_v1_bytes = 168;
constexpr std::size_t cellular_life_v2_bytes = 480;
constexpr std::size_t cellular_corpse_bytes = 100;
// Format 4: cause (1), 7 zero bytes and the predator's life id (8).
constexpr std::size_t cellular_corpse_v4_bytes = cellular_corpse_bytes + 16;
std::uint64_t checksum(std::span<const std::uint8_t> bytes) noexcept {
std::uint64_t value = 14695981039346656037ULL;
@@ -165,7 +168,7 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
const biology::CellularHabitat& habitat, std::span<const CellularOwnedLife> lives,
std::span<const CellularOwnedCorpse> corpses, const biology::LineageArchive& archive,
accounting::Inventory nursery, accounting::Inventory heat,
accounting::Inventory opening_total) {
accounting::Inventory opening_total, bool detritus_rules = false) {
const auto& map = habitat.config();
if (world == 0 || region == 0 || frame == 0 || nursery_config.world != world ||
nursery_config.region != region || nursery_config.frame != frame ||
@@ -263,9 +266,15 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
corpse.position.x_um > config.area.width_um - corpse.extent_um ||
corpse.position.y_um > config.area.height_um - corpse.extent_um)
return std::unexpected{CellularLivesError::invalid_life};
for (std::size_t channel = 0; channel < corpse.inventory.matter.size(); ++channel)
if (corpse.inventory.matter[channel].value < budget->body.matter[channel].value)
if (detritus_rules) {
// Rules 3 (ADR-0124): the inventory became detritus or the predator's.
if (corpse.inventory != accounting::Inventory{})
return std::unexpected{CellularLivesError::conservation};
} else {
for (std::size_t channel = 0; channel < corpse.inventory.matter.size(); ++channel)
if (corpse.inventory.matter[channel].value < budget->body.matter[channel].value)
return std::unexpected{CellularLivesError::conservation};
}
life_ids.push_back(corpse.life_id);
}
std::ranges::sort(life_ids);
@@ -314,8 +323,8 @@ CellularLives::~CellularLives() = default;
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
CellularLives::create(const PrimitiveLives& opening,
std::unique_ptr<biology::CellularHabitat> habitat,
CellularLivesConfig config) {
std::unique_ptr<biology::CellularHabitat> habitat, CellularLivesConfig config,
CellularLivesProfile profile) {
if (!habitat)
return std::unexpected{CellularLivesError::invalid_config};
auto nursery_config = opening.config();
@@ -382,10 +391,14 @@ CellularLives::create(const PrimitiveLives& opening,
const auto world = nursery_config.world;
const auto region = nursery_config.region;
const auto frame = nursery_config.frame;
auto state = std::make_unique<State>(world, region, frame, config, std::move(nursery_config),
std::move(habitat), std::move(lives),
std::vector<CellularOwnedCorpse>{}, archive, nursery, heat,
opening_total, *current);
const bool engulf = profile == CellularLivesProfile::engulf;
if (engulf)
archive.upgrade_to_revision_format(); // Rules 3 regions carry genome revisions.
auto state = std::make_unique<State>(
world, region, frame, config, std::move(nursery_config), std::move(habitat),
std::move(lives), std::vector<CellularOwnedCorpse>{}, archive, nursery, heat, opening_total,
*current, engulf ? cellular_lives_engulf_format : cellular_lives_format,
engulf ? cellular_lives_engulf_rules : cellular_lives_rules);
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
}
@@ -450,8 +463,10 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
const auto life_bytes = state_->format_version == cellular_lives_legacy_format
? cellular_life_v1_bytes
: cellular_life_v2_bytes;
const bool causes = state_->format_version == cellular_lives_engulf_format;
const auto corpse_bytes = causes ? cellular_corpse_v4_bytes : cellular_corpse_bytes;
const auto total_bytes = cellular_lives_header_bytes + cellular_site_bytes * site_count +
life_bytes * life_count + cellular_corpse_bytes * corpse_count +
life_bytes * life_count + corpse_bytes * corpse_count +
habitat.size() + archive.size() + 8;
if (total_bytes > max_cellular_lives_bytes ||
habitat.size() > biology::max_cellular_habitat_bytes ||
@@ -466,6 +481,7 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
const auto magic =
state_->format_version == cellular_lives_legacy_format ? cellular_lives_v1_magic
: state_->format_version == cellular_lives_revision_format ? cellular_lives_v3_magic
: state_->format_version == cellular_lives_engulf_format ? cellular_lives_v4_magic
: cellular_lives_v2_magic;
out.put(magic);
out.put(state_->format_version, 4);
@@ -550,6 +566,11 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
out.put(corpse.growth.damage_per_thousand, 4);
out.put(corpse.extent_um, 4);
out.inventory(corpse.inventory);
if (causes) {
out.put(static_cast<std::uint8_t>(corpse.cause), 1);
out.zeros(7);
out.put(corpse.predator_life);
}
}
out.raw(habitat);
out.raw(archive);
@@ -728,9 +749,10 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
state_->region, state_->frame);
if (!habitat)
return std::unexpected{CellularLivesError::habitat};
const auto current = validate_state(
state_->world, state_->region, state_->frame, state_->config, nursery_config, **habitat,
lives, state_->corpses, archive, nursery, heat, state_->opening_total);
const auto current =
validate_state(state_->world, state_->region, state_->frame, state_->config, nursery_config,
**habitat, lives, state_->corpses, archive, nursery, heat,
state_->opening_total, state_->rules_version == cellular_lives_engulf_rules);
if (!current)
return std::unexpected{current.error()};
@@ -760,9 +782,13 @@ 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;
const bool revision_version = magic == cellular_lives_v3_magic &&
format_version == cellular_lives_revision_format &&
rules_version == cellular_lives_rules;
const bool engulf_version = magic == cellular_lives_v4_magic &&
format_version == cellular_lives_engulf_format &&
rules_version == cellular_lives_engulf_rules;
const bool revision_version =
engulf_version ||
(magic == cellular_lives_v3_magic && format_version == cellular_lives_revision_format &&
rules_version == cellular_lives_rules);
const bool mutation_version = offer_version || revision_version;
if (!legacy && !mutation_version)
return std::unexpected{CellularLivesError::version};
@@ -796,8 +822,9 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
const auto nursery = in.inventory();
const auto heat = in.inventory();
const auto life_bytes = legacy ? cellular_life_v1_bytes : cellular_life_v2_bytes;
const auto corpse_bytes = engulf_version ? cellular_corpse_v4_bytes : cellular_corpse_bytes;
const auto expected_size = cellular_lives_header_bytes + cellular_site_bytes * site_count +
life_bytes * life_count + cellular_corpse_bytes * corpse_count +
life_bytes * life_count + corpse_bytes * corpse_count +
habitat_size + archive_size + 8;
if (source == 0 || expected_size != bytes.size())
return std::unexpected{CellularLivesError::format};
@@ -887,6 +914,20 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
corpse.growth.damage_per_thousand = static_cast<std::uint32_t>(in.get(4));
corpse.extent_um = static_cast<std::uint32_t>(in.get(4));
corpse.inventory = in.inventory();
if (engulf_version) {
// Rules 3: a known cause, a predator exactly when engulfed, and no inventory
// (it became detritus or the predator's).
const auto cause = in.get(1);
const auto padding = in.get(7);
corpse.predator_life = in.get();
corpse.cause = static_cast<biology::CellularDeathCause>(cause);
const bool engulfed = corpse.cause == biology::CellularDeathCause::engulfed;
if (padding != 0 ||
(corpse.cause != biology::CellularDeathCause::starved && !engulfed) ||
engulfed != (corpse.predator_life != 0) || corpse.predator_life == corpse.life_id ||
corpse.inventory != accounting::Inventory{})
return std::unexpected{CellularLivesError::noncanonical};
}
corpses.push_back(corpse);
}
const auto habitat_payload = in.raw(static_cast<std::size_t>(habitat_size));
@@ -938,7 +979,7 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
}
const auto current =
validate_state(saved_world, saved_region, saved_frame, config, nursery_config, **habitat,
lives, corpses, *archive, nursery, heat, opening_total);
lives, corpses, *archive, nursery, heat, opening_total, engulf_version);
if (!current)
return std::unexpected{current.error()};
@@ -974,8 +1015,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
ordered[i].life_id != state_->lives[i].identity.life)
return std::unexpected{CellularLivesError::invalid_intents};
if (!selections.empty() && state_->format_version != cellular_lives_revision_format)
if (!selections.empty() && state_->format_version < cellular_lives_revision_format)
return std::unexpected{CellularLivesError::version};
const bool engulf_rules = state_->rules_version == cellular_lives_engulf_rules;
for (std::size_t i = 0; i < selections.size(); ++i) {
const auto& selection = selections[i];
if (selection.life_id == 0 || selection.event_index == 0 || selection.offer_tick == 0 ||
@@ -1013,6 +1055,12 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
budget_for(state_->archive, life, state_->config.ambient_temperature_millikelvin);
if (!budget)
return std::unexpected{budget.error()};
const auto genome = state_->archive.find(life.identity.genome);
if (!genome)
return std::unexpected{CellularLivesError::archive};
const auto membrane = genome->parameter(biology::Capability::membrane);
if (!membrane)
return std::unexpected{CellularLivesError::biology};
inputs.push_back({life.identity.life,
life.position,
budget->phenotype.extent,
@@ -1020,10 +1068,12 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
life.body,
life.reserve,
{},
*budget});
*budget,
*membrane,
life.source});
}
auto proposal = biology::propose_cellular_region_step(state_->config.tick, state_->config.area,
inputs, *state_->habitat);
inputs, *state_->habitat, {engulf_rules});
if (!proposal)
return std::unexpected{CellularLivesError::region_step};
@@ -1098,7 +1148,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
return std::unexpected{corpse_budget.error()};
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});
corpse_budget->phenotype.extent, dead.inventory,
engulf_rules ? dead.cause : biology::CellularDeathCause::unrecorded,
engulf_rules ? dead.predator_id : 0});
next_lives.erase(found);
}
std::vector<CellularMutationExecution> mutation_results;
@@ -1155,15 +1207,23 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
return std::unexpected{CellularLivesError::habitat};
found->stock = update.stock;
}
// Rules 3 detritus at empty cells becomes new patches; create() revalidates the map.
for (const auto& made : proposal->new_patches) {
const auto at = std::ranges::lower_bound(habitat_config.patches, made.address, {},
[](const auto& patch) { return patch.address; });
if (at != habitat_config.patches.end() && at->address == made.address)
return std::unexpected{CellularLivesError::habitat};
habitat_config.patches.insert(at, made);
}
auto next_habitat = biology::CellularHabitat::create(std::move(habitat_config));
if (!next_habitat)
return std::unexpected{CellularLivesError::habitat};
const auto total =
validate_state(state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin},
state_->nursery_config, **next_habitat, next_lives, next_corpses,
next_archive, state_->nursery, next_heat, state_->opening_total);
const auto total = validate_state(
state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin},
state_->nursery_config, **next_habitat, next_lives, next_corpses, next_archive,
state_->nursery, next_heat, state_->opening_total, engulf_rules);
if (!total)
return std::unexpected{total.error()};
@@ -1182,7 +1242,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
[](const CellularLifeIntent& value) { return value.life_id; });
feedback.push_back({result.life_id, proposal->end_tick, result.candidate.reserve_after,
result.candidate.maintenance_cost, result.candidate.movement_cost,
result.candidate.movement_status, result.candidate.intake_status});
result.candidate.movement_status, result.candidate.intake_status,
result.engulf, result.prey_id});
if (input == ordered.end() || input->life_id != result.life_id)
return std::unexpected{CellularLivesError::invalid_intents};
}
@@ -85,7 +85,7 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
return left.action_id < right.action_id;
});
if (!mutations.empty() && state.format_version() != cellular_lives_revision_format)
if (!mutations.empty() && state.format_version() < cellular_lives_revision_format)
return std::unexpected{CellularSessionBatchError::mutation};
prepared.intents.mutations.reserve(mutations.size());
prepared.mutation_actions.reserve(mutations.size());
+83 -1
View File
@@ -548,6 +548,87 @@ void owner_advances_and_closes_death_atomically() {
CHECK((*terminal_recovery)->heat() == owner.heat());
CHECK((*terminal_recovery)->archive().organism(101) == owner.archive().organism(101));
}
// ADR-0124 rules 3: engulf intents resolve, starvation leaves detritus, corpses keep a cause.
void rules_three_owner_resolves_engulf_and_detritus() {
auto primitive = PrimitiveLives::create({92, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
CHECK(primitive);
LifeRequest request{};
request.account.back() = 1;
request.action = 1;
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
request.account.back() = 2;
CHECK((*primitive)->spawn(request, {2, 102, 202, 302, {1}}));
evo::biology::CellularHabitatConfig habitat_config{
92, 1, 7, 3'000, 2'000, {{{0, 0}, 29, {{10}, {{{10}, {10}, {10}, {10}}}}}}};
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::engulf);
CHECK(created);
auto& owner = **created;
CHECK(owner.format_version() == cellular_lives_engulf_format &&
owner.rules_version() == cellular_lives_engulf_rules &&
owner.archive().format_version() == evo::biology::lineage_archive_revision_format);
// Equal founders touching at an edge: neither is 1.5x the other.
evo::biology::CellularStepIntent engulf{};
engulf.engulf = true;
const std::array hunt{CellularLifeIntent{1, engulf}, CellularLifeIntent{2, {}}};
const auto hunted = owner.advance_tick(hunt);
CHECK(hunted && owner.lives().size() == 2);
CHECK(owner.last_tick_feedback()[0].engulf ==
evo::biology::CellularEngulfStatus::no_eligible_prey &&
owner.last_tick_feedback()[1].engulf ==
evo::biology::CellularEngulfStatus::not_requested);
// An engulf intent with an intake target is refused as a whole tick.
auto both = engulf;
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);
const auto patch_before = owner.habitat().patches()[0].stock;
std::size_t steps{};
while (!owner.lives().empty() && steps < 2'000) {
std::vector<CellularLifeIntent> idle;
for (const auto& life : owner.lives())
idle.push_back({life.identity.life, {}});
const auto advanced = owner.advance_tick(idle);
if (!advanced)
std::fprintf(stderr, "rules 3 idle tick %zu refused: %d\n", steps,
static_cast<int>(advanced.error()));
CHECK(advanced);
CHECK(owner.current_total() == owner.opening_total());
++steps;
}
CHECK(owner.lives().empty() && owner.corpses().size() == 2);
for (const auto& corpse : owner.corpses())
CHECK(corpse.cause == evo::biology::CellularDeathCause::starved &&
corpse.predator_life == 0 && corpse.inventory == Inventory{});
// Both founders died inside the (0, 0) cell, so their whole inventories joined that patch.
CHECK(owner.habitat().patches().size() == 1);
CHECK(owner.habitat().patches()[0].stock.matter[0].value >
patch_before.matter[0].value + 2 * founder_price(1).matter[0].value / 2);
const auto saved = owner.snapshot();
auto recovered = CellularLives::restore(saved, 92, 1, 7, owner.tick());
CHECK(recovered && (*recovered)->snapshot() == saved &&
std::ranges::equal((*recovered)->corpses(), owner.corpses()));
// A corpse cause outside the closed set, or a predator on a starvation corpse, is refused.
const auto corpse_at = saved.size() - 8 - owner.habitat().snapshot().size() -
owner.archive().encode().size() - std::size_t{2} * 116;
auto bad_cause = saved;
bad_cause[corpse_at + 100] = 7;
refresh_checksum(bad_cause);
CHECK(CellularLives::restore(bad_cause, 92, 1, 7, owner.tick()).error() ==
CellularLivesError::noncanonical);
auto bad_predator = saved;
bad_predator[corpse_at + 108] = 1;
refresh_checksum(bad_predator);
CHECK(CellularLives::restore(bad_predator, 92, 1, 7, owner.tick()).error() ==
CellularLivesError::noncanonical);
}
} // namespace
int main() {
@@ -556,7 +637,8 @@ int main() {
cellular_profile_migration_is_explicit_and_no_tick();
retained_feeding_earns_a_persistent_mutation_offer();
owner_advances_and_closes_death_atomically();
std::puts("PASS cellular lives: feeding, tick ownership and terminal closure");
rules_three_owner_resolves_engulf_and_detritus();
std::puts("PASS cellular lives: feeding, tick ownership, terminal closure, rules 3");
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;