Files
aevolution/include/evo/biology/cellular_step.hpp
T
dingoandClaude Opus 5.5 76d21b4815
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
feat(cellular): rules 13 feeding, matter as energy, spent pool and predation
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>
2026-10-22 18:35:31 -04:00

91 lines
4.3 KiB
C++

#pragma once
#include "evo/biology/cellular_burn.hpp"
#include "evo/biology/cellular_habitat.hpp"
#include "evo/biology/cellular_kinematics.hpp"
#include <cstdint>
#include <optional>
namespace evo::biology {
struct CellularStepIntent {
CellularIntent movement{};
std::optional<CellularPatchAddress> intake_target;
// ADR-0124: take one smaller contacted cell after every life's step (rules 3 only).
// Exclusive with an intake target; the server chooses the prey.
bool engulf{};
// ADR-0125: fund and place one wildlife bud after the tick's mutations (rules 4 only).
// Exclusive with an intake target and with engulfment; the owner decides everything.
bool bud{};
// ADR-0128: the owner is offline; the cell does nothing this tick (no maintenance,
// movement, intake or heat) but can still be engulfed. Exclusive with every other field.
bool frozen{};
// Rules 12: oppose relative velocity instead of following `movement`.
bool brake{};
// Rules 13 (ADR-0179): matter channels the player keeps from being burned for anything but
// upkeep, bit 0 carbon to bit 3 other matter. Wildlife keeps nothing.
std::uint8_t exclude{};
auto operator<=>(const CellularStepIntent&) const = default;
};
enum class CellularStepError : std::uint8_t {
invalid_tick,
unsupported_rate_period,
insufficient_maintenance,
overflow,
motion
};
enum class CellularIntakeStatus : std::uint8_t { not_requested, acquired, missing, out_of_contact };
enum class CellularMovementStatus : std::uint8_t {
not_requested,
moved,
blocked,
insufficient_reserve
};
// Complete detached candidate for one 50 ms life tick. Maintenance is charged
// first; unaffordable motion leaves the cell stationary, then one targeted patch
// may be absorbed at the resulting position. Publication owns the final swap.
struct CellularStepCandidate {
std::uint64_t begin_tick{}, end_tick{};
CellularPosition position;
accounting::Inventory reserve_after;
accounting::Inventory heat_after;
accounting::Picojoules maintenance_cost{}, movement_cost{};
CellularMovementStatus movement_status{CellularMovementStatus::not_requested};
CellularIntakeStatus intake_status{CellularIntakeStatus::not_requested};
std::optional<CellularPatchUptakeProposal> intake;
// Rules 12 (liquid motion): the motion state after the tick and the path travelled.
CellularMotionState motion{};
std::uint64_t path_um{};
// Rules 13 (ADR-0179): reserve matter burned in place of energy, for the region's spent
// pool. Costs paid this way add no heat.
accounting::Inventory spent{};
auto operator<=>(const CellularStepCandidate&) const = default;
};
// Rules 12: liquid-relative motion inputs for one life (Cellular_Region_Movement_Plan.md).
struct CellularLiquidInput {
CellularMotionState motion;
CellularHandling handling;
CellularFlowSample flow; // Sampled at the footprint centre by the caller.
bool brake{};
auto operator<=>(const CellularLiquidInput&) const = default;
};
[[nodiscard]] std::expected<CellularStepCandidate, CellularStepError>
propose_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosition position,
std::uint32_t extent_um, CellularStepIntent intent,
accounting::Inventory reserve, accounting::Inventory heat,
const MetabolicBudget& budget, const CellularHabitat& habitat) noexcept;
// Rules 12: maintenance first, then one kinematic tick funded from what is left; thrust it
// cannot fund is not applied and the cell coasts with the flow. No targeted intake: liquid
// regions feed by contact in the region step. Rules 13 pass `burn`: reserve matter stands in
// for missing energy, any channel for maintenance and only unexcluded ones for thrust.
[[nodiscard]] std::expected<CellularStepCandidate, CellularStepError>
propose_liquid_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosition position,
std::uint32_t extent_um, CellularIntent movement,
const CellularLiquidInput& liquid, accounting::Inventory reserve,
accounting::Inventory heat, const MetabolicBudget& budget,
const CellularBurn* burn = nullptr) noexcept;
} // namespace evo::biology