feat(biology): evolve photosynthetic producers that capture light
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (deploy) (push) Successful in 5m15s
Foundation / checks (network) (push) Successful in 21m56s
Foundation / checks (client) (push) Successful in 22m54s
Foundation / checks (tsan) (push) Successful in 47m4s
Foundation / checks (postgres) (push) Successful in 1h15m49s
Foundation / checks (checks) (push) Failing after 1h30m4s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

ADR-0175 implements ADR-0136 step C with trial costs to be balanced after
playtesting. Genome schema 5 adds a photosynthesis efficiency (empty in
schemas 1-4, so earlier offers and draws are unchanged; mutation operators
29-32 are appended). Development version 5 builds the organelles as
internal membrane (p/4 of structure, upkept twice) and slows movement by
p/2 per thousand. Founder 4 and cellular rules 11 let lineages earn the
capability as an offspring plan that children express.

Owner format 9 declares the region's light. Inside each tick's detached
candidate, active unfrozen producers capture cross-section x irradiance x
efficiency (a quarter while moving), credited to the reserve and boundary
inflow together and replayed from recorded intentions. Well-lit wildlife
producers hold still. The joint owner keeps infall, water and radiation and
nests a rules-11 owner unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-19 18:06:02 -04:00
co-authored by Claude Opus 5.5
parent 51991ac7ff
commit 108f29eda5
34 changed files with 856 additions and 128 deletions
@@ -69,7 +69,7 @@ struct CellularEnvironmentConfig {
};
struct CellularEnvironmentTickReport {
std::uint64_t tick{};
accounting::Inventory imported{};
accounting::Inventory imported{}; // Infall only; a rules-11 owner books its own light.
accounting::Picojoules exported{};
std::uint64_t events{}, credited_bubbles{}, skipped_bubbles{};
CellularTickExecution biology;
@@ -114,7 +114,7 @@ class CellularEnvironment {
[[nodiscard]] std::span<const CellularInfallSource> sources() const noexcept;
[[nodiscard]] std::span<const CellularInfallProgress> infall() const noexcept;
[[nodiscard]] accounting::Picojoules radiation_cap() const noexcept;
[[nodiscard]] accounting::Inventory imported() const noexcept; // All sources, cumulative.
[[nodiscard]] accounting::Inventory imported() const noexcept; // Infall, cumulative.
[[nodiscard]] accounting::Picojoules exported() const noexcept;
[[nodiscard]] std::uint64_t tick() const noexcept;
@@ -139,6 +139,13 @@ class CellularEnvironment {
friend std::expected<std::unique_ptr<CellularEnvironment>, CellularEnvironmentError>
execute_environment_batch(const CellularEnvironment&, CellularEnvironmentBatch&, bool record);
struct Exchange;
struct Step {
CellularEnvironmentTickReport report;
};
enum class StepMode : std::uint8_t { live, record, replay };
[[nodiscard]] std::expected<Step, CellularEnvironmentError>
joint_step(std::vector<CellularLifeIntent>& intents,
std::span<const CellularMutationSelection> selections, StepMode mode);
CellularEnvironment(std::unique_ptr<CellularPopulation> population,
CellularEnvironmentConfig config);
[[nodiscard]] std::expected<Exchange, CellularEnvironmentError>
@@ -0,0 +1,34 @@
#pragma once
#include "evo/accounting/ledger.hpp"
#include "evo/biology/genome.hpp"
#include <compare>
#include <cstdint>
#include <optional>
namespace evo::server {
// ADR-0175 trial values: light on a region's habitat, as picojoules per square micrometre
// of a cell's cross-section per 50 ms tick (a rational), and the share a moving cell keeps.
inline constexpr std::uint64_t cellular_light_trial_irradiance = 40;
inline constexpr std::uint32_t cellular_light_trial_moving_per_thousand = 250;
// Declared light on one habitat. The entitlement bounds cumulative capture; light nobody
// captures is not modelled and never enters the books.
struct CellularLight {
std::uint64_t numerator{}, denominator{1};
accounting::Picojoules entitlement{};
std::uint32_t moving_per_thousand{cellular_light_trial_moving_per_thousand};
auto operator<=>(const CellularLight&) const = default;
};
[[nodiscard]] constexpr bool cellular_light_valid(const CellularLight& light) noexcept {
return light.denominator != 0 && light.moving_per_thousand <= 1000 &&
(light.numerator == 0) == (light.entitlement.value == 0);
}
// Energy one cell captures in a tick: cross-section (extent squared) x irradiance x its
// photosynthesis efficiency, reduced while moving, rounded down. Nothing for a genome
// without the capability. Nothing on overflow (refused, never wrapped).
[[nodiscard]] std::optional<std::uint64_t> cellular_light_capture(const biology::Genome& genome,
std::uint32_t extent_um,
const CellularLight& light,
bool moving) noexcept;
} // namespace evo::server
@@ -2,6 +2,7 @@
#include "evo/biology/cellular_region_step.hpp"
#include "evo/biology/mutation.hpp"
#include "evo/server/lifecycle/cellular_light.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include <compare>
@@ -50,13 +51,23 @@ inline constexpr std::uint32_t cellular_lives_maturation_rules = 9;
// ADR-0165: explicit offspring-plan editing mode; expressed bodies retain their genomes.
inline constexpr std::uint32_t cellular_lives_inheritance_format = 8;
inline constexpr std::uint32_t cellular_lives_inheritance_rules = 10;
// ADR-0175: rules 10 with founder 4 (genome schema 5), which can evolve photosynthesis.
// Format 9 is format 8 with the region's declared light and cumulative capture.
inline constexpr std::uint32_t cellular_lives_light_format = 9;
inline constexpr std::uint32_t cellular_lives_photosynthesis_rules = 11;
// Rules that retain offspring plans (formats 8 and 9): 10 and 11.
[[nodiscard]] constexpr bool cellular_retained_plans(std::uint32_t rules) noexcept {
return rules == cellular_lives_inheritance_rules ||
rules == cellular_lives_photosynthesis_rules;
}
inline constexpr std::uint32_t cellular_growth_per_tick = 5; // Per 50 ms; trial rate.
// The founder a region of these rules creates.
[[nodiscard]] constexpr biology::FounderVersion
cellular_founder_version(std::uint32_t rules) noexcept {
return rules >= cellular_lives_reproduction_rules ? biology::primitive_founder_v3
: rules >= cellular_lives_balance_rules ? biology::primitive_founder_v2
: biology::primitive_founder_v1;
return rules >= cellular_lives_photosynthesis_rules ? biology::primitive_founder_v4
: rules >= cellular_lives_reproduction_rules ? biology::primitive_founder_v3
: rules >= cellular_lives_balance_rules ? biology::primitive_founder_v2
: biology::primitive_founder_v1;
}
// ADR-0137: a bud action also yields a twin with probability reproduction / 2 per thousand
// (founders: 25 %), when the reserve funds it and there is room. Seeded per parent and tick.
@@ -283,6 +294,14 @@ class CellularLives {
// ADR-0165: explicit no-tick format-7/rules-9 -> format-8/rules-10 upgrade.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
inheritance_upgrade_candidate() const;
// ADR-0175: explicit no-tick format-8/rules-10 -> format-9/rules-11 upgrade declaring
// the region's light. Existing lineages keep their genome schemas; only founders born
// afterwards can evolve photosynthesis.
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
photosynthesis_upgrade_candidate(CellularLight light) const;
// Format 9: declared light and the energy captured from it, cumulatively.
[[nodiscard]] const CellularLight& light() const noexcept;
[[nodiscard]] accounting::Picojoules captured_light() const noexcept;
[[nodiscard]] std::span<const CellularOffspringRevision> offspring_revisions() const noexcept;
// Latest successful in-memory step report; omitted from snapshots and empty after restore.
[[nodiscard]] std::span<const CellularLifeTickFeedback> last_tick_feedback() const noexcept;
@@ -23,7 +23,9 @@ inline constexpr std::int16_t wildlife_full_speed = 1'000;
// One intention per wildlife life (zero account), sorted by life id: bud when the reserve
// funds one, else steer to and feed from the nearest perceived patch holding energy,
// else wander. Owned lives are left to their players.
// else wander. Owned lives are left to their players. ADR-0175: under rules 11 with
// the region's declared light, a photosynthetic cell that would capture at least its
// maintenance by holding still stays still (it still feeds from whatever it touches).
[[nodiscard]] std::expected<std::vector<CellularLifeIntent>, CellularLivesError>
wildlife_intents(const CellularLives& state, std::uint64_t tick);
} // namespace evo::server