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:
@@ -1,12 +1,108 @@
|
||||
#include "evo/server/lifecycle/cellular_revamp.hpp"
|
||||
|
||||
#include "evo/core/random.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace evo::server {
|
||||
bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
|
||||
return rules.body.essential_upkeep_per_thousand <= 1'000;
|
||||
constexpr std::uint64_t most = 1'000'000'000'000'000ULL;
|
||||
const auto& step = rules.step;
|
||||
for (const auto rate : rules.burn_pj_per_kfg)
|
||||
if (rate > 1'000'000'000'000ULL)
|
||||
return false;
|
||||
return rules.body.essential_upkeep_per_thousand <= 1'000 &&
|
||||
step.membrane_collection_per_mille_per_point <= 1'000 && step.engulf_ratio_milli >= 1 &&
|
||||
step.engulf_ratio_milli <= 1'000'000 && step.engulf_reserve_percent <= 100 &&
|
||||
step.kill_bubble_per_thousand <= 1'000 && rules.drip_interval_ticks <= 72'000 &&
|
||||
rules.drip_bubble_pj <= most && rules.drip_bubble_fg <= most &&
|
||||
(rules.drip_interval_ticks == 0 ||
|
||||
(rules.drip_bubble_pj != 0 && rules.drip_bubble_fg != 0)) &&
|
||||
rules.reserve_load_per_thousand <= 1'000;
|
||||
}
|
||||
|
||||
biology::CellularHandling cellular_loaded_handling(const biology::CellularHandling& handling,
|
||||
std::uint64_t body_mass, std::uint64_t carried,
|
||||
const CellularRevampRules& rules) noexcept {
|
||||
// Masses stay far below 2^40 fg, so these products fit in 64 bits.
|
||||
const auto load = carried / 1'000 * rules.reserve_load_per_thousand +
|
||||
carried % 1'000 * rules.reserve_load_per_thousand / 1'000;
|
||||
if (load == 0 || body_mass == 0 || body_mass > (1ULL << 40U) || load > (1ULL << 40U))
|
||||
return handling;
|
||||
const auto total = body_mass + load;
|
||||
const auto slower = [&](std::uint64_t value) { return value * body_mass / total; };
|
||||
const auto dearer = [&](std::uint64_t value) {
|
||||
return value > (1ULL << 23U) ? value / body_mass * total
|
||||
: (value * total + body_mass - 1) / body_mass;
|
||||
};
|
||||
auto loaded = handling;
|
||||
loaded.thrust_q10 = static_cast<std::uint32_t>(slower(handling.thrust_q10));
|
||||
loaded.reverse_thrust_q10 = static_cast<std::uint32_t>(slower(handling.reverse_thrust_q10));
|
||||
loaded.turn = static_cast<std::uint16_t>(slower(handling.turn));
|
||||
loaded.thrust_cost.value = dearer(handling.thrust_cost.value);
|
||||
loaded.reverse_cost.value = dearer(handling.reverse_cost.value);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool cellular_drip_spent(biology::CellularHabitatConfig& config, accounting::Inventory& spent,
|
||||
const CellularRevampRules& rules, std::uint64_t world,
|
||||
std::uint64_t region, std::uint64_t tick, std::uint64_t source) {
|
||||
if (rules.drip_interval_ticks == 0 || tick % rules.drip_interval_ticks != 0)
|
||||
return true;
|
||||
Random random{world * 0x9e3779b97f4a7c15ULL ^ region * 0xc2b2ae3d27d4eb4fULL ^ tick};
|
||||
const auto by_address = [](const biology::CellularPatch& patch) { return patch.address; };
|
||||
for (std::size_t channel = 0; channel < 5; ++channel) {
|
||||
auto& pool = channel == 0 ? spent.energy.value : spent.matter[channel - 1].value;
|
||||
const auto cap = channel == 0 ? rules.drip_bubble_pj : rules.drip_bubble_fg;
|
||||
// Both draws happen for every channel, so a channel's spot never depends on another's.
|
||||
const auto x = random.next();
|
||||
const auto y = random.next();
|
||||
if (pool == 0 || config.patches.size() >= biology::max_cellular_liquid_deposits)
|
||||
continue;
|
||||
biology::CellularPatchAddress address{static_cast<std::uint32_t>(x % config.width_um),
|
||||
static_cast<std::uint32_t>(y % config.height_um)};
|
||||
auto at = std::ranges::lower_bound(config.patches, address, {}, by_address);
|
||||
while (at != config.patches.end() && at->address == address) {
|
||||
address.x_um = address.x_um + 1 < config.width_um ? address.x_um + 1 : 0;
|
||||
at = std::ranges::lower_bound(config.patches, address, {}, by_address);
|
||||
}
|
||||
if (config.next_deposit == std::numeric_limits<std::uint32_t>::max())
|
||||
return false;
|
||||
const auto amount = std::min(pool, cap);
|
||||
biology::CellularPatch bubble{address,
|
||||
source,
|
||||
{},
|
||||
config.next_deposit++,
|
||||
biology::cellular_mote_radius_um,
|
||||
biology::CellularDepositKind::mote};
|
||||
bubble.merged = 1;
|
||||
if (channel == 0)
|
||||
bubble.stock.energy.value = amount;
|
||||
else
|
||||
bubble.stock.matter[channel - 1].value = amount;
|
||||
pool -= amount;
|
||||
config.patches.insert(at, bubble);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t) {
|
||||
return {.body = {.essential_upkeep_per_thousand =
|
||||
static_cast<std::uint32_t>(t.body_essential_upkeep_per_mille)}};
|
||||
const auto u32 = [](std::int64_t value) { return static_cast<std::uint32_t>(value); };
|
||||
const auto u64 = [](std::int64_t value) { return static_cast<std::uint64_t>(value); };
|
||||
return {.body = {.essential_upkeep_per_thousand = u32(t.body_essential_upkeep_per_mille)},
|
||||
.burn_pj_per_kfg = {u64(t.energy_burn_carbon_pj_per_kfg),
|
||||
u64(t.energy_burn_nitrogen_pj_per_kfg),
|
||||
u64(t.energy_burn_phosphorus_pj_per_kfg),
|
||||
u64(t.energy_burn_other_pj_per_kfg)},
|
||||
.step = {.membrane_collection_per_mille_per_point =
|
||||
u32(t.feeding_membrane_collection_per_mille_per_point),
|
||||
.engulf_ratio_milli = u32(t.predation_engulf_ratio_milli),
|
||||
.engulf_reserve_percent = u32(t.predation_engulf_reserve_percent),
|
||||
.kill_bubble_per_thousand = u32(t.predation_kill_bubble_per_mille)},
|
||||
.drip_interval_ticks = u32(t.spent_drip_interval_ticks),
|
||||
.drip_bubble_pj = u64(t.spent_drip_bubble_pj),
|
||||
.drip_bubble_fg = u64(t.spent_drip_bubble_fg),
|
||||
.reserve_load_per_thousand = u32(t.body_reserve_load_per_mille)};
|
||||
}
|
||||
} // namespace evo::server
|
||||
|
||||
Reference in New Issue
Block a user