Show what a mutation costs and why an engulf failed
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (deploy) (push) Successful in 4m7s
Foundation / checks (tsan) (push) Successful in 9m49s
Foundation / checks (client) (push) Successful in 17m12s
Foundation / checks (network) (push) Successful in 19m34s
Foundation / checks (checks) (push) Successful in 43m5s
Foundation / checks (postgres) (push) Successful in 44m57s
Foundation / server-image (push) Successful in 31s
Foundation / postgres-tools (push) Successful in 1m13s
Foundation / image (push) Successful in 3m24s
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (deploy) (push) Successful in 4m7s
Foundation / checks (tsan) (push) Successful in 9m49s
Foundation / checks (client) (push) Successful in 17m12s
Foundation / checks (network) (push) Successful in 19m34s
Foundation / checks (checks) (push) Successful in 43m5s
Foundation / checks (postgres) (push) Successful in 44m57s
Foundation / server-image (push) Successful in 31s
Foundation / postgres-tools (push) Successful in 1m13s
Foundation / image (push) Successful in 3m24s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -262,7 +262,7 @@ class CellularBridge {
|
|||||||
view.patches.push_back(visible);
|
view.patches.push_back(visible);
|
||||||
}
|
}
|
||||||
(void)sessions_->send_cellular_perception(network::AccountId{life.account}, view);
|
(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) {
|
std::erase_if(offers_, [&](const SentOffer& sent) {
|
||||||
return std::ranges::find(state.lives(), sent.account,
|
return std::ranges::find(state.lives(), sent.account,
|
||||||
@@ -306,6 +306,12 @@ class CellularBridge {
|
|||||||
return network::CellularEngulfResult::no_eligible_prey;
|
return network::CellularEngulfResult::no_eligible_prey;
|
||||||
case biology::CellularEngulfStatus::unsupported:
|
case biology::CellularEngulfStatus::unsupported:
|
||||||
return network::CellularEngulfResult::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;
|
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
|
// 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.
|
// 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 network::AccountId account{life.account};
|
||||||
const auto session = sessions_->holder(account);
|
const auto session = sessions_->holder(account);
|
||||||
const auto& progress = life.mutation;
|
const auto& progress = life.mutation;
|
||||||
@@ -337,7 +344,7 @@ class CellularBridge {
|
|||||||
return;
|
return;
|
||||||
if (!session || (!progress.offer && sent == offers_.end()))
|
if (!session || (!progress.offer && sent == offers_.end()))
|
||||||
return; // Nothing to show, or no one to show it to.
|
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.
|
return; // Not a v10 owner (or the stream refused): retried on a later tick.
|
||||||
if (sent != offers_.end())
|
if (sent != offers_.end())
|
||||||
*sent = current;
|
*sent = current;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- {name: REGION_SESSION, value: "dev"}
|
- {name: REGION_SESSION, value: "dev"}
|
||||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
- {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"}
|
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||||
ports:
|
ports:
|
||||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||||
|
|||||||
@@ -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
|
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.
|
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.
|
||||||
|
|||||||
@@ -19,12 +19,23 @@ server and protocol signals it needs. Contract:
|
|||||||
| Restart | A new life request after death (ADR-0127) |
|
| 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) |
|
| 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
|
The engineering client now selects v10 and exposes the owner mutation offer,
|
||||||
control, accessibility and the first-session observation checks.
|
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
|
## Progress
|
||||||
|
|
||||||
- 2026-10-14: server and protocol signals implemented and tested (codec and QUIC
|
- 2026-10-14: server and protocol signals implemented and tested (codec and QUIC
|
||||||
delivery tests).
|
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.
|
||||||
|
|||||||
@@ -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`
|
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),
|
opening (ADR-0123 note). Executed locally: `deploy-policy-check.py` (0 failures),
|
||||||
`deploy-policy-selftest.py` (46 cases) and `ops-lib-check.sh`.
|
`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.
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ struct CellularLifeStepInput {
|
|||||||
enum class CellularEngulfStatus : std::uint8_t {
|
enum class CellularEngulfStatus : std::uint8_t {
|
||||||
not_requested,
|
not_requested,
|
||||||
engulfed, // Took the reported prey.
|
engulfed, // Took the reported prey.
|
||||||
no_eligible_prey, // Nothing in contact was small enough.
|
no_eligible_prey, // Nothing in contact was small enough (no longer reported).
|
||||||
unsupported // Rules 2 region: the intent had no effect.
|
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 {
|
struct CellularLifeStepResult {
|
||||||
std::uint64_t life_id{};
|
std::uint64_t life_id{};
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ struct CellularOfferedCandidate {
|
|||||||
std::uint8_t capability{}, effect{}; // biology::Capability, biology::MutationEffect.
|
std::uint8_t capability{}, effect{}; // biology::Capability, biology::MutationEffect.
|
||||||
std::uint32_t parameter{}; // The successor's value; zero when shed.
|
std::uint32_t parameter{}; // The successor's value; zero when shed.
|
||||||
std::uint64_t maintenance{}, total_mass{};
|
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<std::uint64_t, 4> cost_matter_fg{};
|
||||||
friend bool operator==(const CellularOfferedCandidate&,
|
friend bool operator==(const CellularOfferedCandidate&,
|
||||||
const CellularOfferedCandidate&) = default;
|
const CellularOfferedCandidate&) = default;
|
||||||
};
|
};
|
||||||
@@ -253,8 +257,11 @@ enum class CellularEngulfResult : std::uint8_t {
|
|||||||
not_reported,
|
not_reported,
|
||||||
not_requested,
|
not_requested,
|
||||||
engulfed,
|
engulfed,
|
||||||
no_eligible_prey,
|
no_eligible_prey, // No longer sent: one of the three reasons below is.
|
||||||
unsupported
|
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 {
|
enum class CellularBudOutcome : std::uint8_t {
|
||||||
not_reported,
|
not_reported,
|
||||||
|
|||||||
@@ -69,9 +69,10 @@ struct CellularMutationReply {
|
|||||||
[[nodiscard]] network::AdmitStatus admit_status(CellularMutationAdmission admission) noexcept;
|
[[nodiscard]] network::AdmitStatus admit_status(CellularMutationAdmission admission) noexcept;
|
||||||
[[nodiscard]] network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) 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
|
// 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.
|
// stable operator order, each with its cost to this cell from its reserve (ADR-0129); no offer
|
||||||
[[nodiscard]] network::CellularMutationOffer offer_view(const CellularOwnedLife& life,
|
// gives an empty view that clears the client's.
|
||||||
std::uint64_t tick);
|
[[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;
|
// 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.
|
// the host replays it from its recovered state and advances only on a confirmed head.
|
||||||
|
|||||||
@@ -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,
|
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
|
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.
|
candidates.
|
||||||
|
|
||||||
| Payload offset | Size | Field |
|
| Payload offset | Size | Field |
|
||||||
@@ -66,6 +66,8 @@ Each candidate:
|
|||||||
| 4 | 4 | the successor's capability value; zero when shed |
|
| 4 | 4 | the successor's capability value; zero when shed |
|
||||||
| 8 | 8 | the successor's maintenance |
|
| 8 | 8 | the successor's maintenance |
|
||||||
| 16 | 8 | the successor's total mass |
|
| 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
|
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
|
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)
|
## v10 tick effects and type 27 (ADR-0129)
|
||||||
|
|
||||||
In a v10 cellular perception the diagnostics byte at payload offset 77 is the
|
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,
|
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,
|
||||||
4 unsupported) 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
|
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.
|
zero, and both results are zero without tick effects. v9 keeps bytes 77-81 zero.
|
||||||
|
|
||||||
|
|||||||
@@ -177,18 +177,30 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
|||||||
continue;
|
continue;
|
||||||
auto& predator = candidate.lives[p];
|
auto& predator = candidate.lives[p];
|
||||||
const auto* hunter = survivors[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) {
|
for (std::size_t q = 0; q < candidate.lives.size(); ++q) {
|
||||||
if (q == p || taken[q])
|
if (q == p || taken[q])
|
||||||
continue;
|
continue;
|
||||||
const auto* prey = survivors[q];
|
const auto* prey = survivors[q];
|
||||||
const auto& prey_step = candidate.lives[q].candidate;
|
const auto& prey_step = candidate.lives[q].candidate;
|
||||||
if (!cellular_footprints_contact(predator.candidate.position, hunter->extent_um,
|
if (!cellular_footprints_contact(predator.candidate.position, hunter->extent_um,
|
||||||
prey_step.position, prey->extent_um) ||
|
prey_step.position, prey->extent_um))
|
||||||
!product_at_least(hunter->budget.phenotype.total_mass, 1'000,
|
continue;
|
||||||
|
if (!product_at_least(hunter->budget.phenotype.total_mass, 1'000,
|
||||||
prey->budget.phenotype.total_mass,
|
prey->budget.phenotype.total_mass,
|
||||||
cellular_engulf_ratio_milli_per_membrane_um *
|
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;
|
continue;
|
||||||
|
}
|
||||||
// The prey's whole inventory moves once: body matter and its post-step reserve.
|
// The prey's whole inventory moves once: body matter and its post-step reserve.
|
||||||
accounting::Inventory whole = prey_step.reserve_after;
|
accounting::Inventory whole = prey_step.reserve_after;
|
||||||
if (!add(whole, prey->body))
|
if (!add(whole, prey->body))
|
||||||
|
|||||||
@@ -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_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_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_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_perception_prefix_bytes = 8 + 8 + 2;
|
||||||
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
||||||
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||||
@@ -61,7 +63,7 @@ bool valid_diagnostics(const CellularLifeDiagnostics& diagnostics) {
|
|||||||
const auto intake = static_cast<std::uint8_t>(diagnostics.intake);
|
const auto intake = static_cast<std::uint8_t>(diagnostics.intake);
|
||||||
if (movement > static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
|
if (movement > static_cast<std::uint8_t>(CellularMovementResult::insufficient_energy) ||
|
||||||
intake > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact) ||
|
intake > static_cast<std::uint8_t>(CellularIntakeResult::out_of_contact) ||
|
||||||
diagnostics.engulf > CellularEngulfResult::unsupported ||
|
diagnostics.engulf > CellularEngulfResult::membrane_too_thick ||
|
||||||
diagnostics.bud > CellularBudOutcome::no_placement)
|
diagnostics.bud > CellularBudOutcome::no_placement)
|
||||||
return false;
|
return false;
|
||||||
if (!diagnostics.has_tick_effects)
|
if (!diagnostics.has_tick_effects)
|
||||||
@@ -325,6 +327,9 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
|||||||
put(out, candidate.parameter, 4);
|
put(out, candidate.parameter, 4);
|
||||||
put(out, candidate.maintenance, 8);
|
put(out, candidate.maintenance, 8);
|
||||||
put(out, candidate.total_mass, 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;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -666,10 +671,17 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
|||||||
return std::unexpected(SessionCodecError::invalid_value);
|
return std::unexpected(SessionCodecError::invalid_value);
|
||||||
for (std::size_t i = 0; i < count; ++i) {
|
for (std::size_t i = 0; i < count; ++i) {
|
||||||
const auto at = cellular_offer_prefix_bytes + i * cellular_offered_candidate_bytes;
|
const auto at = cellular_offer_prefix_bytes + i * cellular_offered_candidate_bytes;
|
||||||
m.candidates.push_back({static_cast<std::uint16_t>(get(payload, at, 2)),
|
CellularOfferedCandidate candidate{static_cast<std::uint16_t>(get(payload, at, 2)),
|
||||||
payload[at + 2], payload[at + 3],
|
payload[at + 2],
|
||||||
static_cast<std::uint32_t>(get(payload, at + 4, 4)),
|
payload[at + 3],
|
||||||
get(payload, at + 8, 8), get(payload, at + 16, 8)});
|
static_cast<std::uint32_t>(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))
|
if (!valid_offer(m))
|
||||||
return std::unexpected(SessionCodecError::invalid_value);
|
return std::unexpected(SessionCodecError::invalid_value);
|
||||||
@@ -708,7 +720,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
|||||||
std::ranges::any_of(payload.subspan(wire_version == session_protocol_v10 ? 79 : 77,
|
std::ranges::any_of(payload.subspan(wire_version == session_protocol_v10 ? 79 : 77,
|
||||||
wire_version == session_protocol_v10 ? 3 : 5),
|
wire_version == session_protocol_v10 ? 3 : 5),
|
||||||
[](std::uint8_t value) { return value != 0; }) ||
|
[](std::uint8_t value) { return value != 0; }) ||
|
||||||
payload[77] > static_cast<std::uint8_t>(CellularEngulfResult::unsupported) ||
|
payload[77] > static_cast<std::uint8_t>(CellularEngulfResult::membrane_too_thick) ||
|
||||||
payload[78] > static_cast<std::uint8_t>(CellularBudOutcome::no_placement))
|
payload[78] > static_cast<std::uint8_t>(CellularBudOutcome::no_placement))
|
||||||
return std::unexpected(SessionCodecError::invalid_value);
|
return std::unexpected(SessionCodecError::invalid_value);
|
||||||
if (wire_version == session_protocol_v10) {
|
if (wire_version == session_protocol_v10) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <limits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace evo::server {
|
namespace evo::server {
|
||||||
@@ -102,19 +103,46 @@ network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) noe
|
|||||||
mutation.tick, mutation.commit_sequence};
|
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, {}};
|
network::CellularMutationOffer view{tick, life.identity.life, 0, 0, {}};
|
||||||
const auto& offer = life.mutation.offer;
|
const auto& offer = life.mutation.offer;
|
||||||
if (!offer)
|
if (!offer)
|
||||||
return view;
|
return view;
|
||||||
view.event_index = life.mutation.event_index;
|
view.event_index = life.mutation.event_index;
|
||||||
view.offer_tick = life.mutation.offer_tick;
|
view.offer_tick = life.mutation.offer_tick;
|
||||||
for (const auto& candidate : offer->candidates)
|
const auto genome = state.archive().find(life.identity.genome);
|
||||||
if (view.candidates.size() < network::max_cellular_offered_candidates)
|
// The cost does not depend on the reserve: fund against an ample one and read what it
|
||||||
view.candidates.push_back(
|
// takes. The owner funds the real choice against the real reserve.
|
||||||
{candidate.operator_id, static_cast<std::uint8_t>(candidate.target),
|
constexpr std::uint64_t ample = std::uint64_t{1} << 60U;
|
||||||
static_cast<std::uint8_t>(candidate.effect), candidate.parameter,
|
const accounting::Inventory unlimited{
|
||||||
candidate.maintenance, candidate.total_mass});
|
{ample},
|
||||||
|
{accounting::Femtograms{ample}, accounting::Femtograms{ample},
|
||||||
|
accounting::Femtograms{ample}, accounting::Femtograms{ample}}};
|
||||||
|
constexpr auto probe_identity = std::numeric_limits<std::uint64_t>::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<std::uint8_t>(candidate.target),
|
||||||
|
static_cast<std::uint8_t>(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);
|
std::ranges::sort(view.candidates, {}, &network::CellularOfferedCandidate::operator_id);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
// 11.4d: the owner's offer lists unranked candidates in operator order with their tradeoffs.
|
||||||
void v10_mutation_offer_is_owner_only_and_canonical() {
|
void v10_mutation_offer_is_owner_only_and_canonical() {
|
||||||
const CellularMutationOffer offer{
|
const CellularMutationOffer offer{120,
|
||||||
120, 9, 2, 100, {{3, 1, 0, 40, 150'000, 9'000}, {7, 2, 2, 1, 160'000, 9'500}}};
|
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});
|
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{};
|
std::uint16_t version{};
|
||||||
const auto decoded = decode_session(bytes, &version);
|
const auto decoded = decode_session(bytes, &version);
|
||||||
CHECK(decoded && version == session_protocol_v10);
|
CHECK(decoded && version == session_protocol_v10);
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ void rules_three_owner_resolves_engulf_and_detritus() {
|
|||||||
const auto hunted = owner.advance_tick(hunt);
|
const auto hunted = owner.advance_tick(hunt);
|
||||||
CHECK(hunted && owner.lives().size() == 2);
|
CHECK(hunted && owner.lives().size() == 2);
|
||||||
CHECK(owner.last_tick_feedback()[0].engulf ==
|
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 ==
|
owner.last_tick_feedback()[1].engulf ==
|
||||||
evo::biology::CellularEngulfStatus::not_requested);
|
evo::biology::CellularEngulfStatus::not_requested);
|
||||||
// An engulf intent with an intake target is refused as a whole tick.
|
// An engulf intent with an intake target is refused as a whole tick.
|
||||||
|
|||||||
@@ -572,12 +572,26 @@ void cellular_host_admits_mutation_choices() {
|
|||||||
offer.candidates.front().operator_id};
|
offer.candidates.front().operator_id};
|
||||||
const auto next = host->state()->tick() + 1;
|
const auto next = host->state()->tick() + 1;
|
||||||
// 11.4d: the owner's view lists the same candidates in operator order.
|
// 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 &&
|
CHECK(view.life_identity == life_id && view.event_index == choice.event_index &&
|
||||||
view.offer_tick == choice.offer_tick &&
|
view.offer_tick == choice.offer_tick &&
|
||||||
view.candidates.size() == offer.candidates.size() &&
|
view.candidates.size() == offer.candidates.size() &&
|
||||||
std::ranges::is_sorted(view.candidates, {},
|
std::ranges::is_sorted(view.candidates, {},
|
||||||
&evo::network::CellularOfferedCandidate::operator_id));
|
&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;
|
auto wrong = choice;
|
||||||
wrong.operator_id = 0xFFFF;
|
wrong.operator_id = 0xFFFF;
|
||||||
CHECK(host->select_mutation(account, control->generation, 31, wrong).status ==
|
CHECK(host->select_mutation(account, control->generation, 31, wrong).status ==
|
||||||
|
|||||||
@@ -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 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);
|
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 && 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.
|
// 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 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);
|
const auto defended = propose_cellular_region_step(4, {3'000, 2'000}, armored, *map, rules3);
|
||||||
CHECK(defended && defended->lives.size() == 2 && defended->starved.empty());
|
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.
|
// 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 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);
|
const auto distant = propose_cellular_region_step(4, {3'000, 2'000}, apart, *map, rules3);
|
||||||
CHECK(distant && distant->lives.size() == 2 &&
|
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() {
|
void a_taken_cell_neither_acts_nor_is_taken_twice() {
|
||||||
|
|||||||
Reference in New Issue
Block a user