feat(lifecycle): add opt-in funded cellular maturation
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 21m0s
Foundation / checks (client) (push) Successful in 22m13s
Foundation / checks (tsan) (push) Successful in 26m35s
Foundation / checks (postgres) (push) Successful in 1h1m27s
Foundation / checks (checks) (push) Successful in 1h14m29s
Foundation / postgres-tools (push) Successful in 1m19s
Foundation / server-image (push) Successful in 3m46s
Foundation / image (push) Successful in 4m57s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 21m0s
Foundation / checks (client) (push) Successful in 22m13s
Foundation / checks (tsan) (push) Successful in 26m35s
Foundation / checks (postgres) (push) Successful in 1h1m27s
Foundation / checks (checks) (push) Successful in 1h14m29s
Foundation / postgres-tools (push) Successful in 1m19s
Foundation / server-image (push) Successful in 3m46s
Foundation / image (push) Successful in 4m57s
This commit is contained in:
@@ -711,6 +711,17 @@ std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
||||
CellularLives::migration_upgrade_candidate() const {
|
||||
return migration_replacement(state_->lives, state_->archive, state_->boundary);
|
||||
}
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
||||
CellularLives::maturation_upgrade_candidate() const {
|
||||
if (state_->format_version != cellular_lives_migration_format ||
|
||||
state_->rules_version != cellular_lives_foraging_rules)
|
||||
return std::unexpected(CellularLivesError::version);
|
||||
auto candidate = restore(snapshot(), world(), region(), frame(), tick());
|
||||
if (!candidate)
|
||||
return std::unexpected(candidate.error());
|
||||
(*candidate)->state_->rules_version = cellular_lives_maturation_rules;
|
||||
return candidate;
|
||||
}
|
||||
std::span<const CellularLifeTickFeedback> CellularLives::last_tick_feedback() const noexcept {
|
||||
return last_tick_feedback_;
|
||||
}
|
||||
@@ -1091,7 +1102,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
// Format 6 carries rules 5, 6 (founder 2) or 7 (founder 3, ADR-0137); no new state.
|
||||
const bool migration_version = magic == cellular_lives_v7_magic &&
|
||||
format_version == cellular_lives_migration_format &&
|
||||
rules_version == cellular_lives_foraging_rules;
|
||||
(rules_version == cellular_lives_foraging_rules ||
|
||||
rules_version == cellular_lives_maturation_rules);
|
||||
const bool presence_version =
|
||||
migration_version ||
|
||||
(magic == cellular_lives_v6_magic && format_version == cellular_lives_presence_format &&
|
||||
@@ -1564,9 +1576,11 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
continue;
|
||||
}
|
||||
const auto offer = found->mutation.offer.value_or(biology::MutationOffer{});
|
||||
auto transition =
|
||||
biology::fund_mutation(*parent, offer.context, offer, selection.operator_id,
|
||||
selection.successor_id, selection.successor_id, found->reserve);
|
||||
auto transition = biology::fund_mutation_at_growth(
|
||||
*parent, offer.context, offer, selection.operator_id, selection.successor_id,
|
||||
selection.successor_id, found->reserve,
|
||||
state_->rules_version >= cellular_lives_maturation_rules ? found->growth
|
||||
: offer.context.growth);
|
||||
if (!transition) {
|
||||
if (transition.error() == biology::MutationError::insufficient_funding) {
|
||||
mutation_results.push_back({selection.life_id, selection.successor_id,
|
||||
@@ -1732,6 +1746,69 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
}
|
||||
}
|
||||
}
|
||||
// ADR-0157: old-size actions finish first. A newborn, frozen life or a life
|
||||
// resuming from suspension did not take an active step and cannot grow here.
|
||||
// Expansion holds the existing lower corner fixed; earlier IDs claim space first.
|
||||
std::vector<CellularGrowthExecution> growth_results;
|
||||
if (state_->rules_version == cellular_lives_maturation_rules) {
|
||||
for (auto& life : next_lives) {
|
||||
const auto input = std::ranges::lower_bound(ordered, life.identity.life, {},
|
||||
&CellularLifeIntent::life_id);
|
||||
const auto previous =
|
||||
std::ranges::lower_bound(state_->lives, life.identity.life, {},
|
||||
[](const auto& old) { return old.identity.life; });
|
||||
if (input == ordered.end() || input->life_id != life.identity.life ||
|
||||
input->intent.frozen || life.presence != CellularPresence::active ||
|
||||
previous == state_->lives.end() || previous->identity.life != life.identity.life ||
|
||||
previous->presence == CellularPresence::suspended ||
|
||||
life.growth.realized_per_thousand == 1000)
|
||||
continue;
|
||||
const auto genome = next_archive.find(life.identity.genome);
|
||||
if (!genome)
|
||||
return std::unexpected(CellularLivesError::archive);
|
||||
const auto budget = biology::metabolic_budget(
|
||||
*genome, life.growth,
|
||||
{state_->config.ambient_temperature_millikelvin, life.reserve},
|
||||
cellular_growth_per_tick);
|
||||
if (!budget || budget->body != life.body)
|
||||
return std::unexpected(CellularLivesError::biology);
|
||||
const auto& move = budget->construction;
|
||||
if (move.after == life.growth)
|
||||
continue;
|
||||
const auto grown = biology::metabolic_budget(
|
||||
*genome, move.after, {state_->config.ambient_temperature_millikelvin, {}});
|
||||
if (!grown)
|
||||
return std::unexpected(CellularLivesError::biology);
|
||||
const auto extent = grown->phenotype.extent;
|
||||
bool clear = extent <= state_->config.area.width_um &&
|
||||
extent <= state_->config.area.height_um &&
|
||||
life.position.x_um <= state_->config.area.width_um - extent &&
|
||||
life.position.y_um <= state_->config.area.height_um - extent;
|
||||
for (const auto& other : next_lives) {
|
||||
if (!clear || other.identity.life == life.identity.life ||
|
||||
other.presence == CellularPresence::suspended)
|
||||
continue;
|
||||
const auto obstacle =
|
||||
budget_for(next_archive, other, state_->config.ambient_temperature_millikelvin);
|
||||
if (!obstacle)
|
||||
return std::unexpected(obstacle.error());
|
||||
clear = separated(life.position.x_um, other.position.x_um, extent,
|
||||
obstacle->phenotype.extent) ||
|
||||
separated(life.position.y_um, other.position.y_um, extent,
|
||||
obstacle->phenotype.extent);
|
||||
}
|
||||
if (!clear)
|
||||
continue; // No partial spatial retry, relocation or spending.
|
||||
if (!subtract_inventory(life.reserve, move.intake) ||
|
||||
!add_inventory(life.reserve, move.release) ||
|
||||
!add_inventory(next_heat, accounting::Inventory{move.intake.energy, {}}))
|
||||
return std::unexpected(CellularLivesError::overflow);
|
||||
growth_results.push_back(
|
||||
{life.identity.life, life.growth, move.after, move.intake, move.release});
|
||||
life.growth = move.after;
|
||||
life.body = grown->body;
|
||||
}
|
||||
}
|
||||
std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism);
|
||||
if (proposal->heat_released.value >
|
||||
std::numeric_limits<std::uint64_t>::max() - next_heat.energy.value)
|
||||
@@ -1829,6 +1906,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
entry = std::prev(feedback.end());
|
||||
}
|
||||
entry->presence = life.presence;
|
||||
if (state_->rules_version == cellular_lives_maturation_rules)
|
||||
entry->reserve = life.reserve; // Includes funded growth/mutation/budding.
|
||||
entry->resume_blocked =
|
||||
std::ranges::find(resume_blocked, life.identity.life) != resume_blocked.end();
|
||||
}
|
||||
@@ -1836,6 +1915,6 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
state_.swap(next);
|
||||
last_tick_feedback_ = std::move(feedback);
|
||||
return CellularTickExecution{std::move(*proposal), std::move(mutation_results),
|
||||
std::move(bud_results)};
|
||||
std::move(bud_results), std::move(growth_results)};
|
||||
}
|
||||
} // namespace evo::server
|
||||
|
||||
@@ -14,7 +14,10 @@ CellularPopulation::CellularPopulation(std::unique_ptr<CellularLives> state,
|
||||
|
||||
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
|
||||
CellularPopulation::create(std::unique_ptr<CellularLives> state, CellularTierPolicy policy) {
|
||||
if (!state || state->rules_version() != cellular_lives_foraging_rules ||
|
||||
if (!state ||
|
||||
(state->rules_version() != cellular_lives_foraging_rules &&
|
||||
!(state->rules_version() == cellular_lives_maturation_rules &&
|
||||
state->format_version() == cellular_lives_migration_format)) ||
|
||||
(state->format_version() != cellular_lives_presence_format &&
|
||||
state->format_version() != cellular_lives_migration_format) ||
|
||||
policy.materialize_radius_um == 0 ||
|
||||
@@ -53,6 +56,18 @@ CellularPopulation::migration_upgrade_candidate() const {
|
||||
(*candidate)->conversion_sequence_ = conversion_sequence_;
|
||||
return candidate;
|
||||
}
|
||||
std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
|
||||
CellularPopulation::maturation_upgrade_candidate() const {
|
||||
auto biological = state_->maturation_upgrade_candidate();
|
||||
if (!biological)
|
||||
return std::unexpected(CellularPopulationError::unsupported);
|
||||
auto candidate = create(std::move(*biological), policy_);
|
||||
if (!candidate)
|
||||
return std::unexpected(candidate.error());
|
||||
(*candidate)->members_ = members_;
|
||||
(*candidate)->conversion_sequence_ = conversion_sequence_;
|
||||
return candidate;
|
||||
}
|
||||
std::expected<std::size_t, CellularPopulationError>
|
||||
CellularPopulation::collapse(std::uint64_t genome) {
|
||||
auto candidate = members_;
|
||||
|
||||
@@ -77,7 +77,8 @@ class Reader {
|
||||
} // namespace
|
||||
|
||||
bool population_interval_safe(const CellularLives& state) noexcept {
|
||||
return state.rules_version() == cellular_lives_foraging_rules &&
|
||||
return (state.rules_version() == cellular_lives_foraging_rules ||
|
||||
state.rules_version() == cellular_lives_maturation_rules) &&
|
||||
std::ranges::all_of(state.lives(), [](const auto& life) {
|
||||
return life.account == LifeAccount{} || life.presence == CellularPresence::suspended;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user