feat(cellular): session v14, bundle 15 and rules-13 wildlife
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s
Session v14 carries the rules-13 revamp: a body block in the owner's view (members, emergence threshold, exclusions, Emerge open, payable energy, mass and the 20 traits), become, emerge and channel exclusions on actions, become on mutation choices, catalog offers (id, chance, cost) and the emerged ending. Older sessions never see a v14 field. The client shows Stay / Become offspring offers named from the shared catalog, continuing as a bud, the organism and its Emerge button, kept channels, the body and the emerged end screen. Bundle 15 (rules 13 on owner format 11) is durable: schema 60 admits it raw-only, stores become as bit 15 of the choice's operator, widens the action input and mutation results, and publishes the 14 -> 15 revamp profile migration. evo-world-clone opens cellular-v10 (cellular-v9 plus the revamp upgrade from --revamp-tuning), resumable and recoverable. Wildlife counts reserve matter as energy, waits for the bud fee, grows organisms one short of emerging, and hunts by the region step's rules-13 engulf test. The play summary adds organisms, offers and the spent pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,7 +107,9 @@ bool valid_action_input(const CellularActionRecord& action, std::uint64_t begin_
|
||||
return !all_zero(action.account) && action.action_id != 0 && tick > begin_tick &&
|
||||
tick <= end_tick && move_x >= -movement_limit && move_x <= movement_limit &&
|
||||
move_y >= -movement_limit && move_y <= movement_limit && input[12] <= 3 &&
|
||||
input[13] <= 1 && all_zero(input.subspan(14, 2)) &&
|
||||
// Flags: brake, become (with a bud) and emerge (no target); then exclusions.
|
||||
input[13] <= 7 && ((input[13] & 2U) == 0 || input[12] == 3) &&
|
||||
((input[13] & 4U) == 0 || input[12] == 0) && input[14] <= 0x0F && input[15] == 0 &&
|
||||
(input[12] == 1 || all_zero(input.subspan(16, 8)));
|
||||
}
|
||||
bool action_less(const CellularActionRecord& a, const CellularActionRecord& b) {
|
||||
@@ -400,7 +402,7 @@ encode_cellular_mutation_input(const CellularMutationActionRecord& action) {
|
||||
put(bytes, action.input.life_id, 8);
|
||||
put(bytes, action.input.event_index, 8);
|
||||
put(bytes, action.input.offer_tick, 8);
|
||||
put(bytes, action.input.operator_id, 2);
|
||||
put(bytes, action.input.operator_id | (action.input.become ? 0x8000U : 0U), 2);
|
||||
std::array<std::uint8_t, cellular_mutation_input_bytes> out{};
|
||||
std::ranges::copy(bytes, out.begin());
|
||||
return out;
|
||||
@@ -418,10 +420,12 @@ decode_cellular_mutation_input(const std::array<std::uint8_t, 16>& account, std:
|
||||
action.input.life_id = get(input, 8, 8);
|
||||
action.input.event_index = get(input, 16, 8);
|
||||
action.input.offer_tick = get(input, 24, 8);
|
||||
action.input.operator_id = static_cast<std::uint16_t>(get(input, 32, 2));
|
||||
const auto stored = static_cast<std::uint16_t>(get(input, 32, 2));
|
||||
action.input.operator_id = static_cast<std::uint16_t>(stored & 0x7FFFU);
|
||||
action.input.become = (stored & 0x8000U) != 0;
|
||||
if (action_id == 0 || action.tick == 0 || action.input.life_id == 0 ||
|
||||
action.input.event_index == 0 || action.input.offer_tick == 0 ||
|
||||
action.input.offer_tick >= action.tick)
|
||||
(action.input.become && action.input.operator_id == 0) || action.input.event_index == 0 ||
|
||||
action.input.offer_tick == 0 || action.input.offer_tick >= action.tick)
|
||||
return std::nullopt;
|
||||
return action;
|
||||
}
|
||||
@@ -517,7 +521,8 @@ encode_cellular_mutation_action_block(std::span<const CellularMutationActionReco
|
||||
put(out, action.input.life_id, 8);
|
||||
put(out, action.input.event_index, 8);
|
||||
put(out, action.input.offer_tick, 8);
|
||||
put(out, action.input.operator_id, 2);
|
||||
// Rules 13: become is bit 15 of the stored operator, as in the reservation input.
|
||||
put(out, action.input.operator_id | (action.input.become ? 0x8000U : 0U), 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
return out;
|
||||
@@ -541,8 +546,11 @@ decode_cellular_mutation_action_block(std::span<const std::uint8_t> bytes, std::
|
||||
action.input.life_id = get(record, 32, 8);
|
||||
action.input.event_index = get(record, 40, 8);
|
||||
action.input.offer_tick = get(record, 48, 8);
|
||||
action.input.operator_id = static_cast<std::uint16_t>(get(record, 56, 2));
|
||||
if (!all_zero(record.subspan(58, 6)))
|
||||
const auto stored = static_cast<std::uint16_t>(get(record, 56, 2));
|
||||
action.input.operator_id = static_cast<std::uint16_t>(stored & 0x7FFFU);
|
||||
action.input.become = (stored & 0x8000U) != 0;
|
||||
if (!all_zero(record.subspan(58, 6)) ||
|
||||
(action.input.become && action.input.operator_id == 0))
|
||||
return std::unexpected{CellularActionBlockError::format};
|
||||
out.push_back(action);
|
||||
offset += cellular_mutation_action_record_bytes;
|
||||
@@ -587,7 +595,10 @@ match_cellular_actions_to_trace(const CellularLives& predecessor, const Cellular
|
||||
intent->intent.movement.y !=
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 10, 2))) ||
|
||||
intent->intent.intake_target != target || intent->intent.engulf != (input[12] == 2) ||
|
||||
intent->intent.bud != (input[12] == 3) || intent->intent.brake != (input[13] == 1))
|
||||
intent->intent.bud != (input[12] == 3) ||
|
||||
intent->intent.brake != ((input[13] & 1U) != 0) ||
|
||||
intent->intent.become != ((input[13] & 2U) != 0) ||
|
||||
intent->intent.emerge != ((input[13] & 4U) != 0) || intent->intent.exclude != input[14])
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
}
|
||||
return {};
|
||||
@@ -623,7 +634,8 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
action.tick == tick && action.input.life_id == selection.life_id &&
|
||||
action.input.event_index == selection.event_index &&
|
||||
action.input.offer_tick == selection.offer_tick &&
|
||||
action.input.operator_id == selection.operator_id;
|
||||
action.input.operator_id == selection.operator_id &&
|
||||
action.input.become == selection.become;
|
||||
});
|
||||
if (matches != 1)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
@@ -645,7 +657,8 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
if (departed == mutations.end() || departed->life_id != action.input.life_id ||
|
||||
departed->event_index != action.input.event_index ||
|
||||
departed->offer_tick != action.input.offer_tick ||
|
||||
departed->operator_id != action.input.operator_id)
|
||||
departed->operator_id != action.input.operator_id ||
|
||||
departed->become != action.input.become)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
continue;
|
||||
}
|
||||
@@ -655,7 +668,24 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto selection = std::ranges::lower_bound(mutations, life->identity.life, {},
|
||||
&CellularMutationSelection::life_id);
|
||||
if (!life->mutation.offer)
|
||||
if (predecessor.rules_version() >= cellular_lives_revamp_rules) {
|
||||
// Rules 13: the catalog offer the life held; operator 0 declines it.
|
||||
const auto& offer = life->revamp.offer;
|
||||
const auto end = offer.ids.begin() + offer.count;
|
||||
if (selection == mutations.end() || selection->life_id != life->identity.life ||
|
||||
selection->event_index != action.input.event_index ||
|
||||
selection->offer_tick != action.input.offer_tick ||
|
||||
selection->operator_id != action.input.operator_id ||
|
||||
selection->become != action.input.become || offer.count == 0 ||
|
||||
offer.event_index != action.input.event_index ||
|
||||
offer.offer_tick != action.input.offer_tick ||
|
||||
life->identity.life != action.input.life_id ||
|
||||
(action.input.operator_id != 0 &&
|
||||
std::ranges::find(offer.ids.begin(), end, action.input.operator_id) == end))
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
continue;
|
||||
}
|
||||
if (!life->mutation.offer || action.input.become)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto offer = life->mutation.offer.value_or(biology::MutationOffer{});
|
||||
if (selection == mutations.end() || selection->life_id != life->identity.life ||
|
||||
|
||||
@@ -1023,6 +1023,11 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
|
||||
}
|
||||
|
||||
std::expected<biology::Genome, CellularLivesError>
|
||||
cellular_organism_genome(const biology::Genome& genome, std::uint32_t members) {
|
||||
return organism_genome(genome, members);
|
||||
}
|
||||
|
||||
bool cellular_can_emerge(const CellularOwnedLife& life, const CellularRevampRules& rules) noexcept {
|
||||
std::uint64_t mass{};
|
||||
for (std::size_t c = 0; c < life.body.matter.size(); ++c)
|
||||
@@ -1084,6 +1089,9 @@ accounting::Inventory CellularLives::nursery() const noexcept {
|
||||
accounting::Inventory CellularLives::heat() const noexcept {
|
||||
return state_->heat;
|
||||
}
|
||||
accounting::Inventory CellularLives::spent() const noexcept {
|
||||
return state_->spent;
|
||||
}
|
||||
accounting::Inventory CellularLives::opening_total() const noexcept {
|
||||
return state_->opening_total;
|
||||
}
|
||||
@@ -3555,6 +3563,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
}
|
||||
if (input == ordered.end() || input->life_id != result.life_id)
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
feedback.back().exclude = input->intent.exclude;
|
||||
}
|
||||
// ADR-0128: each surviving life reports its presence after the tick; a suspended life,
|
||||
// which took no step, reports its unchanged reserve and any blocked resume.
|
||||
|
||||
@@ -15,7 +15,16 @@ summarize_cellular_play(const CellularLives& state) {
|
||||
summary.lingering += life.presence == CellularPresence::lingering ? 1 : 0;
|
||||
summary.suspended += life.presence == CellularPresence::suspended ? 1 : 0;
|
||||
genomes.push_back(life.identity.genome);
|
||||
if (life.revamp.members > 1) {
|
||||
++summary.organisms;
|
||||
summary.largest_organism =
|
||||
std::max<std::uint64_t>(summary.largest_organism, life.revamp.members);
|
||||
}
|
||||
summary.offers_pending += life.revamp.offer.count != 0 ? 1 : 0;
|
||||
summary.offers_earned += life.revamp.events;
|
||||
}
|
||||
for (const auto& channel : state.spent().matter)
|
||||
summary.spent_matter_fg += channel.value;
|
||||
std::ranges::sort(genomes);
|
||||
const auto distinct = std::ranges::unique(genomes);
|
||||
genomes.erase(distinct.begin(), distinct.end());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "evo/server/lifecycle/wildlife_controller.hpp"
|
||||
|
||||
#include "evo/biology/budding.hpp"
|
||||
#include "evo/biology/cellular_burn.hpp"
|
||||
#include "evo/biology/cellular_motion.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -98,6 +99,22 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
{0, -1'000},
|
||||
{707, -707}}};
|
||||
const auto temperature = state.ambient_temperature_millikelvin();
|
||||
// Rules 13 (ADR-0179): organisms develop as their scaled genome, engulf masses carry
|
||||
// reserve matter, membranes are in nanometres, and reserve matter stands in for energy.
|
||||
const bool revamp = state.rules_version() >= cellular_lives_revamp_rules;
|
||||
const auto& revamp_rules = state.revamp_rules();
|
||||
const auto body_genome =
|
||||
[&](const CellularOwnedLife& life) -> std::expected<biology::Genome, CellularLivesError> {
|
||||
const auto genome = state.archive().find(life.identity.genome);
|
||||
if (!genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
return revamp ? cellular_organism_genome(*genome, life.revamp.members)
|
||||
: std::expected<biology::Genome, CellularLivesError>{*genome};
|
||||
};
|
||||
// A life from before the upgrade keeps its membrane in micrometres.
|
||||
const auto membrane_nm = [](const biology::Genome& genome, std::uint32_t membrane) {
|
||||
return genome.cellular_traits() ? membrane : membrane * 1'000;
|
||||
};
|
||||
std::vector<CellularLifeIntent> intents;
|
||||
// Rules 7 prey facts for every cell in the world, derived once per tick: a per-hunter
|
||||
// derivation made the step quadratic in metabolic budgets.
|
||||
@@ -107,6 +124,7 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
std::uint32_t extent{}, membrane{};
|
||||
std::uint64_t mass{};
|
||||
};
|
||||
std::vector<std::uint64_t> engulf_masses; // Rules 13, beside prey_facts.
|
||||
std::vector<Prey> prey_facts;
|
||||
const bool hunting = state.rules_version() >= cellular_lives_reproduction_rules &&
|
||||
std::ranges::any_of(state.lives(), [](const CellularOwnedLife& life) {
|
||||
@@ -117,35 +135,56 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
for (const auto& other : state.lives()) {
|
||||
if (other.presence == CellularPresence::suspended)
|
||||
continue;
|
||||
const auto other_genome = state.archive().find(other.identity.genome);
|
||||
const auto other_genome = body_genome(other);
|
||||
if (!other_genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
return std::unexpected{other_genome.error()};
|
||||
const auto other_budget = biology::metabolic_budget(
|
||||
*other_genome, other.growth, {temperature, {}}, 1000, state.revamp_rules().body);
|
||||
const auto membrane = other_genome->parameter(biology::Capability::membrane);
|
||||
if (!other_budget || !membrane)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
prey_facts.push_back({other.identity.life, other.position,
|
||||
other_budget->phenotype.extent, *membrane,
|
||||
other_budget->phenotype.extent,
|
||||
revamp ? membrane_nm(*other_genome, *membrane) : *membrane,
|
||||
other_budget->phenotype.total_mass});
|
||||
engulf_masses.push_back(biology::cellular_engulf_mass(
|
||||
other_budget->phenotype.total_mass, other.reserve, revamp_rules.step));
|
||||
}
|
||||
}
|
||||
for (const auto& life : state.lives()) {
|
||||
if (life.account != LifeAccount{})
|
||||
continue;
|
||||
const auto genome = state.archive().find(life.identity.genome);
|
||||
if (!genome)
|
||||
const auto expressed = state.archive().find(life.identity.genome);
|
||||
const auto genome = body_genome(life);
|
||||
if (!expressed || !genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
const auto budget = biology::metabolic_budget(*genome, life.growth, {temperature, {}}, 1000,
|
||||
state.revamp_rules().body);
|
||||
if (!budget)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto& traits = expressed->cellular_traits();
|
||||
biology::CellularStepIntent intent{};
|
||||
const auto offspring = state.archive().find(cellular_offspring_genome(life));
|
||||
if (!offspring)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
if ((tick + life.identity.life) % wildlife_bud_interval_ticks == 0 &&
|
||||
biology::fund_offspring(*genome, *offspring, life.growth, life.reserve, temperature)) {
|
||||
// Rules 13: a single cell buds when it can pay the bud and its fee; an organism adds a
|
||||
// member when it can, and stops one short of the emergence threshold (the owner refuses
|
||||
// what it cannot fund).
|
||||
const auto fee =
|
||||
revamp
|
||||
? cellular_mutation_cost({.cost = revamp_rules.bud_fee,
|
||||
.cost_scale_percent = revamp_rules.bud_fee_scale_percent})
|
||||
: accounting::Inventory{};
|
||||
bool fee_paid = life.reserve.energy.value >= fee.energy.value;
|
||||
for (std::size_t c = 0; c < fee.matter.size(); ++c)
|
||||
fee_paid = fee_paid && life.reserve.matter[c].value >= fee.matter[c].value;
|
||||
const bool organism = revamp && life.revamp.members > 1;
|
||||
const bool may_bud =
|
||||
organism ? fee_paid && life.revamp.members + 1U < revamp_rules.emerge_members
|
||||
: fee_paid && biology::fund_offspring(*expressed, *offspring, life.growth,
|
||||
life.reserve, temperature)
|
||||
.has_value();
|
||||
if ((tick + life.identity.life) % wildlife_bud_interval_ticks == 0 && may_bud) {
|
||||
intent.bud = true;
|
||||
intents.push_back({life.identity.life, intent});
|
||||
continue;
|
||||
@@ -156,12 +195,18 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
// players' cells included; otherwise feed.
|
||||
if (hunting) {
|
||||
bool prey = false;
|
||||
for (const auto& other : prey_facts) {
|
||||
const auto hunter_mass = biology::cellular_engulf_mass(budget->phenotype.total_mass,
|
||||
life.reserve, revamp_rules.step);
|
||||
const auto capacity = traits ? traits->engulf_capacity : std::uint16_t{100};
|
||||
for (std::size_t k = 0; k < prey_facts.size(); ++k) {
|
||||
const auto& other = prey_facts[k];
|
||||
if (other.life == life.identity.life ||
|
||||
!biology::cellular_footprints_contact(life.position, extent, other.position,
|
||||
other.extent))
|
||||
continue;
|
||||
if (can_engulf(budget->phenotype.total_mass, other.mass, other.membrane)) {
|
||||
if (revamp ? biology::cellular_engulfable(hunter_mass, capacity, engulf_masses[k],
|
||||
other.membrane, revamp_rules.step)
|
||||
: can_engulf(budget->phenotype.total_mass, other.mass, other.membrane)) {
|
||||
prey = true;
|
||||
break;
|
||||
}
|
||||
@@ -190,9 +235,21 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
// Rules 11: a cell short of energy forages for energy (wildlife_food).
|
||||
const auto demand_period = budget->rate_microseconds / 50'000;
|
||||
const auto demand_per_tick = demand_period == 0 ? 0 : budget->demand.value / demand_period;
|
||||
const bool hungry =
|
||||
state.rules_version() >= cellular_lives_photosynthesis_rules && demand_per_tick != 0 &&
|
||||
life.reserve.energy.value / demand_per_tick < wildlife_energy_hunger_ticks;
|
||||
// Rules 13: burnable reserve matter stands in for energy, so a cell rich in matter is
|
||||
// not hungry.
|
||||
const auto payable =
|
||||
revamp
|
||||
? biology::cellular_payable_energy(
|
||||
life.reserve,
|
||||
biology::cellular_burn(
|
||||
revamp_rules.burn_pj_per_kfg,
|
||||
traits ? traits->burn : std::array<std::uint16_t, 4>{100, 100, 100, 100},
|
||||
0),
|
||||
false)
|
||||
: life.reserve.energy.value;
|
||||
const bool hungry = state.rules_version() >= cellular_lives_photosynthesis_rules &&
|
||||
demand_per_tick != 0 &&
|
||||
payable / demand_per_tick < wildlife_energy_hunger_ticks;
|
||||
const auto chosen = wildlife_food(*perceived, centre_x, centre_y, deposits, hungry);
|
||||
const auto nearest = chosen ? std::optional{chosen->address} : std::nullopt;
|
||||
if (nearest && deposits && chosen) {
|
||||
|
||||
Reference in New Issue
Block a user