#pragma once #include "evo/biology/metabolism.hpp" #include #include #include namespace evo::biology { inline constexpr std::uint64_t cellular_motion_tick_microseconds = 50'000; inline constexpr std::uint64_t cellular_motion_axis_limit_um = 1'000'000; inline constexpr std::int32_t cellular_intent_component_limit = 1'000; struct CellularArea { std::uint64_t width_um{}, height_um{}; auto operator<=>(const CellularArea&) const = default; }; // Lower-left corner of the cell's square footprint, in micrometres. struct CellularPosition { std::uint64_t x_um{}, y_um{}; auto operator<=>(const CellularPosition&) const = default; }; // Bounded movement direction/magnitude, not a position or speed claim. struct CellularIntent { std::int16_t x{}, y{}; auto operator<=>(const CellularIntent&) const = default; }; struct CellularMotionProposal { CellularPosition position; std::uint64_t distance_um{}; // Conservative integer upper bound on actual travel. accounting::Picojoules movement_cost{}; auto operator<=>(const CellularMotionProposal&) const = default; }; struct CellularMotionCandidate { CellularPosition position; accounting::Inventory reserve_after; accounting::Inventory heat_after; accounting::Picojoules movement_cost{}; auto operator<=>(const CellularMotionCandidate&) const = default; }; enum class CellularMotionError : std::uint8_t { invalid_area, invalid_extent, outside_area, invalid_intent, unsupported_rate_period, insufficient_reserve, overflow }; // Pure M11.3 proposal for one 50 ms tick. Costs are reported, not spent; the // authoritative state owner must apply the proposal only when its reserve can // fund the movement_cost. Only per-second development-v2 budgets are accepted. [[nodiscard]] std::expected propose_cellular_motion(CellularArea area, CellularPosition position, std::uint32_t extent_um, CellularIntent intent, const MetabolicBudget& budget) noexcept; // Detached one-tick candidate: movement is refused if reserve cannot pay, and // paid energy moves to heat in the same returned value. Inputs are unchanged. [[nodiscard]] std::expected propose_funded_cellular_motion(CellularArea area, CellularPosition position, std::uint32_t extent_um, CellularIntent intent, const MetabolicBudget& budget, accounting::Inventory reserve, accounting::Inventory heat) noexcept; // Axis-aligned square footprints touching at an edge count as in contact. [[nodiscard]] bool cellular_footprints_contact(CellularPosition a, std::uint32_t extent_a_um, CellularPosition b, std::uint32_t extent_b_um) noexcept; } // namespace evo::biology