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
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:
@@ -22,6 +22,7 @@ constexpr std::uint64_t cellular_lives_v5_magic = 0x3530564C43564541ULL; // AEVC
|
||||
constexpr std::uint64_t cellular_lives_v6_magic = 0x3630564C43564541ULL; // AEVCLV06
|
||||
constexpr std::uint64_t cellular_lives_v7_magic = 0x3730564C43564541ULL; // AEVCLV07
|
||||
constexpr std::uint64_t cellular_lives_v8_magic = 0x3830564C43564541ULL; // AEVCLV08
|
||||
constexpr std::uint64_t cellular_lives_v9_magic = 0x3930564C43564541ULL; // AEVCLV09
|
||||
constexpr std::size_t cellular_lives_header_bytes = 212;
|
||||
constexpr std::size_t cellular_site_bytes = 8;
|
||||
constexpr std::size_t cellular_life_v1_bytes = 168;
|
||||
@@ -39,6 +40,9 @@ constexpr std::size_t cellular_life_v6_bytes = cellular_life_v5_bytes + 16;
|
||||
// Format 7: two boundary-flow inventories and nonresident count/reserved.
|
||||
constexpr std::size_t cellular_lives_v7_header_bytes = cellular_lives_v5_header_bytes + 88;
|
||||
constexpr std::size_t cellular_lives_v8_header_bytes = cellular_lives_v7_header_bytes + 8;
|
||||
// Format 9 (ADR-0175): light numerator, denominator, entitlement, moving share and
|
||||
// reserved (4 each for the last two), and the cumulative captured energy.
|
||||
constexpr std::size_t cellular_lives_v9_header_bytes = cellular_lives_v8_header_bytes + 40;
|
||||
constexpr std::size_t cellular_offspring_revision_bytes = 32;
|
||||
|
||||
std::uint64_t checksum(std::span<const std::uint8_t> bytes) noexcept {
|
||||
@@ -585,6 +589,8 @@ struct CellularLives::State {
|
||||
std::uint64_t next_bud_sequence{1}; // Format 5: the next bud identity's sequence.
|
||||
CellularBoundaryLedger boundary{};
|
||||
std::vector<CellularOffspringRevision> offspring_revisions;
|
||||
CellularLight light{}; // Format 9 (ADR-0175).
|
||||
accounting::Picojoules captured{}; // Format 9: light credited to reserves so far.
|
||||
|
||||
State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id,
|
||||
CellularLivesConfig cfg, NurseryConfig nursery_definition,
|
||||
@@ -803,8 +809,7 @@ CellularLives::migration_replacement(std::vector<CellularOwnedLife> living,
|
||||
std::expected<CellularLives::BoundarySavepoint, CellularLivesError>
|
||||
CellularLives::exchange_boundary(std::span<const biology::CellularPatch> deposits,
|
||||
accounting::Picojoules heat_export) {
|
||||
if (state_->format_version != cellular_lives_migration_format &&
|
||||
state_->format_version != cellular_lives_inheritance_format)
|
||||
if (state_->format_version < cellular_lives_migration_format)
|
||||
return std::unexpected(CellularLivesError::version);
|
||||
if (heat_export.value > state_->heat.energy.value)
|
||||
return std::unexpected(CellularLivesError::conservation);
|
||||
@@ -846,13 +851,13 @@ CellularLives::exchange_boundary(std::span<const biology::CellularPatch> deposit
|
||||
habitat = std::move(*created);
|
||||
}
|
||||
const auto rules = state_->rules_version;
|
||||
const auto total = validate_state(
|
||||
state_->world, state_->region, state_->frame, state_->config, state_->nursery_config,
|
||||
*habitat, state_->lives, state_->corpses, state_->archive, state_->nursery, heat,
|
||||
state_->opening_total, rules >= cellular_lives_engulf_rules,
|
||||
rules >= cellular_lives_bud_rules, state_->next_bud_sequence,
|
||||
rules >= cellular_lives_presence_rules, &boundary,
|
||||
rules == cellular_lives_inheritance_rules ? &state_->offspring_revisions : nullptr);
|
||||
const auto total =
|
||||
validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, *habitat, state_->lives, state_->corpses,
|
||||
state_->archive, state_->nursery, heat, state_->opening_total,
|
||||
rules >= cellular_lives_engulf_rules, rules >= cellular_lives_bud_rules,
|
||||
state_->next_bud_sequence, rules >= cellular_lives_presence_rules, &boundary,
|
||||
cellular_retained_plans(rules) ? &state_->offspring_revisions : nullptr);
|
||||
if (!total)
|
||||
return std::unexpected(total.error());
|
||||
BoundarySavepoint savepoint{std::move(state_->habitat), state_->heat, state_->current_total,
|
||||
@@ -892,6 +897,27 @@ std::span<const CellularLifeTickFeedback> CellularLives::last_tick_feedback() co
|
||||
return last_tick_feedback_;
|
||||
}
|
||||
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
||||
CellularLives::photosynthesis_upgrade_candidate(CellularLight light) const {
|
||||
if (state_->format_version != cellular_lives_inheritance_format ||
|
||||
state_->rules_version != cellular_lives_inheritance_rules)
|
||||
return std::unexpected{CellularLivesError::version};
|
||||
if (!cellular_light_valid(light))
|
||||
return std::unexpected{CellularLivesError::invalid_config};
|
||||
auto candidate = restore(snapshot(), world(), region(), frame(), tick());
|
||||
if (!candidate)
|
||||
return std::unexpected(candidate.error());
|
||||
(*candidate)->state_->format_version = cellular_lives_light_format;
|
||||
(*candidate)->state_->rules_version = cellular_lives_photosynthesis_rules;
|
||||
(*candidate)->state_->light = light;
|
||||
return candidate;
|
||||
}
|
||||
const CellularLight& CellularLives::light() const noexcept {
|
||||
return state_->light;
|
||||
}
|
||||
accounting::Picojoules CellularLives::captured_light() const noexcept {
|
||||
return state_->captured;
|
||||
}
|
||||
std::span<const CellularOffspringRevision> CellularLives::offspring_revisions() const noexcept {
|
||||
return state_->offspring_revisions;
|
||||
}
|
||||
@@ -925,7 +951,8 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
|
||||
const auto corpse_count = state_->corpses.size();
|
||||
const bool parents = state_->format_version >= cellular_lives_bud_format;
|
||||
const bool presence = state_->format_version >= cellular_lives_presence_format;
|
||||
const bool inheritance = state_->format_version == cellular_lives_inheritance_format;
|
||||
const bool inheritance = state_->format_version >= cellular_lives_inheritance_format;
|
||||
const bool lit = state_->format_version == cellular_lives_light_format;
|
||||
const auto life_bytes = inheritance ? cellular_life_v6_bytes + 8
|
||||
: state_->format_version == cellular_lives_legacy_format
|
||||
? cellular_life_v1_bytes
|
||||
@@ -938,10 +965,11 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
|
||||
: causes ? cellular_corpse_v4_bytes
|
||||
: cellular_corpse_bytes;
|
||||
const bool migration = state_->format_version >= cellular_lives_migration_format;
|
||||
const auto header_bytes = inheritance ? cellular_lives_v8_header_bytes
|
||||
: migration ? cellular_lives_v7_header_bytes
|
||||
: parents ? cellular_lives_v5_header_bytes
|
||||
: cellular_lives_header_bytes;
|
||||
const auto header_bytes = lit ? cellular_lives_v9_header_bytes
|
||||
: inheritance ? cellular_lives_v8_header_bytes
|
||||
: migration ? cellular_lives_v7_header_bytes
|
||||
: parents ? cellular_lives_v5_header_bytes
|
||||
: cellular_lives_header_bytes;
|
||||
const auto external_count = migration ? state_->boundary.nonresident_organisms.size() : 0;
|
||||
const auto total_bytes =
|
||||
header_bytes + cellular_site_bytes * site_count + life_bytes * life_count +
|
||||
@@ -966,6 +994,7 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
|
||||
: state_->format_version == cellular_lives_engulf_format ? cellular_lives_v4_magic
|
||||
: state_->format_version == cellular_lives_bud_format ? cellular_lives_v5_magic
|
||||
: state_->format_version == cellular_lives_presence_format ? cellular_lives_v6_magic
|
||||
: lit ? cellular_lives_v9_magic
|
||||
: inheritance ? cellular_lives_v8_magic
|
||||
: migration ? cellular_lives_v7_magic
|
||||
: cellular_lives_v2_magic;
|
||||
@@ -1001,6 +1030,14 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
|
||||
out.put(state_->offspring_revisions.size(), 4);
|
||||
out.put(0, 4);
|
||||
}
|
||||
if (lit) {
|
||||
out.put(state_->light.numerator);
|
||||
out.put(state_->light.denominator);
|
||||
out.put(state_->light.entitlement.value);
|
||||
out.put(state_->light.moving_per_thousand, 4);
|
||||
out.put(0, 4);
|
||||
out.put(state_->captured.value);
|
||||
}
|
||||
for (const auto site : state_->nursery_config.sites)
|
||||
out.site(site);
|
||||
for (const auto& life : state_->lives) {
|
||||
@@ -1267,7 +1304,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
auto lives = state_->lives;
|
||||
lives.push_back({request.account, allocation, state_->nursery_config.source, endowed->growth,
|
||||
*position, endowed->body, endowed->reserve});
|
||||
if (state_->format_version == cellular_lives_inheritance_format)
|
||||
if (state_->format_version >= cellular_lives_inheritance_format)
|
||||
lives.back().offspring_genome = allocation.genome;
|
||||
std::ranges::sort(lives, {}, [](const CellularOwnedLife& life) { return life.identity.life; });
|
||||
|
||||
@@ -1284,7 +1321,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
state_->rules_version >= cellular_lives_bud_rules, state_->next_bud_sequence,
|
||||
state_->rules_version >= cellular_lives_presence_rules,
|
||||
state_->format_version >= cellular_lives_migration_format ? &state_->boundary : nullptr,
|
||||
state_->format_version == cellular_lives_inheritance_format ? &state_->offspring_revisions
|
||||
state_->format_version >= cellular_lives_inheritance_format ? &state_->offspring_revisions
|
||||
: nullptr);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
@@ -1297,6 +1334,8 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
candidate->last_tick_feedback_ = last_tick_feedback_;
|
||||
candidate->state_->next_bud_sequence = state_->next_bud_sequence;
|
||||
candidate->state_->offspring_revisions = state_->offspring_revisions;
|
||||
candidate->state_->light = state_->light;
|
||||
candidate->state_->captured = state_->captured;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
@@ -1319,9 +1358,14 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
format_version == cellular_lives_format &&
|
||||
rules_version == cellular_lives_rules;
|
||||
// Format 6 carries rules 5, 6 (founder 2) or 7 (founder 3, ADR-0137); no new state.
|
||||
const bool inheritance_version = magic == cellular_lives_v8_magic &&
|
||||
format_version == cellular_lives_inheritance_format &&
|
||||
rules_version == cellular_lives_inheritance_rules;
|
||||
// Format 9 is exactly rules 11; format 8 exactly rules 10.
|
||||
const bool light_version = magic == cellular_lives_v9_magic &&
|
||||
format_version == cellular_lives_light_format &&
|
||||
rules_version == cellular_lives_photosynthesis_rules;
|
||||
const bool inheritance_version =
|
||||
light_version ||
|
||||
(magic == cellular_lives_v8_magic && format_version == cellular_lives_inheritance_format &&
|
||||
rules_version == cellular_lives_inheritance_rules);
|
||||
const bool migration_version =
|
||||
inheritance_version ||
|
||||
(magic == cellular_lives_v7_magic && format_version == cellular_lives_migration_format &&
|
||||
@@ -1353,6 +1397,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
return std::unexpected(CellularLivesError::format);
|
||||
if (inheritance_version && bytes.size() < cellular_lives_v8_header_bytes + 8)
|
||||
return std::unexpected(CellularLivesError::format);
|
||||
if (light_version && bytes.size() < cellular_lives_v9_header_bytes + 8)
|
||||
return std::unexpected(CellularLivesError::format);
|
||||
const auto saved_world = in.get();
|
||||
const auto saved_region = in.get();
|
||||
const auto saved_frame = in.get();
|
||||
@@ -1398,6 +1444,19 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
if (in.get(4) != 0 || plan_count > biology::max_archived_genomes)
|
||||
return std::unexpected{CellularLivesError::format};
|
||||
}
|
||||
CellularLight light{};
|
||||
accounting::Picojoules captured{};
|
||||
if (light_version) {
|
||||
light.numerator = in.get();
|
||||
light.denominator = in.get();
|
||||
light.entitlement.value = in.get();
|
||||
light.moving_per_thousand = static_cast<std::uint32_t>(in.get(4));
|
||||
const auto reserved = in.get(4);
|
||||
captured.value = in.get();
|
||||
if (reserved != 0 || !cellular_light_valid(light) ||
|
||||
captured.value > light.entitlement.value)
|
||||
return std::unexpected{CellularLivesError::format};
|
||||
}
|
||||
const auto life_bytes = inheritance_version ? cellular_life_v6_bytes + 8
|
||||
: legacy ? cellular_life_v1_bytes
|
||||
: presence_version ? cellular_life_v6_bytes
|
||||
@@ -1407,10 +1466,11 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
: bud_version ? cellular_corpse_v5_bytes
|
||||
: engulf_version ? cellular_corpse_v4_bytes
|
||||
: cellular_corpse_bytes;
|
||||
const auto expected_size = (inheritance_version ? cellular_lives_v8_header_bytes
|
||||
: migration_version ? cellular_lives_v7_header_bytes
|
||||
: bud_version ? cellular_lives_v5_header_bytes
|
||||
: cellular_lives_header_bytes) +
|
||||
const auto expected_size = (light_version ? cellular_lives_v9_header_bytes
|
||||
: inheritance_version ? cellular_lives_v8_header_bytes
|
||||
: migration_version ? cellular_lives_v7_header_bytes
|
||||
: bud_version ? cellular_lives_v5_header_bytes
|
||||
: cellular_lives_header_bytes) +
|
||||
cellular_site_bytes * site_count + life_bytes * life_count +
|
||||
corpse_bytes * corpse_count + habitat_size + archive_size +
|
||||
nonresident_count * 8 +
|
||||
@@ -1610,6 +1670,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
opening_total, *current, format_version, rules_version, std::move(boundary))}};
|
||||
restored->state_->next_bud_sequence = next_bud_sequence;
|
||||
restored->state_->offspring_revisions = std::move(plan_history);
|
||||
restored->state_->light = light;
|
||||
restored->state_->captured = captured;
|
||||
if (!std::ranges::equal(bytes, restored->snapshot()))
|
||||
return std::unexpected{CellularLivesError::noncanonical};
|
||||
return restored;
|
||||
@@ -1645,7 +1707,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
const bool contact_rules = state_->rules_version >= cellular_lives_foraging_rules;
|
||||
const bool bud_rules = state_->rules_version >= cellular_lives_bud_rules;
|
||||
const bool presence_rules = state_->rules_version >= cellular_lives_presence_rules;
|
||||
const bool inheritance_rules = state_->rules_version == cellular_lives_inheritance_rules;
|
||||
const bool inheritance_rules = cellular_retained_plans(state_->rules_version);
|
||||
for (std::size_t i = 0; i < ordered.size(); ++i) {
|
||||
const auto& intent = ordered[i].intent;
|
||||
// Below rules 4 a bud is ignored, as engulfment is below rules 3 (ADR-0124/0125).
|
||||
@@ -2136,6 +2198,50 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
*total, state_->format_version, state_->rules_version, state_->boundary);
|
||||
next->next_bud_sequence = next_bud_sequence;
|
||||
next->offspring_revisions = std::move(next_offspring_revisions);
|
||||
next->light = state_->light;
|
||||
next->captured = state_->captured;
|
||||
// ADR-0175: light, from this tick's own intentions, credited to every active,
|
||||
// unfrozen photosynthetic survivor's reserve and to the boundary inflow together.
|
||||
if (next->light.numerator != 0) {
|
||||
for (auto& life : next->lives) {
|
||||
const auto left = next->light.entitlement.value - next->captured.value;
|
||||
if (left == 0)
|
||||
break;
|
||||
if (life.presence != CellularPresence::active)
|
||||
continue;
|
||||
const auto genome = next->archive.find(life.identity.genome);
|
||||
if (!genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
if (!genome->carries(biology::Capability::photosynthesis))
|
||||
continue;
|
||||
const auto input = std::ranges::lower_bound(
|
||||
ordered, life.identity.life, {},
|
||||
[](const CellularLifeIntent& value) { return value.life_id; });
|
||||
// Newborn buds had no intention this tick and capture from the next one.
|
||||
if (input == ordered.end() || input->life_id != life.identity.life ||
|
||||
input->intent.frozen)
|
||||
continue;
|
||||
const auto budget =
|
||||
budget_for(next->archive, life, next->config.ambient_temperature_millikelvin);
|
||||
if (!budget)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto energy =
|
||||
cellular_light_capture(*genome, budget->phenotype.extent, next->light,
|
||||
input->intent.movement != biology::CellularIntent{});
|
||||
if (!energy)
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
const auto granted = std::min(*energy, left);
|
||||
constexpr auto most = std::numeric_limits<std::uint64_t>::max();
|
||||
if (granted > most - life.reserve.energy.value ||
|
||||
granted > most - next->boundary.incoming.energy.value ||
|
||||
granted > most - next->current_total.energy.value)
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
life.reserve.energy.value += granted;
|
||||
next->boundary.incoming.energy.value += granted;
|
||||
next->current_total.energy.value += granted;
|
||||
next->captured.value += granted;
|
||||
}
|
||||
}
|
||||
std::vector<CellularLifeTickFeedback> feedback;
|
||||
feedback.reserve(proposal->lives.size());
|
||||
for (const auto& result : proposal->lives) {
|
||||
|
||||
Reference in New Issue
Block a user