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
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:
@@ -12,7 +12,7 @@ spec:
|
||||
env:
|
||||
- {name: REGION_SESSION, value: "dev"}
|
||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261021T202403-5ff7fcb7:1792628643"}
|
||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261021T203908-f12a35b4:1792629548"}
|
||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||
ports:
|
||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/biology/cellular_kinematics.hpp"
|
||||
#include "evo/biology/metabolism.hpp"
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
@@ -78,4 +79,15 @@ parse_cellular_tuning(std::string_view text);
|
||||
[[nodiscard]] CellularHandling founder_cellular_handling(const CellularTuning& tuning,
|
||||
accounting::Picojoules thrust_cost,
|
||||
accounting::Picojoules reverse_cost);
|
||||
|
||||
enum class CellularHandlingError : std::uint8_t { unsupported_genome, unsupported_rate, overflow };
|
||||
// Development 6: an organism's handling from its movement arrangement, scaled from the
|
||||
// founder's tuned handling (index 100 = founder). Output scales thrust, braking scales
|
||||
// reverse thrust, steering scales turning; streamlining lowers forward drag only and
|
||||
// coasting lowers both, so a coasting body also tops out faster. Full-output costs per tick
|
||||
// are the budget's full-speed movement cost times output (or braking) over efficiency.
|
||||
// Without the movement capability or with shed output, the body cannot thrust or turn.
|
||||
[[nodiscard]] std::expected<CellularHandling, CellularHandlingError>
|
||||
derive_cellular_handling(const Genome& genome, const MetabolicBudget& budget,
|
||||
const CellularTuning& tuning);
|
||||
} // namespace evo::biology
|
||||
|
||||
@@ -32,8 +32,8 @@ inline constexpr std::uint64_t development_v2_rate_microseconds = 1'000'000;
|
||||
[[nodiscard]] constexpr std::uint64_t
|
||||
development_rate_microseconds(std::uint32_t development_version) noexcept {
|
||||
return development_version == 1 ? development_v1_tick_microseconds
|
||||
: development_version >= 2 && development_version <= 5
|
||||
? development_v2_rate_microseconds // Versions 3-5 keep version 2's rates.
|
||||
: development_version >= 2 && development_version <= 6
|
||||
? development_v2_rate_microseconds // Versions 3-6 keep version 2's rates.
|
||||
: 0;
|
||||
}
|
||||
// Chosen constants, reviewable as a unit and selected by the genome's
|
||||
|
||||
@@ -37,6 +37,9 @@ inline constexpr FounderVersion primitive_founder_v3{genome_schema_v4, 4};
|
||||
// Founder 4 serves rules 11 (ADR-0175): founder 3 that can evolve photosynthesis. Founders
|
||||
// start without it; the capability is only ever earned through mutation.
|
||||
inline constexpr FounderVersion primitive_founder_v4{genome_schema_v5, 5};
|
||||
// Founder 5 serves rules 12 (Cellular_Region_Movement_Plan.md): founder 4 with the founder
|
||||
// movement arrangement (every index at the 100-point reference).
|
||||
inline constexpr FounderVersion primitive_founder_v5{genome_schema_v6, 6};
|
||||
inline constexpr std::uint32_t primitive_founder_development_version =
|
||||
primitive_founder_v1.development_version;
|
||||
// The founder genome under a world-scoped identity and its origin event. Fails only on
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
@@ -99,6 +100,19 @@ struct CapabilityRecord {
|
||||
std::uint32_t prerequisites{};
|
||||
auto operator<=>(const CapabilityRecord&) const = default;
|
||||
};
|
||||
// Schema 6 (Cellular_movement_draft.md 001-010): the body's movement arrangement as
|
||||
// indices in reference points, where 100 is the founder's arrangement. Burst, anchor and
|
||||
// colony drive are acquired modules: 0 means absent. Output 0 means propulsion was shed
|
||||
// (009); independent propulsion also needs the movement capability.
|
||||
struct MovementArrangement {
|
||||
std::uint16_t output{}, efficiency{}, burst{}, steering{}, streamlining{}, braking{}, anchor{},
|
||||
coasting{}, colony_drive{};
|
||||
auto operator<=>(const MovementArrangement&) const = default;
|
||||
};
|
||||
inline constexpr std::uint16_t movement_reference_points = 100;
|
||||
inline constexpr std::uint16_t max_movement_points = 1'000;
|
||||
inline constexpr MovementArrangement founder_movement_arrangement{100, 100, 0, 100, 100,
|
||||
100, 0, 100, 0};
|
||||
// Unvalidated input. Only Genome::create turns one into a record.
|
||||
struct GenomeDraft {
|
||||
std::uint64_t id{};
|
||||
@@ -110,6 +124,8 @@ struct GenomeDraft {
|
||||
// literal keeps its meaning (rates per 50 ms tick); new records name schema 2. Last,
|
||||
// so positional initialisers are unaffected.
|
||||
std::uint32_t schema_version{1};
|
||||
// Required from schema 6 and refused before it.
|
||||
std::optional<MovementArrangement> movement_arrangement{};
|
||||
};
|
||||
enum class GenomeError : std::uint8_t {
|
||||
unsupported_version,
|
||||
@@ -134,16 +150,19 @@ inline constexpr std::uint32_t genome_schema_v3 = 3;
|
||||
inline constexpr std::uint32_t genome_schema_v4 = 4;
|
||||
// Schema 5 (rules 11, ADR-0175): schema 4's steps with the photosynthesis capability.
|
||||
inline constexpr std::uint32_t genome_schema_v5 = 5;
|
||||
// Schema 6 (rules 12, Cellular_Region_Movement_Plan.md): schema 5's capabilities and steps
|
||||
// plus the movement arrangement.
|
||||
inline constexpr std::uint32_t genome_schema_v6 = 6;
|
||||
// The newest schema. Older records stay valid and are never rewritten (ADR-0099).
|
||||
inline constexpr std::uint32_t genome_schema_version = genome_schema_v5;
|
||||
// The capability table of a supported schema (1 to 5); nullptr otherwise.
|
||||
inline constexpr std::uint32_t genome_schema_version = genome_schema_v6;
|
||||
// The capability table of a supported schema (1 to 6); nullptr otherwise.
|
||||
[[nodiscard]] constexpr const std::array<CapabilitySpec, capability_count>*
|
||||
capability_schema_for(std::uint32_t schema) noexcept {
|
||||
return schema == genome_schema_v1 ? &capability_schema_v1
|
||||
: schema == genome_schema_v2 || schema == genome_schema_v3 || schema == genome_schema_v4
|
||||
? &capability_schema_v2
|
||||
: schema == genome_schema_v5 ? &capability_schema_v5
|
||||
: nullptr;
|
||||
: schema == genome_schema_v5 || schema == genome_schema_v6 ? &capability_schema_v5
|
||||
: nullptr;
|
||||
}
|
||||
inline constexpr std::size_t max_parents = 2;
|
||||
inline constexpr std::size_t max_genome_bytes = 256;
|
||||
@@ -182,6 +201,10 @@ class Genome {
|
||||
[[nodiscard]] std::span<const CapabilityRecord> capabilities() const noexcept {
|
||||
return capabilities_;
|
||||
}
|
||||
// Present exactly from schema 6.
|
||||
[[nodiscard]] const std::optional<MovementArrangement>& movement_arrangement() const noexcept {
|
||||
return movement_arrangement_;
|
||||
}
|
||||
[[nodiscard]] bool carries(Capability kind) const noexcept;
|
||||
[[nodiscard]] std::expected<std::uint32_t, GenomeError>
|
||||
parameter(Capability kind) const noexcept;
|
||||
@@ -206,6 +229,7 @@ class Genome {
|
||||
std::uint32_t development_version_{};
|
||||
std::vector<std::uint64_t> parents_;
|
||||
std::vector<CapabilityRecord> capabilities_;
|
||||
std::optional<MovementArrangement> movement_arrangement_;
|
||||
std::uint64_t digest_{};
|
||||
};
|
||||
} // namespace evo::biology
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "evo/accounting/rates.hpp"
|
||||
#include "evo/biology/cellular_tuning.hpp"
|
||||
#include "evo/biology/founder.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
@@ -125,6 +127,81 @@ void founder_handling() {
|
||||
CHECK(handling.thrust_cost.value == 1'000 && handling.reverse_cost.value == 900);
|
||||
}
|
||||
|
||||
Genome founder_genome(const MovementArrangement& arrangement, bool movement = true) {
|
||||
const auto founder = primitive_founder(1, 1, primitive_founder_v5);
|
||||
check(founder.has_value());
|
||||
GenomeDraft draft{2, 2, 6, {1}, {}, genome_schema_v6, arrangement};
|
||||
for (const auto& record : founder->capabilities())
|
||||
if (movement || record.kind != Capability::movement)
|
||||
draft.capabilities.push_back(record);
|
||||
const auto genome = Genome::create(draft);
|
||||
check(genome.has_value());
|
||||
return *genome;
|
||||
}
|
||||
|
||||
CellularHandling handling_of(const Genome& genome) {
|
||||
const auto budget = metabolic_budget(genome, {1'000, 0}, {293'150, {}});
|
||||
check(budget.has_value());
|
||||
const auto handling = derive_cellular_handling(genome, *budget, v0());
|
||||
check(handling.has_value());
|
||||
return *handling;
|
||||
}
|
||||
|
||||
void derived_handling() {
|
||||
const auto founder = primitive_founder(1, 1, primitive_founder_v5);
|
||||
CHECK(founder && founder->movement_arrangement() == founder_movement_arrangement);
|
||||
const auto budget = metabolic_budget(*founder, {1'000, 0}, {293'150, {}});
|
||||
CHECK(budget);
|
||||
const auto base = handling_of(*founder);
|
||||
// The founder arrangement reproduces the tuned founder handling exactly.
|
||||
const auto full =
|
||||
*evo::accounting::per_tick(budget->movement.value, 50'000, evo::accounting::Rounding::up);
|
||||
CHECK(base == founder_cellular_handling(v0(), {full}, {full}));
|
||||
CHECK(full > 0);
|
||||
|
||||
auto a = founder_movement_arrangement;
|
||||
a.output = 105; // 001: more thrust, costing more per tick.
|
||||
const auto strong = handling_of(founder_genome(a));
|
||||
CHECK(strong.thrust_q10 == 21'504 && strong.thrust_cost.value > base.thrust_cost.value);
|
||||
CHECK(strong.reverse_thrust_q10 == base.reverse_thrust_q10);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.efficiency = 105; // 002: same thrust, cheaper.
|
||||
const auto economical = handling_of(founder_genome(a));
|
||||
CHECK(economical.thrust_q10 == base.thrust_q10 &&
|
||||
economical.thrust_cost.value < base.thrust_cost.value);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.steering = 105; // 004
|
||||
CHECK(handling_of(founder_genome(a)).turn == 3'439);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.streamlining = 105; // 005: forward drag only.
|
||||
const auto straight = handling_of(founder_genome(a));
|
||||
CHECK(straight.forward_drag_ppm == 90'631 && straight.lateral_drag_ppm == 95'163);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.braking = 105; // 006
|
||||
CHECK(handling_of(founder_genome(a)).reverse_thrust_q10 == 21'504);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.coasting = 105; // 008: both drags at 100/105, about 95.24%.
|
||||
const auto coaster = handling_of(founder_genome(a));
|
||||
CHECK(coaster.forward_drag_ppm == 90'631 && coaster.lateral_drag_ppm == 90'631);
|
||||
|
||||
a = founder_movement_arrangement;
|
||||
a.output = 0; // 009: shed propulsion drifts but cannot thrust or turn.
|
||||
const auto shed = handling_of(founder_genome(a));
|
||||
CHECK(shed.thrust_q10 == 0 && shed.reverse_thrust_q10 == 0 && shed.turn == 0);
|
||||
CHECK(shed.thrust_cost.value == 0 && shed.forward_drag_ppm == base.forward_drag_ppm);
|
||||
CHECK(handling_of(founder_genome(founder_movement_arrangement, false)).thrust_q10 == 0);
|
||||
|
||||
const auto old = primitive_founder(1, 1, primitive_founder_v4);
|
||||
CHECK(old);
|
||||
const auto old_budget = metabolic_budget(*old, {1'000, 0}, {293'150, {}});
|
||||
CHECK(old_budget && !derive_cellular_handling(*old, *old_budget, v0()));
|
||||
}
|
||||
|
||||
// The checked-in DEV tuning file must parse; CTest passes its path when it is present.
|
||||
void repository_file(const char* path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
@@ -145,6 +222,7 @@ int main(int argc, char** argv) {
|
||||
comments_separators_and_whitespace();
|
||||
refusals();
|
||||
founder_handling();
|
||||
derived_handling();
|
||||
if (argc > 1)
|
||||
repository_file(argv[1]);
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -174,12 +174,12 @@ void rule_versions_and_invalid_growth() {
|
||||
v3->structure_density == v2->structure_density &&
|
||||
v3->maintenance_per_kilogram == v2->maintenance_per_kilogram &&
|
||||
development_rate_microseconds(3) == development_rate_microseconds(2));
|
||||
for (const auto version : {0U, 6U, 99U}) {
|
||||
for (const auto version : {0U, 7U, 99U}) {
|
||||
const auto missing = rules_for(version);
|
||||
CHECK(!missing && missing.error() == DevelopmentError::unsupported_rules);
|
||||
}
|
||||
auto source = draft();
|
||||
source.development_version = 6; // Version 5 exists since rules 11 (ADR-0175).
|
||||
source.development_version = 7; // Version 6 exists since rules 12.
|
||||
const auto future = build(source);
|
||||
const auto derived = derive_phenotype(future, {1000, 0}, temperate);
|
||||
CHECK(!derived && derived.error() == DevelopmentError::unsupported_rules);
|
||||
|
||||
+49
-2
@@ -362,10 +362,10 @@ void schema_v2_rates() {
|
||||
v1.capabilities[4].parameter = 1'000'001;
|
||||
reject(v1, GenomeError::parameter_out_of_range);
|
||||
auto unknown = founder();
|
||||
unknown.schema_version = 6; // Schema 5 exists since rules 11 (ADR-0175).
|
||||
unknown.schema_version = 7; // Schema 6 exists since rules 12.
|
||||
reject(unknown, GenomeError::unsupported_version);
|
||||
auto bytes = Genome::create(founder())->encode();
|
||||
bytes[8] = 6; // Schema field; decode refuses before the checksum matters.
|
||||
bytes[8] = 7; // Schema field; decode refuses before the checksum matters.
|
||||
CHECK(!Genome::decode(bytes) &&
|
||||
Genome::decode(bytes).error() == GenomeError::unsupported_version);
|
||||
}
|
||||
@@ -397,6 +397,52 @@ void moves_preserve_validity() {
|
||||
static_assert(std::is_copy_constructible_v<Genome>);
|
||||
static_assert(std::is_copy_assignable_v<Genome>);
|
||||
}
|
||||
|
||||
// Schema 6 (rules 12): the movement arrangement is required, encoded after the capability
|
||||
// records, covered by the digest, and refused before schema 6.
|
||||
void schema_v6_movement_arrangement() {
|
||||
auto draft = founder();
|
||||
draft.schema_version = genome_schema_v6;
|
||||
draft.development_version = 6;
|
||||
reject(draft, GenomeError::parameter_out_of_range); // Missing arrangement.
|
||||
draft.movement_arrangement = founder_movement_arrangement;
|
||||
const auto genome = Genome::create(draft);
|
||||
CHECK(genome && genome->movement_arrangement() == founder_movement_arrangement);
|
||||
const auto bytes = genome->encode();
|
||||
const auto decoded = Genome::decode(bytes);
|
||||
CHECK(decoded && *decoded == *genome);
|
||||
CHECK(bytes.size() == 36 + 4 + 3 * 9 + 18 + 16);
|
||||
|
||||
auto changed = draft;
|
||||
changed.movement_arrangement->steering = 105;
|
||||
const auto other = Genome::create(changed);
|
||||
CHECK(other && other->content_digest() != genome->content_digest());
|
||||
|
||||
auto tampered = bytes;
|
||||
tampered[36 + 4 + 3 * 9] ^= 1U; // First arrangement byte; the checksum catches it.
|
||||
CHECK(!Genome::decode(tampered));
|
||||
auto truncated = bytes;
|
||||
truncated.erase(truncated.end() - 18, truncated.end() - 16);
|
||||
CHECK(!Genome::decode(truncated));
|
||||
|
||||
for (auto bad : {MovementArrangement{1'001, 100, 0, 100, 100, 100, 0, 100, 0},
|
||||
MovementArrangement{100, 0, 0, 100, 100, 100, 0, 100, 0},
|
||||
MovementArrangement{100, 100, 0, 100, 100, 100, 0, 0, 0}}) {
|
||||
auto refused = draft;
|
||||
refused.movement_arrangement = bad;
|
||||
reject(refused, GenomeError::parameter_out_of_range);
|
||||
}
|
||||
// Shed output and absent modules are valid.
|
||||
auto shed = draft;
|
||||
shed.movement_arrangement = MovementArrangement{0, 100, 0, 100, 100, 100, 0, 100, 0};
|
||||
CHECK(Genome::create(shed));
|
||||
|
||||
auto early = founder();
|
||||
early.schema_version = genome_schema_v5;
|
||||
early.development_version = 5;
|
||||
early.movement_arrangement = founder_movement_arrangement;
|
||||
reject(early, GenomeError::parameter_out_of_range);
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
founders_and_ancestry();
|
||||
@@ -408,6 +454,7 @@ int main() try {
|
||||
frozen_record_compatibility();
|
||||
schema_v2_rates();
|
||||
moves_preserve_validity();
|
||||
schema_v6_movement_arrangement();
|
||||
std::cout << "PASS genome schema, ancestry, development graph and canonical encoding\n";
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
@@ -385,12 +385,12 @@ void rules_fail_closed() {
|
||||
const auto m3 = metabolic_rules_for(3);
|
||||
CHECK(m2 && m3 && m3->movement_per_kilogram == m2->movement_per_kilogram &&
|
||||
m3->intake_energy_per_kilogram == m2->intake_energy_per_kilogram);
|
||||
for (const auto version : {0U, 6U, 99U}) {
|
||||
for (const auto version : {0U, 7U, 99U}) {
|
||||
const auto missing = metabolic_rules_for(version);
|
||||
CHECK(!missing && missing.error() == DevelopmentError::unsupported_rules);
|
||||
}
|
||||
auto source = draft();
|
||||
source.development_version = 6;
|
||||
source.development_version = 7;
|
||||
const auto future = build(source);
|
||||
const auto refused = metabolic_budget(future, {1000, 0}, temperate);
|
||||
CHECK(!refused && refused.error() == DevelopmentError::unsupported_rules);
|
||||
|
||||
@@ -315,7 +315,7 @@ void invalid_contexts_are_refused() {
|
||||
// An unsupported development version leaves no eligible operator at all,
|
||||
// because every successor fails to derive a budget.
|
||||
auto source = draft();
|
||||
source.development_version = 6;
|
||||
source.development_version = 7;
|
||||
const auto future = build(source);
|
||||
const auto empty = mutation_candidates(future, context(1));
|
||||
CHECK(!empty && empty.error() == MutationError::no_candidates);
|
||||
|
||||
Reference in New Issue
Block a user