feat(cellular): rules 13 feeding, matter as energy, spent pool and predation
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m24s
Foundation / image (push) Successful in 5m3s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m24s
Foundation / image (push) Successful in 5m3s
Phase 2 of the cellular revamp build plan (ADR-0179), server half. - Matter as energy: when an energy cost exceeds the reserve's energy, reserve matter stands in for the rest at each channel's burn rate (pJ per 1,000 fg, scaled by the genome's burn efficiency), largest channel first. Upkeep may burn any channel; thrust only channels the player has not excluded. Burned matter adds no heat; it goes to the region's spent pool. A cell dies only when nothing can pay its upkeep. - Collection: per-channel limits scaled by the genome's collection indices, a shared limit on all matter, a tunable cost per membrane point, and only the genome's kept share (energy conversion) of bubble energy reaching the reserve. - Predation: engulf mass carries a tunable share of reserve matter, the predator's engulf capacity scales its side and the prey's membrane (now in nanometres) its own; kill absorption scales the predator's intake; the kill's remainder is split between bubbles at the prey and the spent pool, and a full habitat sends overflow to the pool. - The spent pool is owner format 11 state, counted in conservation, and drips back as seeded random bubbles every interval tick. - Reserve matter is carried as load: slower thrust and turning, costlier thrust. - Channel exclusions are a 4-bit step intent field, trace byte 14; only owned lives under rules 13 may send them. All values come from the revamp tuning file. Rules up to 12 are unchanged. Tests cover payments and their conservation over 400 seeds, the rules-13 region step (collection, membrane, kept energy, burning, engulfment and kill splits with closure), the drip, load, exclusions, a 700-tick run with closure and exact restore, and trace replay with exclusions. Session v14 and the client follow the server phases (build plan). Refreshes the DEV session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,9 +52,13 @@ constexpr std::size_t cellular_lives_v9_header_bytes = cellular_lives_v8_header_
|
||||
// its motion state (two velocities, heading, reserved, two carries), 20 bytes.
|
||||
constexpr std::size_t cellular_lives_v10_header_bytes = cellular_lives_v9_header_bytes + 88;
|
||||
constexpr std::size_t cellular_life_motion_bytes = 20;
|
||||
// Format 11 (rules 13, ADR-0179): the revamp rules, so far the essential upkeep share (4) and a
|
||||
// reserved zero (4). Later build phases extend this block before format 11 is deployed.
|
||||
constexpr std::size_t cellular_lives_v11_header_bytes = cellular_lives_v10_header_bytes + 8;
|
||||
// Format 11 (rules 13, ADR-0179): the revamp rules and the spent pool. Essential upkeep share and
|
||||
// a reserved zero (8), four burn rates (32), membrane collection cost, engulf ratio, engulf
|
||||
// reserve share and kill bubble share (16), drip interval and a reserved zero (8), drip bubble
|
||||
// energy and matter (16), and the spent pool (40): 120 bytes. The word after the drip interval
|
||||
// is the reserve load share. Later build phases extend this
|
||||
// block before format 11 is deployed.
|
||||
constexpr std::size_t cellular_lives_v11_header_bytes = cellular_lives_v10_header_bytes + 120;
|
||||
|
||||
bool valid_motion(const biology::CellularMotionState& m) noexcept {
|
||||
constexpr std::int64_t carry = biology::cellular_velocity_q10_per_um_s * 1'000'000;
|
||||
@@ -395,7 +399,8 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
accounting::Inventory opening_total, bool detritus_rules = false,
|
||||
bool bud_rules = false, std::uint64_t next_bud_sequence = 1,
|
||||
bool presence_rules = false, const CellularBoundaryLedger* boundary = nullptr,
|
||||
const std::vector<CellularOffspringRevision>* plans = nullptr) {
|
||||
const std::vector<CellularOffspringRevision>* plans = nullptr,
|
||||
const accounting::Inventory& spent = {}) {
|
||||
// A bud's identity lies in this region's namespace below the next sequence; anything
|
||||
// else is an allocated identity, below the namespace (ADR-0125).
|
||||
const auto bud_identity = [&](std::uint64_t identity) noexcept {
|
||||
@@ -568,9 +573,12 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
|
||||
if (plans && !validate_plans(lives, corpses, archive, *plans, config.tick))
|
||||
return std::unexpected{CellularLivesError::invalid_life};
|
||||
const auto current = sum_state(nursery, heat, habitat, lives, corpses);
|
||||
auto current = sum_state(nursery, heat, habitat, lives, corpses);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
// Rules 13: the spent pool is region stock until it drips back.
|
||||
if (!add_inventory(*current, spent))
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
auto expected = opening_total;
|
||||
if (boundary) {
|
||||
accounting::Inventory credit{}, debit{};
|
||||
@@ -616,6 +624,7 @@ struct CellularLives::State {
|
||||
accounting::Picojoules captured{}; // Format 9: light credited to reserves so far.
|
||||
CellularLiquidRules liquid{}; // Format 10 (rules 12).
|
||||
CellularRevampRules revamp{}; // Format 11 (rules 13).
|
||||
accounting::Inventory spent{}; // Format 11: matter and energy waiting to drip back.
|
||||
std::shared_ptr<const biology::CellularFlowField> field; // Generated from `liquid`.
|
||||
|
||||
State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id,
|
||||
@@ -812,10 +821,11 @@ CellularLives::migration_replacement(std::vector<CellularOwnedLife> living,
|
||||
state_->region, state_->frame);
|
||||
if (!habitat)
|
||||
return std::unexpected(CellularLivesError::habitat);
|
||||
const auto total = validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, **habitat, living, state_->corpses,
|
||||
archive, state_->nursery, state_->heat, state_->opening_total,
|
||||
true, true, state_->next_bud_sequence, true, &boundary);
|
||||
const auto total =
|
||||
validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, **habitat, living, state_->corpses, archive,
|
||||
state_->nursery, state_->heat, state_->opening_total, true, true,
|
||||
state_->next_bud_sequence, true, &boundary, nullptr, state_->spent);
|
||||
if (!total)
|
||||
return std::unexpected(total.error());
|
||||
auto replacement = std::unique_ptr<CellularLives>{new CellularLives{std::make_unique<State>(
|
||||
@@ -877,13 +887,13 @@ CellularLives::exchange_boundary(std::span<const biology::CellularPatch> deposit
|
||||
habitat = std::move(*created);
|
||||
}
|
||||
const auto rules = state_->rules_version;
|
||||
const auto total =
|
||||
validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, *habitat, state_->lives, state_->corpses,
|
||||
state_->archive, state_->nursery, heat, state_->opening_total,
|
||||
rules >= cellular_lives_engulf_rules, rules >= cellular_lives_bud_rules,
|
||||
state_->next_bud_sequence, rules >= cellular_lives_presence_rules, &boundary,
|
||||
cellular_retained_plans(rules) ? &state_->offspring_revisions : nullptr);
|
||||
const auto total = validate_state(
|
||||
state_->world, state_->region, state_->frame, state_->config, state_->nursery_config,
|
||||
*habitat, state_->lives, state_->corpses, state_->archive, state_->nursery, heat,
|
||||
state_->opening_total, rules >= cellular_lives_engulf_rules,
|
||||
rules >= cellular_lives_bud_rules, state_->next_bud_sequence,
|
||||
rules >= cellular_lives_presence_rules, &boundary,
|
||||
cellular_retained_plans(rules) ? &state_->offspring_revisions : nullptr, state_->spent);
|
||||
if (!total)
|
||||
return std::unexpected(total.error());
|
||||
BoundarySavepoint savepoint{std::move(state_->habitat), state_->heat, state_->current_total,
|
||||
@@ -1152,8 +1162,20 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
|
||||
out.put(cost == 1'000 ? 0 : cost, 4);
|
||||
}
|
||||
if (revamp) {
|
||||
out.put(state_->revamp.body.essential_upkeep_per_thousand, 4);
|
||||
const auto& r = state_->revamp;
|
||||
out.put(r.body.essential_upkeep_per_thousand, 4);
|
||||
out.put(0, 4);
|
||||
for (const auto rate : r.burn_pj_per_kfg)
|
||||
out.put(rate);
|
||||
out.put(r.step.membrane_collection_per_mille_per_point, 4);
|
||||
out.put(r.step.engulf_ratio_milli, 4);
|
||||
out.put(r.step.engulf_reserve_percent, 4);
|
||||
out.put(r.step.kill_bubble_per_thousand, 4);
|
||||
out.put(r.drip_interval_ticks, 4);
|
||||
out.put(r.reserve_load_per_thousand, 4);
|
||||
out.put(r.drip_bubble_pj);
|
||||
out.put(r.drip_bubble_fg);
|
||||
out.inventory(state_->spent);
|
||||
}
|
||||
for (const auto site : state_->nursery_config.sites)
|
||||
out.site(site);
|
||||
@@ -1469,7 +1491,8 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
state_->rules_version >= cellular_lives_presence_rules,
|
||||
state_->format_version >= cellular_lives_migration_format ? &state_->boundary : nullptr,
|
||||
state_->format_version >= cellular_lives_inheritance_format ? &state_->offspring_revisions
|
||||
: nullptr);
|
||||
: nullptr,
|
||||
state_->spent);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
|
||||
@@ -1486,6 +1509,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
candidate->state_->liquid = state_->liquid;
|
||||
candidate->state_->field = state_->field;
|
||||
candidate->state_->revamp = state_->revamp;
|
||||
candidate->state_->spent = state_->spent;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
@@ -1660,9 +1684,23 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
field = std::move(*generated);
|
||||
}
|
||||
CellularRevampRules revamp{};
|
||||
accounting::Inventory spent{};
|
||||
if (revamp_version) {
|
||||
revamp.body.essential_upkeep_per_thousand = static_cast<std::uint32_t>(in.get(4));
|
||||
if (in.get(4) != 0 || !cellular_revamp_valid(revamp))
|
||||
const auto u32 = [&in] { return static_cast<std::uint32_t>(in.get(4)); };
|
||||
revamp.body.essential_upkeep_per_thousand = u32();
|
||||
const auto reserved = in.get(4);
|
||||
for (auto& rate : revamp.burn_pj_per_kfg)
|
||||
rate = in.get();
|
||||
revamp.step.membrane_collection_per_mille_per_point = u32();
|
||||
revamp.step.engulf_ratio_milli = u32();
|
||||
revamp.step.engulf_reserve_percent = u32();
|
||||
revamp.step.kill_bubble_per_thousand = u32();
|
||||
revamp.drip_interval_ticks = u32();
|
||||
revamp.reserve_load_per_thousand = u32();
|
||||
revamp.drip_bubble_pj = in.get();
|
||||
revamp.drip_bubble_fg = in.get();
|
||||
spent = in.inventory();
|
||||
if (reserved != 0 || !cellular_revamp_valid(revamp))
|
||||
return std::unexpected{CellularLivesError::format};
|
||||
}
|
||||
const auto life_bytes = liquid_version ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes
|
||||
@@ -1886,7 +1924,7 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
saved_world, saved_region, saved_frame, config, nursery_config, **habitat, lives, corpses,
|
||||
*archive, nursery, heat, opening_total, engulf_version, bud_version, next_bud_sequence,
|
||||
presence_version, migration_version ? &boundary : nullptr,
|
||||
inheritance_version ? &plan_history : nullptr);
|
||||
inheritance_version ? &plan_history : nullptr, spent);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
|
||||
@@ -1901,6 +1939,7 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
restored->state_->liquid = liquid;
|
||||
restored->state_->field = std::move(field);
|
||||
restored->state_->revamp = revamp;
|
||||
restored->state_->spent = spent;
|
||||
if (!std::ranges::equal(bytes, restored->snapshot()))
|
||||
return std::unexpected{CellularLivesError::noncanonical};
|
||||
return restored;
|
||||
@@ -1938,6 +1977,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
const bool presence_rules = state_->rules_version >= cellular_lives_presence_rules;
|
||||
const bool inheritance_rules = cellular_retained_plans(state_->rules_version);
|
||||
const bool liquid_rules = state_->rules_version >= cellular_lives_liquid_rules;
|
||||
const bool revamp_rules = state_->rules_version >= cellular_lives_revamp_rules;
|
||||
if (liquid_rules && !state_->field)
|
||||
return std::unexpected{CellularLivesError::invalid_config};
|
||||
for (std::size_t i = 0; i < ordered.size(); ++i) {
|
||||
@@ -1953,6 +1993,10 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
if (intent.brake && !liquid_rules)
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
// Rules 13: exclusions are an owned life's setting, never wildlife's or a frozen cell's.
|
||||
if (intent.exclude != 0 && (!revamp_rules || intent.exclude > 0x0F || intent.frozen ||
|
||||
state_->lives[i].account == LifeAccount{}))
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
}
|
||||
for (std::size_t i = 0; i < selections.size(); ++i) {
|
||||
const auto& selection = selections[i];
|
||||
@@ -2018,18 +2062,50 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
*membrane,
|
||||
life.source});
|
||||
if (liquid_rules) {
|
||||
const auto handling = cellular_liquid_handling(*genome, *budget, state_->liquid);
|
||||
auto handling = cellular_liquid_handling(*genome, *budget, state_->liquid);
|
||||
if (!handling)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
if (revamp_rules) {
|
||||
// Rules 13: reserve matter is carried as load.
|
||||
std::uint64_t carried{};
|
||||
for (const auto& channel : life.reserve.matter)
|
||||
carried += channel.value;
|
||||
*handling = cellular_loaded_handling(*handling, budget->phenotype.total_mass,
|
||||
carried, state_->revamp);
|
||||
}
|
||||
inputs.back().liquid = biology::CellularLiquidInput{
|
||||
life.motion, *handling,
|
||||
state_->field->at_footprint(life.position, budget->phenotype.extent),
|
||||
ordered[i].intent.brake};
|
||||
}
|
||||
if (revamp_rules) {
|
||||
// Rules 13: the genome's traits; a life from before the upgrade (no traits, the
|
||||
// membrane in micrometres) feeds and burns as a founder and keeps all bubble energy.
|
||||
biology::CellularRevampLifeInput revamp{};
|
||||
const auto& traits = genome->cellular_traits();
|
||||
const auto kept = genome->parameter(biology::Capability::energy_conversion);
|
||||
if (traits) {
|
||||
revamp.burn = biology::cellular_burn(state_->revamp.burn_pj_per_kfg, traits->burn,
|
||||
ordered[i].intent.exclude);
|
||||
revamp.collection = traits->collection;
|
||||
revamp.energy_kept_per_thousand = kept ? *kept : 1'000;
|
||||
revamp.membrane_nm = *membrane;
|
||||
revamp.engulf_capacity = traits->engulf_capacity;
|
||||
revamp.kill_absorption = traits->kill_absorption;
|
||||
} else {
|
||||
revamp.burn =
|
||||
biology::cellular_burn(state_->revamp.burn_pj_per_kfg, {100, 100, 100, 100},
|
||||
ordered[i].intent.exclude);
|
||||
revamp.membrane_nm = *membrane * 1'000;
|
||||
}
|
||||
inputs.back().revamp = revamp;
|
||||
}
|
||||
}
|
||||
auto proposal =
|
||||
biology::propose_cellular_region_step(state_->config.tick, state_->config.area, inputs,
|
||||
*state_->habitat, {engulf_rules, contact_rules});
|
||||
biology::CellularRegionRules region_rules{engulf_rules, contact_rules};
|
||||
if (revamp_rules)
|
||||
region_rules.revamp = state_->revamp.step;
|
||||
auto proposal = biology::propose_cellular_region_step(state_->config.tick, state_->config.area,
|
||||
inputs, *state_->habitat, region_rules);
|
||||
if (!proposal)
|
||||
return std::unexpected{CellularLivesError::region_step};
|
||||
|
||||
@@ -2038,6 +2114,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
auto next_archive = state_->archive;
|
||||
auto next_offspring_revisions = state_->offspring_revisions;
|
||||
auto next_heat = state_->heat;
|
||||
auto next_spent = state_->spent;
|
||||
if (!add_inventory(next_spent, proposal->spent))
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
auto habitat_config = state_->habitat->config();
|
||||
for (const auto& result : proposal->lives) {
|
||||
const auto found = std::ranges::lower_bound(
|
||||
@@ -2428,6 +2507,11 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
}
|
||||
habitat_config.patches.insert(at, made);
|
||||
}
|
||||
// Rules 13: the spent pool drips back as bubbles at seeded random spots.
|
||||
if (revamp_rules &&
|
||||
!cellular_drip_spent(habitat_config, next_spent, state_->revamp, state_->world,
|
||||
state_->region, proposal->end_tick, state_->nursery_config.source))
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
if (deposits)
|
||||
std::erase_if(habitat_config.patches, [](const biology::CellularPatch& patch) {
|
||||
return patch.stock == accounting::Inventory{};
|
||||
@@ -2466,7 +2550,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
state_->nursery, next_heat, state_->opening_total, engulf_rules, bud_rules,
|
||||
next_bud_sequence, presence_rules,
|
||||
state_->format_version >= cellular_lives_migration_format ? &state_->boundary : nullptr,
|
||||
inheritance_rules ? &next_offspring_revisions : nullptr);
|
||||
inheritance_rules ? &next_offspring_revisions : nullptr, next_spent);
|
||||
if (!total)
|
||||
return std::unexpected{total.error()};
|
||||
|
||||
@@ -2483,6 +2567,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
next->captured = state_->captured;
|
||||
next->liquid = state_->liquid;
|
||||
next->field = state_->field;
|
||||
next->revamp = state_->revamp;
|
||||
next->spent = next_spent;
|
||||
// ADR-0175: light, from this tick's own intentions, credited to every active,
|
||||
// unfrozen photosynthetic survivor's reserve and to the boundary inflow together.
|
||||
std::vector<std::pair<std::uint64_t, std::uint64_t>> lit_lives;
|
||||
|
||||
Reference in New Issue
Block a user