From 7c16a13dd9674b855b71c7febe58fe5bdd09bbfe Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 14 Oct 2026 15:39:35 -0400 Subject: [PATCH] Show what a mutation costs and why an engulf failed After the first M11.9 playtest (ADR-0129 amendment): each offered candidate now carries its funded cost to the cell, construction energy and matter per channel, so the client can grey out what the reserve cannot pay; a candidate is affordable by that cost exactly when the owner would fund it. A failed engulf now reports no contact, prey too large, or membrane too thick. The v10 candidate record grows to 64 bytes, so v10 clients must be rebuilt. Co-Authored-By: Claude Opus 5.5 --- apps/evo-server/cellular_bridge.hpp | 13 ++++-- .../region/dev-session-route/listener.yaml | 2 +- .../0129-cellular-readable-play-signals.md | 14 +++++++ docs/engineering/M11_8_DELIVERY_PLAN.md | 17 ++++++-- docs/engineering/VALIDATION.md | 13 ++++++ include/evo/biology/cellular_region_step.hpp | 8 +++- include/evo/network/session_protocol.hpp | 11 ++++- include/evo/server/cellular_region_host.hpp | 7 ++-- .../session-v10-cellular-mutation-action.md | 7 ++-- src/biology/cellular_region_step.cpp | 18 ++++++-- src/network/protocol/session_protocol.cpp | 26 ++++++++---- src/server/cellular_region_host.cpp | 42 +++++++++++++++---- tests/cellular_intent_protocol_tests.cpp | 10 +++-- tests/cellular_lives_tests.cpp | 2 +- tests/cellular_publication_tests.cpp | 16 ++++++- tests/cellular_region_step_tests.cpp | 7 +++- 16 files changed, 172 insertions(+), 41 deletions(-) diff --git a/apps/evo-server/cellular_bridge.hpp b/apps/evo-server/cellular_bridge.hpp index 7514c4d..1062481 100644 --- a/apps/evo-server/cellular_bridge.hpp +++ b/apps/evo-server/cellular_bridge.hpp @@ -262,7 +262,7 @@ class CellularBridge { view.patches.push_back(visible); } (void)sessions_->send_cellular_perception(network::AccountId{life.account}, view); - send_offer(life, tick); + send_offer(state, life, tick); } std::erase_if(offers_, [&](const SentOffer& sent) { return std::ranges::find(state.lives(), sent.account, @@ -306,6 +306,12 @@ class CellularBridge { return network::CellularEngulfResult::no_eligible_prey; case biology::CellularEngulfStatus::unsupported: return network::CellularEngulfResult::unsupported; + case biology::CellularEngulfStatus::no_contact: + return network::CellularEngulfResult::no_contact; + case biology::CellularEngulfStatus::prey_too_large: + return network::CellularEngulfResult::prey_too_large; + case biology::CellularEngulfStatus::membrane_too_thick: + return network::CellularEngulfResult::membrane_too_thick; } return network::CellularEngulfResult::not_reported; } @@ -325,7 +331,8 @@ class CellularBridge { } // 11.4d: the owner's outstanding offer is sent reliably when it changes or the owner's // session changes; an empty view clears an offer that was consumed. - void send_offer(const server::CellularOwnedLife& life, std::uint64_t tick) { + void send_offer(const server::CellularLives& state, const server::CellularOwnedLife& life, + std::uint64_t tick) { const network::AccountId account{life.account}; const auto session = sessions_->holder(account); const auto& progress = life.mutation; @@ -337,7 +344,7 @@ class CellularBridge { return; if (!session || (!progress.offer && sent == offers_.end())) return; // Nothing to show, or no one to show it to. - if (!sessions_->send_mutation_offer(account, server::offer_view(life, tick))) + if (!sessions_->send_mutation_offer(account, server::offer_view(state, life, tick))) return; // Not a v10 owner (or the stream refused): retried on a later tick. if (sent != offers_.end()) *sent = current; diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index e69e191..f797556 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-20261014T170921-95733:1792008561"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261014T193935-75798:1792017575"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/docs/adr/0129-cellular-readable-play-signals.md b/docs/adr/0129-cellular-readable-play-signals.md index 7f3598d..b286882 100644 --- a/docs/adr/0129-cellular-readable-play-signals.md +++ b/docs/adr/0129-cellular-readable-play-signals.md @@ -31,3 +31,17 @@ simply cleared. Wildlife and players already share one replicated presentation. The client can say why a cell died and what a bud or engulf attempt did, without inferring it from a vanished view. v1-v9 are unchanged. + +## Amendment (2026-10-14, after the first M11.9 playtest) + +- Each offered candidate also carries its cost to this cell: the construction + energy and the matter per channel its funded transition takes from the reserve + (ADR-0118). The client compares it with the reserve in the diagnostics to grey out + what the cell cannot afford. The cost is fixed for the offer (its context is), and + a candidate is affordable by the shown cost exactly when the owner would fund it. + Candidates that only shed or reshape may cost nothing. The candidate record grows + from 24 to 64 bytes; v10 clients must be rebuilt. +- The engulf result says why nothing was taken: 5 no other cell touching, 6 every + touching cell too large even with the thinnest membrane, 7 a touching cell small + enough but defended by its membrane. Value 3 (no eligible prey) is no longer sent. + Who is engulfed is unchanged. diff --git a/docs/engineering/M11_8_DELIVERY_PLAN.md b/docs/engineering/M11_8_DELIVERY_PLAN.md index 936088d..3f544e1 100644 --- a/docs/engineering/M11_8_DELIVERY_PLAN.md +++ b/docs/engineering/M11_8_DELIVERY_PLAN.md @@ -19,12 +19,23 @@ server and protocol signals it needs. Contract: | Restart | A new life request after death (ADR-0127) | | Shared presentation | Players and wildlife replicate through the same organism presentation; suspended cells are not replicated (ADR-0128) | -## Remaining (maintainer) +## Client integration (2026-10-14) -The engineering client's HUD, death and restart screens, offer chooser, bud -control, accessibility and the first-session observation checks. +The engineering client now selects v10 and exposes the owner mutation offer, +engulf and bud controls, reserve/tick feedback, death cause and a new-life request. +Discrete requests retain their identity through reconnect, with explicit unresolved +outcomes. The UI adds a responsive cellular HUD and dark teal theme using the +existing toolkit/font. See [CLIENT](CLIENT.md) for operation and protocol limits. + +Human accessibility/hardware checks and first-session/repeated-life observations +remain. Existing v10 signals do not provide detailed engulf refusals, full mutation +prices, or historical death/result recovery across every server restart. ## Progress - 2026-10-14: server and protocol signals implemented and tested (codec and QUIC delivery tests). +- 2026-10-14 (after the first playtest): each offered candidate carries its cost to + the cell (energy and matter per channel) so the client can grey out unaffordable + choices, and a failed engulf says why (no contact, too large, membrane). The + candidate record is now 64 bytes; v10 clients need rebuilding. diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 9356f14..8ef9ddb 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -7481,3 +7481,16 @@ postgres attempt failed only in the ASan pass at `region upgrade test line 197` re-run passed. The DEV overlay now serves region 100/4 with the `cellular-v4` opening (ADR-0123 note). Executed locally: `deploy-policy-check.py` (0 failures), `deploy-policy-selftest.py` (46 cases) and `ops-lib-check.sh`. + +## 2026-10-14 — offer costs and engulf reasons (CI pending) + +ADR-0129 amendment: offered candidates carry their funded cost to the cell (64-byte +candidate records), and engulf results distinguish no contact, prey too large and +membrane too thick. Tests: the region step reports each reason; the codec round- +trips costs; the PostgreSQL host test checks that a candidate is affordable by its +shown cost exactly when `fund_mutation` succeeds against the cell's reserve. + +Executed locally: MSVC Debug 69/69, network 75/75, client-network protocol/QUIC/ +session/cellular 15/15 (`evo-client.exe` was in use and not relinked); the WSL +PostgreSQL C++ suite; g++-14 `-Werror -Wshadow` and clang-tidy-19 on the changed +sources and server main; clang-format 19.1.5. diff --git a/include/evo/biology/cellular_region_step.hpp b/include/evo/biology/cellular_region_step.hpp index 5c7fd9c..507fa61 100644 --- a/include/evo/biology/cellular_region_step.hpp +++ b/include/evo/biology/cellular_region_step.hpp @@ -40,8 +40,12 @@ struct CellularLifeStepInput { enum class CellularEngulfStatus : std::uint8_t { not_requested, engulfed, // Took the reported prey. - no_eligible_prey, // Nothing in contact was small enough. - unsupported // Rules 2 region: the intent had no effect. + no_eligible_prey, // Nothing in contact was small enough (no longer reported). + unsupported, // Rules 2 region: the intent had no effect. + // Why nothing was taken (reporting only; who is engulfed is unchanged): + no_contact, // No other cell touched it. + prey_too_large, // Touching cells were too large even with the thinnest membrane. + membrane_too_thick // A touching cell was small enough, but its membrane defended it. }; struct CellularLifeStepResult { std::uint64_t life_id{}; diff --git a/include/evo/network/session_protocol.hpp b/include/evo/network/session_protocol.hpp index d6e386a..59f3307 100644 --- a/include/evo/network/session_protocol.hpp +++ b/include/evo/network/session_protocol.hpp @@ -209,6 +209,10 @@ struct CellularOfferedCandidate { std::uint8_t capability{}, effect{}; // biology::Capability, biology::MutationEffect. std::uint32_t parameter{}; // The successor's value; zero when shed. std::uint64_t maintenance{}, total_mass{}; + // What choosing it costs this cell from its reserve (ADR-0129): construction energy and + // the matter each channel must add. Compare with the reserve in the diagnostics. + std::uint64_t cost_energy_pj{}; + std::array cost_matter_fg{}; friend bool operator==(const CellularOfferedCandidate&, const CellularOfferedCandidate&) = default; }; @@ -253,8 +257,11 @@ enum class CellularEngulfResult : std::uint8_t { not_reported, not_requested, engulfed, - no_eligible_prey, - unsupported + no_eligible_prey, // No longer sent: one of the three reasons below is. + unsupported, + no_contact, // No other cell touched it. + prey_too_large, // Touching cells were too large even with the thinnest membrane. + membrane_too_thick // A touching cell was small enough, but its membrane defended it. }; enum class CellularBudOutcome : std::uint8_t { not_reported, diff --git a/include/evo/server/cellular_region_host.hpp b/include/evo/server/cellular_region_host.hpp index 3766fd0..2e36519 100644 --- a/include/evo/server/cellular_region_host.hpp +++ b/include/evo/server/cellular_region_host.hpp @@ -69,9 +69,10 @@ struct CellularMutationReply { [[nodiscard]] network::AdmitStatus admit_status(CellularMutationAdmission admission) noexcept; [[nodiscard]] network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) noexcept; // The owner's view of a life's outstanding offer at `tick` (11.4d): candidates in their -// stable operator order; no offer gives an empty view that clears the client's. -[[nodiscard]] network::CellularMutationOffer offer_view(const CellularOwnedLife& life, - std::uint64_t tick); +// stable operator order, each with its cost to this cell from its reserve (ADR-0129); no offer +// gives an empty view that clears the client's. +[[nodiscard]] network::CellularMutationOffer +offer_view(const CellularLives& state, const CellularOwnedLife& life, std::uint64_t tick); // Single-writer profile-4 authority. The caller supplies a complete bounded trace; // the host replays it from its recovered state and advances only on a confirmed head. diff --git a/schemas/network/session-v10-cellular-mutation-action.md b/schemas/network/session-v10-cellular-mutation-action.md index bbe34f2..8d31bfc 100644 --- a/schemas/network/session-v10-cellular-mutation-action.md +++ b/schemas/network/session-v10-cellular-mutation-action.md @@ -44,7 +44,7 @@ final outcome. The `ActionOutcome` is `committed` when applied and 11.4d adds the owner's outstanding offer as a reliable-stream message, type 26, sent only to the owning account's v10 session when the offer or the session -changes. Payload, little-endian: a 40-byte prefix followed by `count` 24-byte +changes. Payload, little-endian: a 40-byte prefix followed by `count` 64-byte candidates. | Payload offset | Size | Field | @@ -66,6 +66,8 @@ Each candidate: | 4 | 4 | the successor's capability value; zero when shed | | 8 | 8 | the successor's maintenance | | 16 | 8 | the successor's total mass | +| 24 | 8 | cost to this cell: construction energy (ADR-0129) | +| 32 | 32 | cost to this cell: matter per channel (carbon, nitrogen, phosphorus, other) | A message with no candidates clears the client's offer and must carry zero event and offer tick; one with candidates must name a nonzero life, event and offer @@ -74,8 +76,7 @@ tick. Types 25 and 26 are not decoded under versions 1–9. ## v10 tick effects and type 27 (ADR-0129) In a v10 cellular perception the diagnostics byte at payload offset 77 is the -engulf result (0 not reported, 1 not requested, 2 engulfed, 3 no eligible prey, -4 unsupported) and byte 78 the bud result (0 not reported, 1 not requested, +engulf result (0 not reported, 1 not requested, 2 engulfed, 3 no eligible prey (no\nlonger sent), 4 unsupported, 5 no contact, 6 prey too large, 7 membrane too thick) and byte 78 the bud result (0 not reported, 1 not requested, 2 budded, 3 not able, 4 insufficient funding, 5 no placement); bytes 79-81 stay zero, and both results are zero without tick effects. v9 keeps bytes 77-81 zero. diff --git a/src/biology/cellular_region_step.cpp b/src/biology/cellular_region_step.cpp index 23bc2ea..4164b28 100644 --- a/src/biology/cellular_region_step.cpp +++ b/src/biology/cellular_region_step.cpp @@ -177,18 +177,30 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area, continue; auto& predator = candidate.lives[p]; const auto* hunter = survivors[p]; + // Why nothing was taken, for the owner: no contact, too large, or membrane. + bool membrane_blocked = false; + predator.engulf = CellularEngulfStatus::no_contact; for (std::size_t q = 0; q < candidate.lives.size(); ++q) { if (q == p || taken[q]) continue; const auto* prey = survivors[q]; const auto& prey_step = candidate.lives[q].candidate; if (!cellular_footprints_contact(predator.candidate.position, hunter->extent_um, - prey_step.position, prey->extent_um) || - !product_at_least(hunter->budget.phenotype.total_mass, 1'000, + prey_step.position, prey->extent_um)) + continue; + if (!product_at_least(hunter->budget.phenotype.total_mass, 1'000, prey->budget.phenotype.total_mass, cellular_engulf_ratio_milli_per_membrane_um * - prey->membrane_um)) + prey->membrane_um)) { + membrane_blocked = + membrane_blocked || + product_at_least(hunter->budget.phenotype.total_mass, 1'000, + prey->budget.phenotype.total_mass, + cellular_engulf_ratio_milli_per_membrane_um); + predator.engulf = membrane_blocked ? CellularEngulfStatus::membrane_too_thick + : CellularEngulfStatus::prey_too_large; continue; + } // The prey's whole inventory moves once: body matter and its post-step reserve. accounting::Inventory whole = prey_step.reserve_after; if (!add(whole, prey->body)) diff --git a/src/network/protocol/session_protocol.cpp b/src/network/protocol/session_protocol.cpp index 5300ade..b9c78d9 100644 --- a/src/network/protocol/session_protocol.cpp +++ b/src/network/protocol/session_protocol.cpp @@ -16,7 +16,9 @@ constexpr std::size_t cellular_action_bytes = (std::size_t{4} * 8) + 4 + 1 + 3 + constexpr std::size_t cellular_mutation_action_bytes = (std::size_t{7} * 8) + 2 + 6; constexpr std::size_t cellular_offer_prefix_bytes = (std::size_t{4} * 8) + 2 + 6; constexpr std::size_t cellular_life_ended_bytes = (std::size_t{2} * 8) + 1 + 7; -constexpr std::size_t cellular_offered_candidate_bytes = 2 + 1 + 1 + 4 + 8 + 8; +// A candidate: operator, capability, effect, parameter, maintenance, mass, then its cost to +// this cell (energy and four matter channels, ADR-0129). +constexpr std::size_t cellular_offered_candidate_bytes = 2 + 1 + 1 + 4 + 8 + 8 + 8 + (4 * 8); constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2; constexpr std::size_t cellular_diagnostics_bytes = 64; constexpr std::size_t cellular_perception_v9_prefix_bytes = @@ -61,7 +63,7 @@ bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) { const auto intake = static_cast(diagnostics.intake); if (movement > static_cast(CellularMovementResult::insufficient_energy) || intake > static_cast(CellularIntakeResult::out_of_contact) || - diagnostics.engulf > CellularEngulfResult::unsupported || + diagnostics.engulf > CellularEngulfResult::membrane_too_thick || diagnostics.bud > CellularBudOutcome::no_placement) return false; if (!diagnostics.has_tick_effects) @@ -325,6 +327,9 @@ std::vector encode_session(const SessionMessage& message, std::uin put(out, candidate.parameter, 4); put(out, candidate.maintenance, 8); put(out, candidate.total_mass, 8); + put(out, candidate.cost_energy_pj, 8); + for (const auto matter : candidate.cost_matter_fg) + put(out, matter, 8); } return out; } @@ -666,10 +671,17 @@ std::expected decode_session(std::span(get(payload, at, 2)), - payload[at + 2], payload[at + 3], - static_cast(get(payload, at + 4, 4)), - get(payload, at + 8, 8), get(payload, at + 16, 8)}); + CellularOfferedCandidate candidate{static_cast(get(payload, at, 2)), + payload[at + 2], + payload[at + 3], + static_cast(get(payload, at + 4, 4)), + get(payload, at + 8, 8), + get(payload, at + 16, 8), + get(payload, at + 24, 8), + {}}; + for (std::size_t channel = 0; channel < candidate.cost_matter_fg.size(); ++channel) + candidate.cost_matter_fg[channel] = get(payload, at + 32 + channel * 8, 8); + m.candidates.push_back(candidate); } if (!valid_offer(m)) return std::unexpected(SessionCodecError::invalid_value); @@ -708,7 +720,7 @@ std::expected decode_session(std::span static_cast(CellularEngulfResult::unsupported) || + payload[77] > static_cast(CellularEngulfResult::membrane_too_thick) || payload[78] > static_cast(CellularBudOutcome::no_placement)) return std::unexpected(SessionCodecError::invalid_value); if (wire_version == session_protocol_v10) { diff --git a/src/server/cellular_region_host.cpp b/src/server/cellular_region_host.cpp index ad6c491..008899f 100644 --- a/src/server/cellular_region_host.cpp +++ b/src/server/cellular_region_host.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace evo::server { @@ -102,19 +103,46 @@ network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) noe mutation.tick, mutation.commit_sequence}; } -network::CellularMutationOffer offer_view(const CellularOwnedLife& life, std::uint64_t tick) { +network::CellularMutationOffer offer_view(const CellularLives& state, const CellularOwnedLife& life, + std::uint64_t tick) { network::CellularMutationOffer view{tick, life.identity.life, 0, 0, {}}; const auto& offer = life.mutation.offer; if (!offer) return view; view.event_index = life.mutation.event_index; view.offer_tick = life.mutation.offer_tick; - for (const auto& candidate : offer->candidates) - if (view.candidates.size() < network::max_cellular_offered_candidates) - view.candidates.push_back( - {candidate.operator_id, static_cast(candidate.target), - static_cast(candidate.effect), candidate.parameter, - candidate.maintenance, candidate.total_mass}); + const auto genome = state.archive().find(life.identity.genome); + // The cost does not depend on the reserve: fund against an ample one and read what it + // takes. The owner funds the real choice against the real reserve. + constexpr std::uint64_t ample = std::uint64_t{1} << 60U; + const accounting::Inventory unlimited{ + {ample}, + {accounting::Femtograms{ample}, accounting::Femtograms{ample}, + accounting::Femtograms{ample}, accounting::Femtograms{ample}}}; + constexpr auto probe_identity = std::numeric_limits::max(); + for (const auto& candidate : offer->candidates) { + if (view.candidates.size() >= network::max_cellular_offered_candidates) + break; + network::CellularOfferedCandidate shown{candidate.operator_id, + static_cast(candidate.target), + static_cast(candidate.effect), + candidate.parameter, + candidate.maintenance, + candidate.total_mass, + 0, + {}}; + if (genome) { + const auto funded = + biology::fund_mutation(*genome, offer->context, *offer, candidate.operator_id, + probe_identity, probe_identity, unlimited); + if (funded) { + shown.cost_energy_pj = funded->intake.energy.value; + for (std::size_t channel = 0; channel < shown.cost_matter_fg.size(); ++channel) + shown.cost_matter_fg[channel] = funded->intake.matter[channel].value; + } + } + view.candidates.push_back(shown); + } std::ranges::sort(view.candidates, {}, &network::CellularOfferedCandidate::operator_id); return view; } diff --git a/tests/cellular_intent_protocol_tests.cpp b/tests/cellular_intent_protocol_tests.cpp index 1c95538..85a2516 100644 --- a/tests/cellular_intent_protocol_tests.cpp +++ b/tests/cellular_intent_protocol_tests.cpp @@ -332,10 +332,14 @@ void v10_effects_and_life_end_are_owner_only() { // 11.4d: the owner's offer lists unranked candidates in operator order with their tradeoffs. void v10_mutation_offer_is_owner_only_and_canonical() { - const CellularMutationOffer offer{ - 120, 9, 2, 100, {{3, 1, 0, 40, 150'000, 9'000}, {7, 2, 2, 1, 160'000, 9'500}}}; + const CellularMutationOffer offer{120, + 9, + 2, + 100, + {{3, 1, 0, 40, 150'000, 9'000, 1'200, {300, 70, 35, 140}}, + {7, 2, 2, 1, 160'000, 9'500, 2'400, {600, 140, 70, 280}}}}; const auto bytes = encode_session(SessionMessage{offer}); - CHECK(bytes.size() == session_header_bytes + 40 + (std::size_t{2} * 24)); + CHECK(bytes.size() == session_header_bytes + 40 + (std::size_t{2} * 64)); std::uint16_t version{}; const auto decoded = decode_session(bytes, &version); CHECK(decoded && version == session_protocol_v10); diff --git a/tests/cellular_lives_tests.cpp b/tests/cellular_lives_tests.cpp index 2b642fc..a315c4a 100644 --- a/tests/cellular_lives_tests.cpp +++ b/tests/cellular_lives_tests.cpp @@ -581,7 +581,7 @@ void rules_three_owner_resolves_engulf_and_detritus() { 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 && + evo::biology::CellularEngulfStatus::prey_too_large && owner.last_tick_feedback()[1].engulf == evo::biology::CellularEngulfStatus::not_requested); // An engulf intent with an intake target is refused as a whole tick. diff --git a/tests/cellular_publication_tests.cpp b/tests/cellular_publication_tests.cpp index f98d05b..b7baa63 100644 --- a/tests/cellular_publication_tests.cpp +++ b/tests/cellular_publication_tests.cpp @@ -572,12 +572,26 @@ void cellular_host_admits_mutation_choices() { offer.candidates.front().operator_id}; const auto next = host->state()->tick() + 1; // 11.4d: the owner's view lists the same candidates in operator order. - const auto view = offer_view(life, next - 1); + const auto view = offer_view(*host->state(), life, next - 1); CHECK(view.life_identity == life_id && view.event_index == choice.event_index && view.offer_tick == choice.offer_tick && view.candidates.size() == offer.candidates.size() && std::ranges::is_sorted(view.candidates, {}, &evo::network::CellularOfferedCandidate::operator_id)); + // ADR-0129: a candidate is affordable by its shown cost exactly when the owner would + // fund it from the current reserve. + const auto parent_genome = host->state()->archive().find(life.identity.genome); + CHECK(parent_genome.has_value()); + for (const auto& shown : view.candidates) { + bool covered = life.reserve.energy.value >= shown.cost_energy_pj; + for (std::size_t c = 0; c < shown.cost_matter_fg.size(); ++c) + covered = covered && life.reserve.matter[c].value >= shown.cost_matter_fg[c]; + const auto funded = parent_genome + ? fund_mutation(*parent_genome, offer.context, offer, + shown.operator_id, 999'999, 999'999, life.reserve) + : std::unexpected{MutationError::development}; + CHECK(covered == funded.has_value()); + } auto wrong = choice; wrong.operator_id = 0xFFFF; CHECK(host->select_mutation(account, control->generation, 31, wrong).status == diff --git a/tests/cellular_region_step_tests.cpp b/tests/cellular_region_step_tests.cpp index 3c1c433..f67d9b8 100644 --- a/tests/cellular_region_step_tests.cpp +++ b/tests/cellular_region_step_tests.cpp @@ -170,17 +170,20 @@ void size_and_membrane_contest_engulfment() { const std::array equal{cell(1, {0, 0}, 1'000, 1, true), cell(2, {0, 0}, 1'000, 1, false)}; const auto same = propose_cellular_region_step(4, {3'000, 2'000}, equal, *map, rules3); CHECK(same && same->lives.size() == 2 && same->starved.empty()); - CHECK(same->lives[0].engulf == CellularEngulfStatus::no_eligible_prey); + // The owner learns why: equal sizes are too large whatever the membrane. + CHECK(same->lives[0].engulf == CellularEngulfStatus::prey_too_large); // A 3 um membrane raises the required ratio to 4.5; a 3x predator fails. const std::array armored{cell(1, {0, 0}, 3'000, 1, true), cell(2, {0, 0}, 1'000, 3, false)}; const auto defended = propose_cellular_region_step(4, {3'000, 2'000}, armored, *map, rules3); CHECK(defended && defended->lives.size() == 2 && defended->starved.empty()); + // 3x would beat a 1 um membrane, so the membrane is the reason. + CHECK(defended->lives[0].engulf == CellularEngulfStatus::membrane_too_thick); // Out of contact: no prey, whatever the size. const std::array apart{cell(1, {0, 0}, 9'000, 1, true), cell(2, {2'000, 0}, 1'000, 1, false)}; const auto distant = propose_cellular_region_step(4, {3'000, 2'000}, apart, *map, rules3); CHECK(distant && distant->lives.size() == 2 && - distant->lives[0].engulf == CellularEngulfStatus::no_eligible_prey); + distant->lives[0].engulf == CellularEngulfStatus::no_contact); } void a_taken_cell_neither_acts_nor_is_taken_twice() {