feat(biology): genome schema 6 movement arrangement and derived handling
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m26s
Foundation / postgres-tools (push) Successful in 19s
Foundation / image (push) Successful in 3m57s
Foundation / server-image (push) Successful in 4m2s

Schema 6 genomes carry the body's movement arrangement for mutations 001-010 as
reference-point indices (100 = founder): output, efficiency, burst, steering,
streamlining, braking, anchor, coasting and colony drive. It is encoded after the
capability records and covered by the digest; older schemas refuse it, so their
capability tables and mutation catalogs are unchanged. Development version 6 and
founder 5 serve rules 12.

derive_cellular_handling scales the tuned founder handling by the arrangement:
output scales thrust, braking reverse thrust, steering turning; streamlining lowers
forward drag and coasting both drags. Full-output costs follow the metabolic
budget's movement cost times output over efficiency. Shed output or a missing
movement capability leaves only passive drift. Refreshes the DEV session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-21 16:39:09 -04:00
co-authored by Claude Opus 5.5
parent ab5df35c3f
commit 2bffbc2095
16 changed files with 285 additions and 20 deletions
+47
View File
@@ -1,5 +1,8 @@
#include "evo/biology/cellular_tuning.hpp"
#include "evo/accounting/rates.hpp"
#include <algorithm>
#include <array>
#include <optional>
@@ -245,4 +248,48 @@ CellularHandling founder_cellular_handling(const CellularTuning& tuning,
.thrust_cost = thrust_cost,
.reverse_cost = reverse_cost};
}
std::expected<CellularHandling, CellularHandlingError>
derive_cellular_handling(const Genome& genome, const MetabolicBudget& budget,
const CellularTuning& tuning) {
const auto& arrangement = genome.movement_arrangement();
if (!arrangement || genome.development_version() < 6)
return std::unexpected{CellularHandlingError::unsupported_genome};
if (budget.rate_microseconds != accounting::microseconds_per_second)
return std::unexpected{CellularHandlingError::unsupported_rate};
const auto full_cost = accounting::per_tick(
budget.movement.value, cellular_motion_tick_microseconds, accounting::Rounding::up);
if (!full_cost || *full_cost > std::uint64_t{1} << 40U)
return std::unexpected{CellularHandlingError::overflow};
const auto founder = founder_cellular_handling(tuning, {}, {});
const auto& a = *arrangement;
constexpr std::uint64_t reference = movement_reference_points;
const auto scale = [](std::uint64_t value, std::uint64_t index) {
return value * index / reference;
};
const auto cost = [&](std::uint64_t index) {
const auto product = *full_cost * index;
return accounting::Picojoules{product / a.efficiency +
(product % a.efficiency != 0 ? 1 : 0)};
};
constexpr std::uint64_t drag_limit = cellular_drag_ppm_limit - 1;
CellularHandling handling{};
handling.forward_drag_ppm = static_cast<std::uint32_t>(
std::min<std::uint64_t>(drag_limit, founder.forward_drag_ppm * reference * reference /
(std::uint64_t{a.streamlining} * a.coasting)));
handling.lateral_drag_ppm = static_cast<std::uint32_t>(
std::min<std::uint64_t>(drag_limit, founder.lateral_drag_ppm * reference / a.coasting));
if (!genome.carries(Capability::movement) || a.output == 0)
return handling;
constexpr std::uint64_t velocity_limit = cellular_velocity_limit_q10;
handling.thrust_q10 =
static_cast<std::uint32_t>(std::min(velocity_limit, scale(founder.thrust_q10, a.output)));
handling.reverse_thrust_q10 = static_cast<std::uint32_t>(
std::min(velocity_limit, scale(founder.reverse_thrust_q10, a.braking)));
handling.turn = static_cast<std::uint16_t>(
std::min<std::uint64_t>(cellular_heading_turn / 2, scale(founder.turn, a.steering)));
handling.thrust_cost = cost(a.output);
handling.reverse_cost = cost(a.braking);
return handling;
}
} // namespace evo::biology
+3 -1
View File
@@ -70,7 +70,9 @@ std::expected<DevelopmentRules, DevelopmentError> rules_for(std::uint32_t develo
// Version 4 (rules 7, ADR-0137) keeps version 3's rules; only what reproduction
// means changes (metabolism.cpp).
// Version 5 (ADR-0175) keeps them too; it adds photosynthetic organelles below.
if (development_version >= 3 && development_version <= 5) {
// Version 6 (rules 12) keeps version 5's body; handling comes from the genome's movement
// arrangement (derive_cellular_handling).
if (development_version >= 3 && development_version <= 6) {
return DevelopmentRules{1000, 1200, 10, 15, 13, 60'000, 293'150, 50};
}
return std::unexpected{DevelopmentError::unsupported_rules};
+2
View File
@@ -17,6 +17,8 @@ std::expected<Genome, GenomeError> primitive_founder(std::uint64_t id, std::uint
{Capability::ingestion, p.ingestion, 0},
{Capability::reproduction, p.reproduction, 0},
{Capability::target_size, p.target_size, 0}};
if (version.genome_schema >= genome_schema_v6)
draft.movement_arrangement = founder_movement_arrangement;
return Genome::create(draft);
}
+50 -1
View File
@@ -13,6 +13,35 @@ constexpr std::size_t parent_size = 8;
constexpr std::size_t record_size = 9;
constexpr std::size_t digest_size = 8;
constexpr std::size_t checksum_size = 8;
// Schema 6: nine 16-bit movement indices after the capability records.
constexpr std::size_t arrangement_count = 9;
constexpr std::size_t arrangement_size = arrangement_count * 2;
bool has_arrangement(std::uint32_t schema) noexcept {
return schema >= genome_schema_v6;
}
std::array<std::uint16_t, arrangement_count> indices(const MovementArrangement& a) noexcept {
return {a.output, a.efficiency, a.burst, a.steering, a.streamlining,
a.braking, a.anchor, a.coasting, a.colony_drive};
}
// Required from schema 6 and refused before it. Parts a body cannot lack (efficiency,
// steering, streamlining, braking, coasting) are at least 1; acquired modules and shed
// output may be 0.
bool valid_arrangement(std::uint32_t schema,
const std::optional<MovementArrangement>& arrangement) noexcept {
if (!has_arrangement(schema))
return !arrangement.has_value();
if (!arrangement)
return false;
const auto& a = *arrangement;
for (const auto value : indices(a))
if (value > max_movement_points)
return false;
return a.efficiency != 0 && a.steering != 0 && a.streamlining != 0 && a.braking != 0 &&
a.coasting != 0;
}
// Accidental-corruption detection only, per ADR-0008. Not authenticity.
std::uint64_t checksum(std::span<const std::uint8_t> bytes) noexcept {
@@ -172,6 +201,9 @@ std::vector<std::uint8_t> Genome::body() const {
append(bytes, record.parameter, 4);
append(bytes, record.prerequisites, 4);
}
if (movement_arrangement_)
for (const auto value : indices(*movement_arrangement_))
append(bytes, value, 2);
return bytes;
}
@@ -194,6 +226,9 @@ std::expected<Genome, GenomeError> Genome::create(const GenomeDraft& draft) {
!valid) {
return std::unexpected{valid.error()};
}
if (!valid_arrangement(draft.schema_version, draft.movement_arrangement)) {
return std::unexpected{GenomeError::parameter_out_of_range};
}
Genome genome;
genome.schema_version_ = draft.schema_version;
genome.id_ = draft.id;
@@ -201,6 +236,7 @@ std::expected<Genome, GenomeError> Genome::create(const GenomeDraft& draft) {
genome.development_version_ = draft.development_version;
genome.parents_ = draft.parents;
genome.capabilities_ = std::move(ordered);
genome.movement_arrangement_ = draft.movement_arrangement;
genome.digest_ = digest_of(genome.body());
return genome;
}
@@ -241,8 +277,9 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
return std::unexpected{GenomeError::duplicate_capability};
}
// An exact length match rejects trailing bytes rather than ignoring them.
const auto arrangement_bytes = has_arrangement(schema) ? arrangement_size : 0;
const auto expected = counted + static_cast<std::size_t>(record_count) * record_size +
digest_size + checksum_size;
arrangement_bytes + digest_size + checksum_size;
if (bytes.size() != expected) {
return std::unexpected{GenomeError::invalid_encoding};
}
@@ -261,10 +298,21 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
const auto prerequisites = static_cast<std::uint32_t>(reader.read(4));
capabilities.push_back({static_cast<Capability>(kind), parameter, prerequisites});
}
std::optional<MovementArrangement> arrangement;
if (has_arrangement(schema)) {
std::array<std::uint16_t, arrangement_count> read{};
for (auto& value : read)
value = static_cast<std::uint16_t>(reader.read(2));
arrangement = MovementArrangement{read[0], read[1], read[2], read[3], read[4],
read[5], read[6], read[7], read[8]};
}
if (const auto valid = validate(schema, id, origin, development, parents, capabilities);
!valid) {
return std::unexpected{valid.error()};
}
if (!valid_arrangement(schema, arrangement)) {
return std::unexpected{GenomeError::parameter_out_of_range};
}
Genome genome;
genome.schema_version_ = schema;
genome.id_ = id;
@@ -272,6 +320,7 @@ std::expected<Genome, GenomeError> Genome::decode(std::span<const std::uint8_t>
genome.development_version_ = development;
genome.parents_ = std::move(parents);
genome.capabilities_ = std::move(capabilities);
genome.movement_arrangement_ = arrangement;
// The body must reproduce exactly, so a rewritten record is rejected.
const auto digest = digest_of(genome.body());
if (digest != reader.read(digest_size)) {
+3 -3
View File
@@ -109,8 +109,8 @@ metabolic_rules_for(std::uint32_t development_version) {
return MetabolicRules{structure_shares, membrane_shares, 20, 50'000};
}
// Version 2: per second; movement at 1000 um/s costs 50 pJ/s per 1000 fg (tunable).
// Versions 3, 4 and 5: the same metabolism.
if (development_version >= 2 && development_version <= 5) {
// Versions 3 to 6: the same metabolism.
if (development_version >= 2 && development_version <= 6) {
return MetabolicRules{structure_shares, membrane_shares, 50, 50'000};
}
return std::unexpected{DevelopmentError::unsupported_rules};
@@ -209,7 +209,7 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
// Version 4 (ADR-0137): a bud is always half the body, and reproduction is skill:
// it takes up to half off the bud's construction energy (value / 2000). Matter is
// never discounted (ADR-0118). Earlier versions invest `value` per thousand.
const bool skill = genome.development_version() >= 4; // Versions 4 and 5.
const bool skill = genome.development_version() >= 4; // Versions 4 to 6.
const auto fraction = skill ? bud_body_per_thousand_v4 : value;
// A parent divides the body it has, so the investment keeps its composition.
budget.reproduction_investment = fraction_of(budget.body, fraction);
+2 -1
View File
@@ -39,7 +39,7 @@ constexpr std::array<MutationOperator, 4 * capability_count> catalog = [] {
constexpr std::uint32_t adjustment_step(const std::array<CapabilitySpec, capability_count>& table,
Capability kind, std::uint32_t schema,
std::uint32_t current) noexcept {
if (schema == genome_schema_v4 || schema == genome_schema_v5)
if (schema == genome_schema_v4 || schema == genome_schema_v5 || schema == genome_schema_v6)
return current / 10 == 0 ? 1 : current / 10;
const auto& limits = table[static_cast<std::size_t>(kind)];
const auto span = limits.maximum - limits.minimum;
@@ -103,6 +103,7 @@ std::optional<GenomeDraft> apply(const Genome& genome, const MutationOperator& e
draft.development_version = genome.development_version();
draft.parents = {genome.id()};
draft.capabilities.assign(genome.capabilities().begin(), genome.capabilities().end());
draft.movement_arrangement = genome.movement_arrangement();
const auto& table = *capability_schema_for(genome.schema_version());
const auto& limits = table[static_cast<std::size_t>(entry.target)];
const auto carried =