#pragma once #include "evo/core/random.hpp" #include "evo/processes/feeding.hpp" namespace evo::processes { // One founder strategy. ADR-0028 makes a child duplicate its parent, so a founder // strategy identifies one lineage for the whole episode. struct StrategyConfig { accounting::Inventory opening; accounting::Inventory intake_limit; std::uint16_t assimilation_per_thousand; accounting::Inventory reproduction_threshold; accounting::Inventory investment; // Ticks of life before a host terminal fact. Bounds the episode; not senescence. std::uint32_t lifespan; }; struct EcosystemConfig { ProducerConfig producer; accounting::Picojoules source; std::array nutrients; DecompositionConfig decomposition; std::uint16_t construction_per_thousand; std::uint32_t capacity; std::uint64_t tick_limit; }; struct EcosystemReport { std::uint64_t seed; std::uint64_t ticks; std::uint64_t births; std::uint64_t predation_deaths; std::uint64_t lifespan_deaths; // Zero when living consumers remained when the episode stopped. std::uint64_t extinction_tick; std::uint32_t founders; std::uint32_t surviving_lineages; accounting::Inventory decomposed; accounting::Inventory conserved; std::uint64_t fingerprint; auto operator<=>(const EcosystemReport&) const = default; }; enum class EcosystemError : std::uint8_t { invalid_config, // The community rejected a driver batch. This is a driver defect, not ecology. community_failure }; inline constexpr std::size_t max_strategies = 4; class EcosystemEpisode { public: [[nodiscard]] static std::expected create(EcosystemConfig config, std::span founders, std::uint64_t seed); // One driven tick. False once the episode has ended; the report is then final. [[nodiscard]] std::expected step(); [[nodiscard]] std::expected run(); [[nodiscard]] EcosystemReport report() const noexcept; [[nodiscard]] const FeedingCommunity& community() const noexcept { return community_; } // Founder ID whose retained ancestry this process descends from; zero if unborn. [[nodiscard]] std::uint32_t lineage(std::uint32_t id) const noexcept; private: EcosystemEpisode(FeedingCommunity community, std::vector founders, EcosystemConfig config, std::uint64_t seed); [[nodiscard]] const StrategyConfig& strategy(std::uint32_t id) const noexcept; FeedingCommunity community_; std::vector founders_; EcosystemConfig config_; Random random_; std::uint64_t seed_; std::uint64_t births_{}; std::uint64_t predation_deaths_{}; std::uint64_t lifespan_deaths_{}; std::uint64_t extinction_tick_{}; accounting::Inventory decomposed_{}; bool finished_{}; }; } // namespace evo::processes