#pragma once #include "evo/biology/cellular_catalog.hpp" #include #include #include // Behaviour triggers (rules 13, ADR-0179; Cellular_mutation_plan.md section 3): what a cell did // each tick raises or lowers its affinity score for each mutation. Integer state only, advanced // once per tick by the owner, so replay reproduces every score exactly. namespace evo::biology { // One tick of a cell's activity: flags are 0 or 1, amounts are pJ or fg (CellularSignal). struct CellularActivity { std::array signal{}; std::uint16_t heading{}; // The cell's heading after the tick (65,536 per turn). [[nodiscard]] std::uint64_t operator[](CellularSignal s) const noexcept { return signal[static_cast(s)]; } std::uint64_t& operator[](CellularSignal s) noexcept { return signal[static_cast(s)]; } }; // One trigger's progress. Its meaning depends on the trigger kind; all fields start at zero. struct CellularTriggerState { std::uint64_t first{}, second{}; std::uint32_t ticks{}; std::uint16_t heading{}; std::uint8_t running{}; auto operator<=>(const CellularTriggerState&) const = default; }; // Advances one trigger by one tick; true when it fires. `threshold` replaces the spec's tick // threshold (or window) when non-zero. [[nodiscard]] bool cellular_trigger_tick(const CellularTriggerSpec& spec, std::uint32_t threshold, CellularTriggerState& state, const CellularActivity& activity) noexcept; // Affinity: every mutation's score, and its increase and decrease triggers' progress. struct CellularAffinity { std::array score{}; std::array increase{}, decrease{}; auto operator<=>(const CellularAffinity&) const = default; }; // Bounds of every score. struct CellularScoreBounds { std::int32_t min{-1'000}, max{1'000}; auto operator<=>(const CellularScoreBounds&) const = default; }; // Advances every mutation's triggers by one tick and applies their points to its score // (`tuning` is indexed like the catalog). Disabled mutations do not move. void cellular_affinity_tick(CellularAffinity& affinity, const CellularActivity& activity, std::span tuning, CellularScoreBounds bounds) noexcept; } // namespace evo::biology