feat(cellular): seed dev wildlife and tune budding playtests
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m16s
Foundation / image (push) Successful in 4m54s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m16s
Foundation / image (push) Successful in 4m54s
This commit is contained in:
@@ -18,6 +18,8 @@ constexpr std::int64_t amount_limit = 1'000'000'000'000'000'000; // pJ or fg per
|
||||
// Schema order is the canonical encoding order.
|
||||
constexpr std::array fields{
|
||||
Field{"tuning.version", &CellularRevampTuning::version, 1, 1'000},
|
||||
Field{"playtest.starting_wildlife_cells",
|
||||
&CellularRevampTuning::playtest_starting_wildlife_cells, 0, 255},
|
||||
Field{"body.essential_upkeep_per_mille", &CellularRevampTuning::body_essential_upkeep_per_mille,
|
||||
0, 1'000},
|
||||
Field{"body.reserve_load_per_mille", &CellularRevampTuning::body_reserve_load_per_mille, 0,
|
||||
@@ -244,12 +246,15 @@ parse_cellular_revamp_tuning(std::string_view text) {
|
||||
tuning.*field.member = *value;
|
||||
}
|
||||
for (std::size_t index = 0; index < fields.size(); ++index)
|
||||
if (!seen.at(index))
|
||||
if (!seen.at(index) && fields.at(index).key != "playtest.starting_wildlife_cells")
|
||||
return std::unexpected{
|
||||
error(CellularTuningErrorKind::missing_key, 0, fields.at(index).key)};
|
||||
if (tuning.version != cellular_revamp_tuning_version)
|
||||
return std::unexpected{
|
||||
error(CellularTuningErrorKind::unsupported_version, 0, "tuning.version")};
|
||||
if (tuning.playtest_starting_wildlife_cells >= tuning.reproduction_organism_cap)
|
||||
return std::unexpected{
|
||||
error(CellularTuningErrorKind::inconsistent, 0, "playtest.starting_wildlife_cells")};
|
||||
if (tuning.mutation_floor_ppm > tuning.mutation_cap_ppm ||
|
||||
tuning.mutation_min_points >= tuning.mutation_max_points)
|
||||
return std::unexpected{
|
||||
|
||||
@@ -403,11 +403,13 @@ std::expected<CommittedCheckpoint, CellularProfileMigrationFailure> migrate_cell
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure> migrate_cellular_revamp_profile(
|
||||
Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, Uuid commit, const Sha256Digest& build,
|
||||
const server::CellularRevampRules& rules, milliseconds timeout, const PublishHooks& hooks) {
|
||||
const server::CellularRevampRules& rules, milliseconds timeout, const PublishHooks& hooks,
|
||||
std::uint32_t count, std::uint64_t first) {
|
||||
return migrate_rules_profile(
|
||||
db, objects, lease, predecessor, commit, build, timeout, hooks,
|
||||
[rules](std::span<const std::uint8_t> payload, const CheckpointManifest& previous) {
|
||||
return cellular_revamp_upgrade_payload(payload, previous, rules);
|
||||
[rules, count, first](std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous) {
|
||||
return cellular_revamp_upgrade_payload(payload, previous, rules, count, first);
|
||||
},
|
||||
cellular_revamp_upgrade_manifest);
|
||||
}
|
||||
@@ -722,6 +724,13 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob
|
||||
if (!target)
|
||||
return fail(RecoveryError::payload);
|
||||
auto upgraded = cellular_revamp_upgrade_payload(*bytes, *source, (*target)->revamp_rules());
|
||||
if (upgraded && !std::ranges::equal(*upgraded, payload) && !(*target)->lives().empty()) {
|
||||
// ADR-0180: the only additional opening input is the explicit fixture identity range.
|
||||
upgraded = cellular_revamp_upgrade_payload(
|
||||
*bytes, *source, (*target)->revamp_rules(),
|
||||
static_cast<std::uint32_t>((*target)->lives().size()),
|
||||
(*target)->lives().front().identity.life);
|
||||
}
|
||||
if (!upgraded || !std::ranges::equal(*upgraded, payload))
|
||||
return fail(RecoveryError::history);
|
||||
} else if (liquid) {
|
||||
|
||||
@@ -261,10 +261,9 @@ cellular_revamp_upgrade_manifest(const CheckpointManifest& previous,
|
||||
return upgrade_manifest(previous, previous_digest, commit, lease, build, bytes, digest,
|
||||
cellular_v14_versions, cellular_v15_versions);
|
||||
}
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
cellular_revamp_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous,
|
||||
const server::CellularRevampRules& rules) {
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError> cellular_revamp_upgrade_payload(
|
||||
std::span<const std::uint8_t> payload, const CheckpointManifest& previous,
|
||||
const server::CellularRevampRules& rules, std::uint32_t count, std::uint64_t first) {
|
||||
if (!supported(previous) || previous.profile != CheckpointProfile::cellular_lives_v1 ||
|
||||
previous.cellular_versions != cellular_v14_versions)
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
@@ -273,7 +272,7 @@ cellular_revamp_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
auto state = restore_cellular_payload(payload, previous);
|
||||
if (!state)
|
||||
return std::unexpected(state.error());
|
||||
auto upgraded = (*state)->revamp_upgrade_candidate(rules);
|
||||
auto upgraded = (*state)->revamp_upgrade_candidate(rules, count, first);
|
||||
if (!upgraded)
|
||||
return std::unexpected(CheckpointError::payload);
|
||||
return (*upgraded)->snapshot();
|
||||
|
||||
@@ -1281,7 +1281,8 @@ const CellularLiquidRules& CellularLives::liquid_rules() const noexcept {
|
||||
return state_->liquid;
|
||||
}
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
||||
CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules) const {
|
||||
CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules, std::uint32_t count,
|
||||
std::uint64_t first) const {
|
||||
if (state_->format_version != cellular_lives_liquid_format ||
|
||||
state_->rules_version != cellular_lives_liquid_rules)
|
||||
return std::unexpected{CellularLivesError::version};
|
||||
@@ -1294,7 +1295,154 @@ CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules) const
|
||||
next.format_version = cellular_lives_revamp_format;
|
||||
next.rules_version = cellular_lives_revamp_rules;
|
||||
next.revamp = rules;
|
||||
return candidate;
|
||||
if (count == 0)
|
||||
return first == 0 ? std::move(candidate) : std::unexpected{CellularLivesError::identity};
|
||||
// ADR-0180: only an explicit, empty opening may contain fixture roots.
|
||||
if (tick() != 1 || !next.lives.empty() || !next.corpses.empty() ||
|
||||
next.archive.archived() != 0 || count >= rules.organism_cap || count > 255 || first == 0 ||
|
||||
first > cellular_bud_namespace - count)
|
||||
return std::unexpected{CellularLivesError::invalid_config};
|
||||
for (std::uint32_t index = 0; index < count; ++index) {
|
||||
const auto id = first + index;
|
||||
const auto founder = biology::primitive_founder(id, id, biology::primitive_founder_v6);
|
||||
if (!founder)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
biology::GenomeDraft draft{
|
||||
.id = id,
|
||||
.origin_event = id,
|
||||
.development_version = 7,
|
||||
.parents = {},
|
||||
.capabilities = {founder->capabilities().begin(), founder->capabilities().end()},
|
||||
.schema_version = biology::genome_schema_v7,
|
||||
.movement_arrangement = biology::founder_movement_arrangement,
|
||||
.cellular_traits = biology::founder_cellular_traits};
|
||||
Random random{mutation_seed(world(), region(), id, 0x57494C44U)};
|
||||
const auto points = [&] { return static_cast<std::uint16_t>(75 + random.next() % 51); };
|
||||
auto& traits = *draft.cellular_traits;
|
||||
traits.density = points();
|
||||
traits.upkeep_efficiency = points();
|
||||
traits.growth_speed = points();
|
||||
for (auto& channel : traits.collection)
|
||||
channel = points();
|
||||
for (auto& channel : traits.burn)
|
||||
channel = points();
|
||||
traits.engulf_capacity = points();
|
||||
traits.kill_absorption = points();
|
||||
auto& movement = *draft.movement_arrangement;
|
||||
movement.output = points();
|
||||
movement.efficiency = points();
|
||||
movement.steering = points();
|
||||
movement.streamlining = points();
|
||||
movement.braking = points();
|
||||
movement.coasting = points();
|
||||
const auto genome = biology::Genome::create(draft);
|
||||
const auto budget =
|
||||
genome ? biology::metabolic_budget(*genome, {1000, 0},
|
||||
{next.config.ambient_temperature_millikelvin, {}},
|
||||
1000, rules.body)
|
||||
: std::unexpected{biology::DevelopmentError::overflow};
|
||||
if (!budget)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
// A normal founder's starting provision, evaluated for its randomized genome.
|
||||
const accounting::Inventory reserve{
|
||||
{budget->demand.value * biology::founder_reserve_seconds}, {}};
|
||||
auto empty_body = accounting::Inventory{};
|
||||
auto nursery = next.nursery;
|
||||
auto heat = next.heat;
|
||||
const auto development = biology::rules_for(genome->development_version());
|
||||
if (!development || !subtract_inventory(nursery, reserve) ||
|
||||
!rebody(empty_body, nursery, heat, budget->body,
|
||||
development->construction_per_kilogram))
|
||||
return std::unexpected{CellularLivesError::insufficient_funding};
|
||||
const auto extent = budget->phenotype.extent;
|
||||
if (next.config.area.width_um <= extent + 2000 ||
|
||||
next.config.area.height_um <= extent + 2000)
|
||||
return std::unexpected{CellularLivesError::no_placement};
|
||||
std::optional<biology::CellularPosition> position;
|
||||
for (int attempt = 0; attempt < 1024 && !position; ++attempt) {
|
||||
const biology::CellularPosition spot{
|
||||
1000 + random.next() % (next.config.area.width_um - extent - 2000),
|
||||
1000 + random.next() % (next.config.area.height_um - extent - 2000)};
|
||||
bool occupied = false;
|
||||
for (const auto& other : next.lives) {
|
||||
const auto body = budget_for(
|
||||
next.archive, other, next.config.ambient_temperature_millikelvin, rules.body);
|
||||
if (!body)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto side = body->phenotype.extent;
|
||||
occupied = occupied || (spot.x_um < other.position.x_um + side &&
|
||||
other.position.x_um < spot.x_um + extent &&
|
||||
spot.y_um < other.position.y_um + side &&
|
||||
other.position.y_um < spot.y_um + extent);
|
||||
}
|
||||
if (!occupied)
|
||||
position = spot;
|
||||
}
|
||||
if (!position)
|
||||
return std::unexpected{CellularLivesError::no_placement};
|
||||
if (!next.archive.admit(*genome) || !next.archive.record_birth(id, id, {tick()}))
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
CellularOwnedLife life{};
|
||||
life.identity = {id, id, id, id, {tick()}};
|
||||
life.source = next.nursery_config.source;
|
||||
life.growth = {1000, 0};
|
||||
life.position = *position;
|
||||
life.body = budget->body;
|
||||
life.reserve = reserve;
|
||||
life.offspring_genome = id;
|
||||
next.lives.push_back(life);
|
||||
next.nursery = nursery;
|
||||
next.nursery_config.funding = nursery;
|
||||
next.heat = heat;
|
||||
}
|
||||
// Restore validates bodies, identities, history and channel-by-channel closure.
|
||||
return restore((*candidate)->snapshot(), world(), region(), frame(), tick());
|
||||
}
|
||||
|
||||
std::optional<accounting::Inventory> CellularLives::budding_cost(std::uint64_t id) const {
|
||||
const auto life =
|
||||
std::ranges::find(state_->lives, id, [](const auto& value) { return value.identity.life; });
|
||||
if (life == state_->lives.end())
|
||||
return std::nullopt;
|
||||
const auto parent = state_->archive.find(life->identity.genome);
|
||||
const auto child = state_->archive.find(cellular_offspring_genome(*life));
|
||||
if (!parent || !child)
|
||||
return std::nullopt;
|
||||
if (state_->rules_version < cellular_lives_revamp_rules)
|
||||
return biology::offspring_cost(*parent, *child, ambient_temperature_millikelvin());
|
||||
auto cost =
|
||||
cellular_mutation_cost({.cost = state_->revamp.bud_fee,
|
||||
.cost_scale_percent = state_->revamp.bud_fee_scale_percent});
|
||||
if (life->revamp.members == 1) {
|
||||
const auto investment =
|
||||
biology::offspring_cost(*parent, *child, ambient_temperature_millikelvin());
|
||||
if (!investment || !add_inventory(cost, *investment))
|
||||
return std::nullopt;
|
||||
} else {
|
||||
const auto traits = parent->cellular_traits().value_or(biology::founder_cellular_traits);
|
||||
const auto added = std::min<std::uint32_t>(1 + (traits.litter + 99U) / 100U,
|
||||
1 + state_->revamp.bounds.max_litter / 100U);
|
||||
const auto grown = organism_genome(*parent, life->revamp.members + added);
|
||||
const auto target = grown
|
||||
? biology::metabolic_budget(*grown, life->growth,
|
||||
{ambient_temperature_millikelvin(), {}},
|
||||
1000, state_->revamp.body)
|
||||
: std::unexpected{biology::DevelopmentError::overflow};
|
||||
const auto development = biology::rules_for(parent->development_version());
|
||||
if (!target || !development)
|
||||
return std::nullopt;
|
||||
std::uint64_t mass{};
|
||||
for (std::size_t c = 0; c < cost.matter.size(); ++c) {
|
||||
const auto difference = target->body.matter[c].value > life->body.matter[c].value
|
||||
? target->body.matter[c].value - life->body.matter[c].value
|
||||
: 0;
|
||||
cost.matter[c].value += difference;
|
||||
mass += difference;
|
||||
}
|
||||
const auto price = development->construction_per_kilogram;
|
||||
cost.energy.value += mass / 1000 * price + mass % 1000 * price / 1000;
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
const CellularRevampRules& CellularLives::revamp_rules() const noexcept {
|
||||
return state_->revamp;
|
||||
|
||||
@@ -51,9 +51,8 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
|
||||
rules.split_share_per_thousand < 1'000 && rules.split_min_growth != 0 &&
|
||||
rules.split_min_growth <= 1'000 && rules.bud_fee_scale_percent <= 100 &&
|
||||
rules.bud_fee.energy.value <= most &&
|
||||
std::ranges::all_of(
|
||||
rules.bud_fee.matter,
|
||||
[](const accounting::Femtograms& f) { return f.value <= most; }) &&
|
||||
std::ranges::all_of(rules.bud_fee.matter,
|
||||
[](const accounting::Femtograms& f) { return f.value <= most; }) &&
|
||||
rules.organism_cap != 0 && rules.organism_cap <= biology::max_cellular_tick_lives &&
|
||||
rules.organism_load_per_thousand <= 10'000 && rules.emerge_members >= 2 &&
|
||||
rules.emerge_members <= 10'000 && rules.emerge_mass_fg <= most &&
|
||||
|
||||
Reference in New Issue
Block a user