#include "evo/processes/development_opening.hpp" #include #include #include namespace evo::processes { namespace { // Mirrors tests/fixtures/environmental_region.hpp exactly; the lineage-region // contracts test proves byte equality with the fixture for world 7. EnvironmentalConfig config(world::WorldIdentity id) { EnvironmentalConfig c; c.rules = 2; c.world = id.world; c.frame = id.frame; c.producer = 1; c.consumer = 2; c.source = 3; c.tick_microseconds = 50000; c.area_um2 = 1; c.irradiance_numerator = 11; c.irradiance_denominator = 3; c.efficiency = 600; c.growth_numerator = 3; c.growth_denominator = 2; c.growth_cost = 1; c.recipe = {1, 2, 1, 1, 1}; c.intake.fill(100); c.assimilation = 1000; c.producer_min_mK = c.consumer_min_mK = 270000; c.producer_max_mK = c.consumer_max_mK = 310000; c.decay.fill(1); return c; } std::unique_ptr community(world::WorldIdentity id) { using namespace world; constexpr auto maximum = std::numeric_limits::max(); std::array environment{200, 6, 6, 400, 0, 0, 200, 0, 2000, 0}; const FieldSite site{{0, 0, -16000}, {{0}, {0}, {0}, {10}, {20}, {3}}, {1}}; std::array opening{}; for (std::size_t k = 0; k < 10; ++k) opening[k] = {static_cast(k), {&environment[k], 1}}; const FieldDefaults defaults{ {accounting::Femtograms{0}, accounting::Femtograms{maximum}, accounting::Femtograms{0}}}; auto f = FieldStore::create(id, 1, defaults, {&site, 1}, opening, 2000000); auto t = ChunkStore::create({}, 1, 2000000, {{VolumeUnits{100}, VolumeUnits{100}}}); if (!f || !t || !(*t)->load({0, 0, -1000})) return nullptr; std::array accounts{}; accounts[0].id = {1}; accounts[1].id = {2}; accounts[0].capacities.fill(100000000); accounts[1].capacities.fill(100000000); auto r = EnvironmentalTransfers::create(id, std::move(*f), std::move(*t), accounts, 4000000); if (!r) return nullptr; auto o = EnvironmentalCommunity::create(config(id), std::move(*r), 8000000); return o ? std::move(*o) : nullptr; } std::optional genome(std::uint64_t id, std::uint64_t parent) { biology::GenomeDraft draft; draft.schema_version = biology::genome_schema_v1; // development-v1 is fixed (ADR-0099). draft.id = id; draft.origin_event = id; draft.development_version = 1; if (parent != 0) draft.parents = {parent}; draft.capabilities = {{biology::Capability::energy_conversion, 400, 0}, {biology::Capability::membrane, 120, 0}, {biology::Capability::target_size, 8'000'000, 0}}; auto made = biology::Genome::create(draft); if (!made) return std::nullopt; return *made; } } // namespace EnvironmentalInput development_input(std::uint64_t tick) noexcept { EnvironmentalInput in; in.temperature_mK = 290000; in.source_enabled = tick % 7 == 0 ? 0 : 1; if (tick == 16) in.bite = {2, 2, 2, 2, 1}; if (tick == 20) in.terminal[1] = 1; return in; } std::expected, DevelopmentOpeningError> development_opening(std::uint64_t world) { if (world == 0) return std::unexpected{DevelopmentOpeningError::identity}; const world::WorldIdentity id{world, development_opening_frame}; auto founder = genome(1, 0); auto descendant = genome(2, 1); auto opening = community(id); if (!founder || !descendant || !opening) return std::unexpected{DevelopmentOpeningError::build}; biology::LineageArchive archive; if (!archive.admit(*founder) || !archive.admit(*descendant) || !archive.record_birth(5, 1, Tick{0}) || !archive.record_death(5, Tick{0}) || !archive.record_birth(10, 1, Tick{0}) || !archive.record_birth(11, 2, Tick{0})) return std::unexpected{DevelopmentOpeningError::build}; auto region = LineageRegion::create(std::move(opening), archive, {10, 11, 12, 3}); if (!region) return std::unexpected{DevelopmentOpeningError::build}; return std::move(*region); } } // namespace evo::processes