Preserve terminal inventories and add bounded decomposition
This commit is contained in:
+3
-1
@@ -46,7 +46,7 @@ this proof. Production indexing awaits actual interaction workloads.
|
||||
| 2.1 Ratify accounting units and ledger | accounting/ledger.*, ENERGY_MODEL, ADR-0024 | M1, units ADR | Exact local units/ranges, finite inventories and atomic ordered transfers | Unit-type separation, rollback/overflow/replay, million-transaction independent balance checks | Mistaking conservation for valid biology |
|
||||
| 2.2 Add abiotic source and producer | processes/producer.*, ADR-0025 | 2.1 | Finite source capture, whole growth recipes, carried rate remainders and atomic owned ledger | Closed-box audit, independent fractional reference, finite-resource and arithmetic limits | Confusing synthetic process with organism biology |
|
||||
| 2.3 Add consumer intentions and ingestion | processes/feeding.*, ADR-0026 | 2.2 | Shared ledger and atomic tick; capped ordered feeding with heat/waste outputs | Predation, contention, rollback, terminal depletion, replay/conservation | Fixture rules becoming gameplay; spatial validation remains separate |
|
||||
| 2.4 Death and decomposition | biology/lifecycle, ecology | 2.3 | Active capability ends; corpse pool transfers conserved nutrients | Death terminality, decomposition limits, ledger audit | Nutrients double counted |
|
||||
| 2.4 Death and decomposition | processes/feeding.*, ADR-0027 | 2.3 | Terminal events preserve corpse inventory; corpses/waste share decay budget | Terminality, rollback, cap sharing, mixed channels, nutrient regrowth and conservation | Confusing fixture transfer rules with microbial chemistry |
|
||||
| 2.5 Reproduction and wildlife identity | biology/reproduction, genome identity | 2.4, reproduction contract | Sufficient resources required; child consumes parent budget | Insufficient investment, unique ID and ancestry tests | Free offspring or implicit player ownership |
|
||||
| 2.6 Long-run ecosystem fixture | apps/evo-sim, tests/ecosystem, metrics | 2.2–2.5 | Producer→consumer→death→nutrients cycle; report over million ticks | Many seeds, nonnegative balances, measured extinction/diversity | Passing invariants despite uninteresting ecology |
|
||||
|
||||
@@ -62,6 +62,8 @@ the existing fixture is not itself a complete ecosystem or an organism model.
|
||||
M2.3 now supplies this bounded shared ownership and ingestion fixture. M2.4 must
|
||||
retain remaining inventory on death and implement explicit corpse/decomposition
|
||||
flows, rather than relying on M2.3's zero-inventory depletion trigger.
|
||||
M2.4 now implements that terminal-inventory and bounded-return contract. M2.5
|
||||
must settle offspring identity and funding before adding reproductive operations.
|
||||
|
||||
## M3 — Genome v0.1
|
||||
|
||||
|
||||
+12
-5
@@ -7,7 +7,7 @@ persistent simulation server. The founding vision remains unchanged.
|
||||
## Completed implementation
|
||||
|
||||
- Vision, architectural pillars, risks, open-question register, architecture
|
||||
diagrams, biological contracts, engineering constitution and 26 ADRs.
|
||||
diagrams, biological contracts, engineering constitution and 27 ADRs.
|
||||
Proposed/deferred choices remain distinct from accepted proof decisions.
|
||||
- M0–M4 task breakdowns with dependencies, acceptance evidence and risks,
|
||||
plus M5–M14 gates in [ROADMAP.md](ROADMAP.md).
|
||||
@@ -61,8 +61,8 @@ for the bounded proof; the general production ECS remains a later measured choic
|
||||
|
||||
| Priority | Work | Completion evidence |
|
||||
|---|---|---|
|
||||
| 1 | M2.4 death and decomposition contract | Terminal activity with remaining inventory, corpse ownership, bounded decomposition and nutrient return |
|
||||
| 2 | M2.5–2.6 first headless energy cycle | Funded reproduction and complete producer/consumer/decomposition cycle; seeded million-tick ecosystem evidence |
|
||||
| 1 | M2.5 funded reproduction contract | Atomic parent/offspring investment, non-reused identity and explicit ancestry without inherited account power |
|
||||
| 2 | M2.6 headless energy-cycle fixture | Complete capture/feeding/reproduction/decomposition cycle, seeded million-tick ecosystem runs and diagnostics |
|
||||
| Delivery gate | Add/update the dev workload when a deployable increment needs it; Argo is ready | Observe Job/pod completion separately from image publication; no World0 changes |
|
||||
|
||||
M1.6 now implements [the sequential scheduler contract](architecture/SCHEDULER_CONTRACT.md):
|
||||
@@ -115,8 +115,15 @@ predation, resource contention, terminal actors, batch order/replay and conserva
|
||||
No spatial/perception validation,
|
||||
organism biology, persistent checkpoint or deployment is included in this fixture.
|
||||
Native Release, analysis, ASan and formatting passed; all four Gitea run 1415
|
||||
jobs passed. The next increment is M2.4 death with remaining inventory and
|
||||
bounded decomposition into nutrients.
|
||||
jobs passed.
|
||||
|
||||
M2.4 adds terminal events with preserved corpse inventory, followed by a shared
|
||||
bounded decomposition phase. Energy moves to heat, elemental matter returns to
|
||||
nutrients, and next-tick producer growth can use those nutrients. Corpses retain
|
||||
their process ID and cannot resume activity. Invalid ticks roll back death and
|
||||
decomposition with all earlier phases. Default zero decay preserves earlier
|
||||
fixture behavior. This is not death-cause biology, microbial chemistry, corpse
|
||||
scavenging, persistent lineage history or a database-backed world.
|
||||
|
||||
Before biology, resolve the relevant heredity and energetic contracts rather
|
||||
than treating proof particles as organisms. Exact game tick rate, NPC mutation,
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# ADR-0027: Terminal inventory ownership and bounded decomposition
|
||||
|
||||
## Status
|
||||
|
||||
Adopted for the M2.4 synthetic community fixture. No biological death cause,
|
||||
decomposer organism, biochemical reaction or live-world identity is selected.
|
||||
|
||||
## Context
|
||||
|
||||
M2.3 only deactivates targets completely consumed by feeding. Real terminal
|
||||
events can leave reserve and structure behind; removing that inventory would
|
||||
violate conservation. Nutrient return must have a finite per-tick bound.
|
||||
|
||||
## Decision
|
||||
|
||||
Extend `FeedingCommunity::advance` with an optional bounded list of trusted
|
||||
`TerminalEvent` facts (process ID only). They are host/system decisions, never
|
||||
client kill commands. Admit at most one per process, reject zero/unknown/duplicate
|
||||
or already inactive IDs, and apply them before producer activity. A terminated
|
||||
producer does not capture or grow in that tick. Existing feeding still rejects
|
||||
inactive actors and targets; scavenging is not added in this increment.
|
||||
|
||||
A dead process's existing ledger reservoir becomes its corpse compartment. There
|
||||
is no duplicate corpse inventory and no account ownership; the immutable process
|
||||
ID identifies the residual material. `corpse(id)` returns its current inventory
|
||||
by value, rejects active/unknown IDs, and returns zero after decomposition. IDs and
|
||||
terminal flags remain even when inventory is empty. There is no resurrection API.
|
||||
|
||||
Tick phases: terminal facts → producer activity → ordered feeding → decomposition
|
||||
→ atomic publish. Decomposition drains inactive process reservoirs in ascending
|
||||
process ID, then the waste reservoir. Each community has one configured inventory
|
||||
budget per tick, shared across all corpses and waste, independently per channel.
|
||||
Take min(remaining budget, available inventory). Energy goes only to heat;
|
||||
C/N/P/other matter goes unchanged to nutrients. No yield, energy reuse, reactants,
|
||||
fractional kinetics or invisible sink is claimed. Nutrients can fund growth next
|
||||
tick, not earlier in this same tick. Zero budgets disable the corresponding channel.
|
||||
|
||||
The cap defaults to zero to preserve M2.3 fixture behavior. Empty corpses do not
|
||||
consume budget or ledger actions. Unused budget expires; no backlog accumulates.
|
||||
Expose `last_decomposed()` as the committed inventory moved in that tick; it is
|
||||
diagnostic state, not an additional owned resource. It resets on each successful
|
||||
tick and remains unchanged on failed ticks.
|
||||
|
||||
All phases run on the existing private candidate. Invalid feeding after a death
|
||||
fact rolls back death, producer progress, transfers and diagnostics. Death facts
|
||||
are not idempotent acknowledgments: replay of a committed tick or a repeated death
|
||||
is rejected. Durable exactly-once history and snapshots remain separate work.
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
Copying into a corpse object risks double counting; moving into a new reservoir
|
||||
requires unnecessary allocation/identity lifecycle for this bounded fixture.
|
||||
Unbounded instant decay hides the ecological rate constraint. Per-corpse budgets
|
||||
scale throughput with corpse count; one shared budget makes this proof's bound
|
||||
explicit. A reaction solver requires reactants/stoichiometry not yet defined.
|
||||
|
||||
## Benefits
|
||||
|
||||
One owner for every residual quantity, terminal activity, exact conservation and
|
||||
a measurable upper bound on nutrient return. A complete return-to-producer path
|
||||
can now be tested without implementing reproduction.
|
||||
|
||||
## Costs
|
||||
|
||||
Dead process slots are retained. Oldest-ID priority may starve later corpses/waste;
|
||||
it is an experimental scheduling rule, not an ecological fairness decision.
|
||||
Per-element caps can change residual composition; they are not physical kinetics.
|
||||
|
||||
## Risks
|
||||
|
||||
Do not label this as microbial decomposition or use host terminal facts as a
|
||||
client-authorized action. Actual death, lineage history, corpse scavenging and
|
||||
decomposer capabilities need their own contracts. No synthetic actors seed World0.
|
||||
|
||||
## Consequences
|
||||
|
||||
Test death before producer activity, preserved corpse inventories, no dead actions,
|
||||
duplicate/stale events, rollback, budget sharing, zero/full caps, exact u64 limits,
|
||||
waste decay, returned nutrients funding later growth and repeated conservation.
|
||||
No state codec, PostgreSQL connection, renderer or deployment change.
|
||||
@@ -19,6 +19,7 @@ Each record has the eight required sections.
|
||||
0024 adopts finite, typed energy/matter inventory transfers for M2.1.
|
||||
0025 scopes finite capture, growth recipes and residual accounting for M2.2.
|
||||
0026 adds shared community ownership and bounded synthetic feeding for M2.3.
|
||||
0027 adds terminal inventory ownership and budgeted nutrient return for M2.4.
|
||||
|
||||
Every dependency adoption records exact version/commit and integrity hash,
|
||||
transitive license obligations, maintenance/security review, owner and removal
|
||||
|
||||
@@ -174,3 +174,31 @@ flowchart LR
|
||||
P -->|unassimilated energy| H[Heat]
|
||||
P -->|unassimilated matter| W[Waste inventory]
|
||||
```
|
||||
|
||||
## Implemented M2.4 terminal inventory and decomposition
|
||||
|
||||
[ADR-0027](../adr/0027-terminal-inventory-and-decomposition.md) extends community
|
||||
ticks with trusted terminal facts before producer activity. The dead process's
|
||||
existing inventory becomes its corpse; no extra copy is created or discarded.
|
||||
`corpse(id)` exposes a value only for inactive process IDs. Dead actors never
|
||||
capture, grow or feed again, and their identity remains after decomposition.
|
||||
|
||||
After feeding, inactive reservoirs in ID order and then waste share one configured
|
||||
per-tick inventory budget. Drained energy goes to heat and each elemental mass
|
||||
goes unchanged to nutrients. Zero caps disable channels. This is a synthetic
|
||||
transport model, not decomposition chemistry or an autonomous microbial lineage.
|
||||
Returned nutrients can fund producer growth next tick. Default caps are zero,
|
||||
preserving earlier fixture behavior; all new state participates in tick rollback.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[Active process inventory] -->|terminal state, same owner| C[Corpse inventory]
|
||||
C -->|bounded energy release| H[Heat]
|
||||
C -->|bounded elemental return| N[Nutrients]
|
||||
W[Waste] -->|remaining shared budget| N
|
||||
N -->|next tick growth| P[Living producer structure]
|
||||
```
|
||||
|
||||
Host terminal events do not define health, starvation, combat, age or player death
|
||||
causes. Corpse scavenging, live-world lineage history, persistence and reproduction
|
||||
remain outside this increment. No physical inventory disappears on death.
|
||||
|
||||
@@ -254,3 +254,20 @@ implemented. These are co-located synthetic process fixtures.
|
||||
passed all four jobs for source `b7dd466f57f385d6a8ffccfaa69f639077545587`:
|
||||
Linux checks, ECS regression, separate TSan and image smoke/publication.
|
||||
No deployment image pin was changed.
|
||||
|
||||
## M2.4 terminal inventory and decomposition (2026-09-20)
|
||||
|
||||
Native Release, analysis and MSVC ASan passed 8/8 CTests; formatting passed.
|
||||
Commands: `tools/windows-check.ps1 -Preset <release|analysis|asan> -Action check`
|
||||
and Release `-Action format`. Tests preserve corpse inventories on death, suppress
|
||||
producer activity immediately, reject repeated/invalid terminal events and roll
|
||||
back death with later invalid feeding. Sixteen seeds × 256 ticks compare a
|
||||
closed-form depletion reference, reversed terminal-event order, per-tick budgets,
|
||||
inventories and conservation. Additional cases cover shared corpse/waste limits,
|
||||
mixed and zero channel caps, u64-maximum inventories, diagnostic rollback, and
|
||||
returned nutrients funding producer structure on the next tick.
|
||||
|
||||
The existing feeding, standalone producer, ledger and particle tests pass unchanged.
|
||||
This does not validate reaction chemistry, actual death causes, corpse scavenging,
|
||||
serialized recovery, allocation-failure injection or persistent history. There is
|
||||
no deployment change. Linux CI is pending source push.
|
||||
|
||||
@@ -20,12 +20,19 @@ struct FeedReceipt {
|
||||
bool target_depleted;
|
||||
auto operator<=>(const FeedReceipt&) const = default;
|
||||
};
|
||||
struct TerminalEvent {
|
||||
std::uint32_t actor;
|
||||
};
|
||||
struct DecompositionConfig {
|
||||
accounting::Inventory per_tick_limit{};
|
||||
};
|
||||
enum class FeedingError : std::uint8_t {
|
||||
invalid_config,
|
||||
wrong_tick,
|
||||
invalid_batch,
|
||||
invalid_actor,
|
||||
inactive_actor,
|
||||
not_corpse,
|
||||
intake_limit,
|
||||
insufficient_inventory,
|
||||
accounting_failure
|
||||
@@ -37,9 +44,10 @@ class FeedingCommunity {
|
||||
[[nodiscard]] static std::expected<FeedingCommunity, FeedingError>
|
||||
create(ProducerConfig producer, accounting::Picojoules source,
|
||||
std::array<accounting::Femtograms, 4> nutrients,
|
||||
std::span<const ConsumerConfig> consumers);
|
||||
std::span<const ConsumerConfig> consumers, DecompositionConfig decomposition = {});
|
||||
[[nodiscard]] std::expected<std::vector<FeedReceipt>, FeedingError>
|
||||
advance(Tick target, std::span<const FeedIntent> inputs = {});
|
||||
advance(Tick target, std::span<const FeedIntent> inputs = {},
|
||||
std::span<const TerminalEvent> terminal_events = {});
|
||||
[[nodiscard]] std::span<const accounting::Inventory> balances() const noexcept {
|
||||
return producer_.balances();
|
||||
}
|
||||
@@ -48,12 +56,21 @@ class FeedingCommunity {
|
||||
}
|
||||
// Process IDs are one-based. Out-of-range is a query error, not an inactive actor.
|
||||
[[nodiscard]] std::expected<bool, FeedingError> active(std::uint32_t id) const noexcept;
|
||||
[[nodiscard]] std::expected<accounting::Inventory, FeedingError>
|
||||
corpse(std::uint32_t id) const noexcept;
|
||||
[[nodiscard]] accounting::Inventory last_decomposed() const noexcept {
|
||||
return last_decomposed_;
|
||||
}
|
||||
|
||||
private:
|
||||
FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers);
|
||||
FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers,
|
||||
DecompositionConfig decomposition);
|
||||
[[nodiscard]] std::expected<FeedReceipt, FeedingError> feed(const FeedIntent& input);
|
||||
[[nodiscard]] std::expected<void, FeedingError> decompose();
|
||||
ProducerProcess producer_;
|
||||
std::vector<ConsumerConfig> consumers_;
|
||||
std::vector<std::uint8_t> active_;
|
||||
DecompositionConfig decomposition_;
|
||||
accounting::Inventory last_decomposed_{};
|
||||
};
|
||||
} // namespace evo::processes
|
||||
|
||||
@@ -26,14 +26,16 @@ accounting::ReservoirId reservoir(std::uint32_t actor) noexcept {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
FeedingCommunity::FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers)
|
||||
FeedingCommunity::FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers,
|
||||
DecompositionConfig decomposition)
|
||||
: producer_{std::move(producer)}, consumers_{std::move(consumers)},
|
||||
active_(consumers_.size() + 1, 1) {}
|
||||
active_(consumers_.size() + 1, 1), decomposition_{decomposition} {}
|
||||
|
||||
std::expected<FeedingCommunity, FeedingError>
|
||||
FeedingCommunity::create(ProducerConfig producer, accounting::Picojoules source,
|
||||
std::array<accounting::Femtograms, 4> nutrients,
|
||||
std::span<const ConsumerConfig> consumers) {
|
||||
std::span<const ConsumerConfig> consumers,
|
||||
DecompositionConfig decomposition) {
|
||||
if (consumers.empty() || consumers.size() > max_consumers ||
|
||||
std::ranges::any_of(consumers,
|
||||
[](const auto& c) { return c.assimilation_per_thousand > 1000; })) {
|
||||
@@ -54,7 +56,8 @@ FeedingCommunity::create(ProducerConfig producer, accounting::Picojoules source,
|
||||
return std::unexpected{FeedingError::accounting_failure};
|
||||
}
|
||||
isolated->ledger_ = std::move(*ledger);
|
||||
return FeedingCommunity{std::move(*isolated), {consumers.begin(), consumers.end()}};
|
||||
return FeedingCommunity{
|
||||
std::move(*isolated), {consumers.begin(), consumers.end()}, decomposition};
|
||||
}
|
||||
|
||||
std::expected<bool, FeedingError> FeedingCommunity::active(std::uint32_t id) const noexcept {
|
||||
@@ -105,13 +108,69 @@ std::expected<FeedReceipt, FeedingError> FeedingCommunity::feed(const FeedIntent
|
||||
return FeedReceipt{input.sequence, assimilated, depleted};
|
||||
}
|
||||
|
||||
std::expected<accounting::Inventory, FeedingError>
|
||||
FeedingCommunity::corpse(std::uint32_t id) const noexcept {
|
||||
const auto alive = active(id);
|
||||
if (!alive) {
|
||||
return std::unexpected{alive.error()};
|
||||
}
|
||||
if (*alive) {
|
||||
return std::unexpected{FeedingError::not_corpse};
|
||||
}
|
||||
return balances()[reservoir(id).value - 1];
|
||||
}
|
||||
|
||||
std::expected<void, FeedingError> FeedingCommunity::decompose() {
|
||||
auto remaining = decomposition_.per_tick_limit;
|
||||
// Final iteration is waste, after all inactive process reservoirs.
|
||||
for (std::size_t index = 0; index <= active_.size(); ++index) {
|
||||
if (index < active_.size() && active_[index] != 0) {
|
||||
continue;
|
||||
}
|
||||
const auto from =
|
||||
index == active_.size()
|
||||
? accounting::ReservoirId{static_cast<std::uint32_t>(balances().size())}
|
||||
: reservoir(static_cast<std::uint32_t>(index + 1));
|
||||
const auto available = balances()[from.value - 1];
|
||||
accounting::Inventory heat{}, nutrients{};
|
||||
heat.energy.value = std::min(remaining.energy.value, available.energy.value);
|
||||
for (std::size_t channel = 0; channel < 4; ++channel) {
|
||||
nutrients.matter[channel].value =
|
||||
std::min(remaining.matter[channel].value, available.matter[channel].value);
|
||||
}
|
||||
if (heat == accounting::Inventory{} && nutrients == accounting::Inventory{}) {
|
||||
continue;
|
||||
}
|
||||
const std::array legs{accounting::Transfer{from, {4}, heat},
|
||||
accounting::Transfer{from, {2}, nutrients}};
|
||||
auto& ledger = producer_.ledger_;
|
||||
if (ledger.last_action() == std::numeric_limits<std::uint64_t>::max() ||
|
||||
!ledger.transfer(ledger.last_action() + 1, legs)) {
|
||||
return std::unexpected{FeedingError::accounting_failure};
|
||||
}
|
||||
remaining.energy.value -= heat.energy.value;
|
||||
for (std::size_t channel = 0; channel < 4; ++channel) {
|
||||
remaining.matter[channel].value -= nutrients.matter[channel].value;
|
||||
}
|
||||
}
|
||||
last_decomposed_.energy.value =
|
||||
decomposition_.per_tick_limit.energy.value - remaining.energy.value;
|
||||
for (std::size_t channel = 0; channel < 4; ++channel) {
|
||||
last_decomposed_.matter[channel].value =
|
||||
decomposition_.per_tick_limit.matter[channel].value - remaining.matter[channel].value;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::expected<std::vector<FeedReceipt>, FeedingError>
|
||||
FeedingCommunity::advance(Tick target, std::span<const FeedIntent> inputs) {
|
||||
FeedingCommunity::advance(Tick target, std::span<const FeedIntent> inputs,
|
||||
std::span<const TerminalEvent> terminal_events) {
|
||||
if (progress().tick.value == std::numeric_limits<std::uint64_t>::max() ||
|
||||
target.value != progress().tick.value + 1) {
|
||||
return std::unexpected{FeedingError::wrong_tick};
|
||||
}
|
||||
if (inputs.size() > max_consumers || active_.empty()) {
|
||||
if (inputs.size() > max_consumers || active_.empty() ||
|
||||
terminal_events.size() > active_.size()) {
|
||||
return std::unexpected{FeedingError::invalid_batch};
|
||||
}
|
||||
std::vector<FeedIntent> ordered{inputs.begin(), inputs.end()};
|
||||
@@ -127,6 +186,17 @@ FeedingCommunity::advance(Tick target, std::span<const FeedIntent> inputs) {
|
||||
previous = input.sequence;
|
||||
}
|
||||
auto candidate = *this;
|
||||
std::array<bool, max_consumers + 2> terminated{};
|
||||
for (const auto event : terminal_events) {
|
||||
if (event.actor == 0 || event.actor > active_.size() || terminated[event.actor]) {
|
||||
return std::unexpected{FeedingError::invalid_batch};
|
||||
}
|
||||
if (candidate.active_[event.actor - 1] == 0) {
|
||||
return std::unexpected{FeedingError::inactive_actor};
|
||||
}
|
||||
terminated[event.actor] = true;
|
||||
candidate.active_[event.actor - 1] = 0;
|
||||
}
|
||||
if (candidate.active_[0] != 0) {
|
||||
if (!candidate.producer_.advance(target)) {
|
||||
return std::unexpected{FeedingError::accounting_failure};
|
||||
@@ -143,6 +213,9 @@ FeedingCommunity::advance(Tick target, std::span<const FeedIntent> inputs) {
|
||||
}
|
||||
receipts.push_back(*result);
|
||||
}
|
||||
if (const auto result = candidate.decompose(); !result) {
|
||||
return std::unexpected{result.error()};
|
||||
}
|
||||
static_assert(std::is_nothrow_move_assignable_v<FeedingCommunity>);
|
||||
*this = std::move(candidate);
|
||||
return receipts;
|
||||
|
||||
@@ -111,6 +111,128 @@ void validation_and_rollback() {
|
||||
too_many.pop_back();
|
||||
CHECK(FeedingCommunity::create(producer(), {}, {}, too_many));
|
||||
}
|
||||
void corpse_preservation_and_rollback() {
|
||||
const std::array configs{ConsumerConfig{bundle(5), bundle(10), 1000}};
|
||||
auto community = FeedingCommunity::create(producer(), {100}, bundle(20).matter, configs);
|
||||
CHECK(community);
|
||||
CHECK(!community->corpse(0) && !community->corpse(1));
|
||||
CHECK(community->advance(evo::Tick{1}));
|
||||
const auto before = copy(*community);
|
||||
const auto progress = community->progress();
|
||||
const std::array deaths{TerminalEvent{1}, TerminalEvent{2}};
|
||||
const std::array bad_feed{FeedIntent{1, 2, 1, bundle(1)}};
|
||||
CHECK(!community->advance(evo::Tick{2}, bad_feed, deaths));
|
||||
CHECK(copy(*community) == before && community->progress() == progress);
|
||||
CHECK(*community->active(1) && *community->active(2));
|
||||
for (const auto actor : {0U, 3U}) {
|
||||
const std::array bad{TerminalEvent{actor}};
|
||||
CHECK(!community->advance(evo::Tick{2}, {}, bad));
|
||||
}
|
||||
const std::array duplicate{TerminalEvent{1}, TerminalEvent{1}};
|
||||
CHECK(!community->advance(evo::Tick{2}, {}, duplicate));
|
||||
const std::array excess{TerminalEvent{1}, TerminalEvent{2}, TerminalEvent{1}};
|
||||
CHECK(!community->advance(evo::Tick{2}, {}, excess));
|
||||
CHECK(community->advance(evo::Tick{2}, {}, deaths));
|
||||
CHECK(copy(*community) == before); // Death relabels ownership without losing inventory.
|
||||
CHECK(community->corpse(1) && *community->corpse(1) == before[2]);
|
||||
CHECK(community->corpse(2) && *community->corpse(2) == bundle(5));
|
||||
CHECK(community->last_decomposed() == Inventory{});
|
||||
const auto dead_progress = community->progress();
|
||||
CHECK(!community->advance(evo::Tick{3}, {}, deaths));
|
||||
CHECK(community->progress() == dead_progress && copy(*community) == before);
|
||||
CHECK(community->advance(evo::Tick{3}));
|
||||
CHECK(copy(*community) == before && !*community->active(1) && !*community->active(2));
|
||||
}
|
||||
void decomposition_reference() {
|
||||
for (std::uint64_t seed = 0; seed < 16; ++seed) {
|
||||
evo::Random random{seed};
|
||||
const auto opening = 1 + random.next() % 100;
|
||||
const auto cap = 1 + random.next() % 7;
|
||||
const std::array configs{ConsumerConfig{bundle(opening), {}, 0},
|
||||
ConsumerConfig{bundle(opening), {}, 0}};
|
||||
auto community = FeedingCommunity::create(producer(), {}, {}, configs, {bundle(cap)});
|
||||
CHECK(community);
|
||||
auto replay = *community;
|
||||
const auto total = sum(*community);
|
||||
const std::array deaths{TerminalEvent{2}, TerminalEvent{3}};
|
||||
const std::array reversed{TerminalEvent{3}, TerminalEvent{2}};
|
||||
std::uint64_t previous{};
|
||||
for (std::uint64_t tick = 1; tick <= 256; ++tick) {
|
||||
CHECK(community->advance(evo::Tick{tick}, {},
|
||||
tick == 1 ? std::span{deaths}
|
||||
: std::span<const TerminalEvent>{}));
|
||||
CHECK(
|
||||
replay.advance(evo::Tick{tick}, {},
|
||||
tick == 1 ? std::span{reversed} : std::span<const TerminalEvent>{}));
|
||||
const auto drained = std::min(tick * cap, 2 * opening);
|
||||
const auto first = opening - std::min(opening, drained);
|
||||
const auto second = 2 * opening - drained - first;
|
||||
CHECK(*community->corpse(2) == bundle(first));
|
||||
CHECK(*community->corpse(3) == bundle(second));
|
||||
CHECK(community->last_decomposed() == bundle(drained - previous));
|
||||
CHECK(community->balances()[1].matter == bundle(drained).matter);
|
||||
CHECK(community->balances()[3].energy.value == drained);
|
||||
CHECK(sum(*community) == total && copy(*community) == copy(replay));
|
||||
CHECK(community->progress() == replay.progress());
|
||||
CHECK(!*community->active(2) && !*community->active(3));
|
||||
previous = drained;
|
||||
}
|
||||
}
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
const std::array configs{ConsumerConfig{bundle(maximum), {}, 0}};
|
||||
auto extreme = FeedingCommunity::create(producer(), {}, {}, configs, {bundle(maximum)});
|
||||
CHECK(extreme);
|
||||
const std::array death{TerminalEvent{2}};
|
||||
CHECK(extreme->advance(evo::Tick{1}, {}, death));
|
||||
CHECK(*extreme->corpse(2) == Inventory{} && extreme->last_decomposed() == bundle(maximum));
|
||||
CHECK(sum(*extreme) == bundle(maximum));
|
||||
}
|
||||
void nutrient_return_and_waste() {
|
||||
const std::array configs{ConsumerConfig{bundle(1), bundle(10), 0}};
|
||||
auto community = FeedingCommunity::create(producer(), {100}, {}, configs, {bundle(1)});
|
||||
CHECK(community);
|
||||
const auto total = sum(*community);
|
||||
const std::array death{TerminalEvent{2}};
|
||||
CHECK(community->advance(evo::Tick{1}, {}, death));
|
||||
CHECK(community->balances()[2].matter == Inventory{}.matter);
|
||||
CHECK(community->balances()[1].matter == bundle(1).matter);
|
||||
CHECK(community->advance(evo::Tick{2}));
|
||||
CHECK(community->balances()[2].matter == bundle(1).matter);
|
||||
CHECK(community->balances()[1].matter == Inventory{}.matter);
|
||||
CHECK(sum(*community) == total && community->last_decomposed() == Inventory{});
|
||||
|
||||
const std::array feeder{ConsumerConfig{{}, bundle(10), 0}};
|
||||
auto waste = FeedingCommunity::create(producer(), {100}, bundle(1).matter, feeder, {bundle(1)});
|
||||
CHECK(waste);
|
||||
const std::array meal{FeedIntent{1, 2, 1, bundle(1)}};
|
||||
CHECK(waste->advance(evo::Tick{1}, meal));
|
||||
CHECK(waste->balances().back() == Inventory{});
|
||||
CHECK(waste->balances()[1].matter == bundle(1).matter);
|
||||
CHECK(waste->last_decomposed() == (Inventory{{}, bundle(1).matter}));
|
||||
const auto before = copy(*waste);
|
||||
const auto diagnostic = waste->last_decomposed();
|
||||
const std::array invalid{FeedIntent{1, 2, 1, bundle(100)}};
|
||||
CHECK(!waste->advance(evo::Tick{2}, invalid));
|
||||
CHECK(copy(*waste) == before && waste->last_decomposed() == diagnostic);
|
||||
|
||||
const std::array competing{ConsumerConfig{bundle(1), {}, 0}, feeder[0]};
|
||||
auto shared =
|
||||
FeedingCommunity::create(producer(), {100}, bundle(1).matter, competing, {bundle(1)});
|
||||
CHECK(shared);
|
||||
const std::array feeding{FeedIntent{1, 3, 1, bundle(1)}};
|
||||
CHECK(shared->advance(evo::Tick{1}, feeding, death));
|
||||
CHECK(*shared->corpse(2) == Inventory{});
|
||||
CHECK(shared->last_decomposed() == bundle(1));
|
||||
CHECK(shared->balances().back().matter == bundle(1).matter); // Corpse used the shared cap.
|
||||
|
||||
const Inventory mixed{{0}, {Femtograms{1}, Femtograms{0}, Femtograms{2}, Femtograms{3}}};
|
||||
const std::array funded{ConsumerConfig{bundle(5), {}, 0}};
|
||||
auto channels = FeedingCommunity::create(producer(), {}, {}, funded, {mixed});
|
||||
CHECK(channels && channels->advance(evo::Tick{1}, {}, death));
|
||||
CHECK(channels->last_decomposed() == mixed);
|
||||
CHECK(*channels->corpse(2) ==
|
||||
(Inventory{{5}, {Femtograms{4}, Femtograms{5}, Femtograms{3}, Femtograms{2}}}));
|
||||
}
|
||||
void ordered_replay() {
|
||||
for (std::uint64_t seed = 0; seed < 32; ++seed) {
|
||||
evo::Random random{seed};
|
||||
@@ -151,6 +273,9 @@ int main() try {
|
||||
capture_feeding_and_terminal();
|
||||
validation_and_rollback();
|
||||
ordered_replay();
|
||||
corpse_preservation_and_rollback();
|
||||
decomposition_reference();
|
||||
nutrient_return_and_waste();
|
||||
std::cout << "PASS shared feeding, rollback, terminality and conservation\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
|
||||
Reference in New Issue
Block a user