diff --git a/CMakeLists.txt b/CMakeLists.txt index 282e45c..6140f66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ add_library(evo_lifecycle STATIC src/server/lifecycle/primitive_lives.cpp src/server/lifecycle/cellular_population_codec.cpp src/server/lifecycle/cellular_population_policy.cpp src/server/lifecycle/cellular_schedule.cpp src/server/lifecycle/cellular_population_batch.cpp src/server/lifecycle/cellular_environment.cpp src/server/lifecycle/cellular_environment_batch.cpp - src/server/lifecycle/cellular_light.cpp) + src/server/lifecycle/cellular_light.cpp src/server/lifecycle/cellular_liquid.cpp) add_library(evo::lifecycle ALIAS evo_lifecycle) target_link_libraries(evo_lifecycle PUBLIC evo::biology evo::world) evo_owned_target(evo_lifecycle) @@ -743,6 +743,12 @@ if(BUILD_TESTING) -P "${CMAKE_CURRENT_SOURCE_DIR}/tests/cellular_population_restart.cmake") set_tests_properties(cellular-retained-plan-population cellular-retained-plan-population-restart PROPERTIES TIMEOUT ${evo_cohort_timeout}) + add_executable(evo-cellular-liquid-owner-tests tests/cellular_liquid_owner_tests.cpp) + target_include_directories(evo-cellular-liquid-owner-tests PRIVATE tests) + target_link_libraries(evo-cellular-liquid-owner-tests PRIVATE evo::lifecycle) + evo_owned_target(evo-cellular-liquid-owner-tests) + add_test(NAME cellular-liquid-owner-contracts COMMAND evo-cellular-liquid-owner-tests) + set_tests_properties(cellular-liquid-owner-contracts PROPERTIES TIMEOUT 300) add_executable(evo-photosynthesis-tests tests/photosynthesis_tests.cpp) target_link_libraries(evo-photosynthesis-tests PRIVATE evo::lifecycle) evo_owned_target(evo-photosynthesis-tests) diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index 8c0fc89..f861d04 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -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-20261021T205045-d2835fc2:1792630245"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261021T212858-ccf85ec3:1792632538"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/include/evo/biology/cellular_step.hpp b/include/evo/biology/cellular_step.hpp index d54d1c2..8cef71d 100644 --- a/include/evo/biology/cellular_step.hpp +++ b/include/evo/biology/cellular_step.hpp @@ -19,6 +19,8 @@ struct CellularStepIntent { // ADR-0128: the owner is offline; the cell does nothing this tick (no maintenance, // movement, intake or heat) but can still be engulfed. Exclusive with every other field. bool frozen{}; + // Rules 12: oppose relative velocity instead of following `movement`. + bool brake{}; auto operator<=>(const CellularStepIntent&) const = default; }; diff --git a/include/evo/biology/cellular_tuning.hpp b/include/evo/biology/cellular_tuning.hpp index e55c839..65cf3f6 100644 --- a/include/evo/biology/cellular_tuning.hpp +++ b/include/evo/biology/cellular_tuning.hpp @@ -80,14 +80,19 @@ parse_cellular_tuning(std::string_view text); accounting::Picojoules thrust_cost, accounting::Picojoules reverse_cost); -enum class CellularHandlingError : std::uint8_t { unsupported_genome, unsupported_rate, overflow }; +enum class CellularHandlingError : std::uint8_t { 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. +// A genome from before schema 6 has no arrangement and handles as the founder does. [[nodiscard]] std::expected derive_cellular_handling(const Genome& genome, const MetabolicBudget& budget, const CellularTuning& tuning); +// The same from the founder's per-tick handling directly; its costs are ignored. +[[nodiscard]] std::expected +derive_cellular_handling(const Genome& genome, const MetabolicBudget& budget, + const CellularHandling& founder); } // namespace evo::biology diff --git a/include/evo/server/lifecycle/cellular_liquid.hpp b/include/evo/server/lifecycle/cellular_liquid.hpp new file mode 100644 index 0000000..7c9159d --- /dev/null +++ b/include/evo/server/lifecycle/cellular_liquid.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "evo/biology/cellular_currents.hpp" +#include "evo/biology/cellular_deposit_motion.hpp" +#include "evo/biology/cellular_tuning.hpp" + +#include +#include +#include + +// Rules 12 (Cellular_Region_Movement_Plan.md, ADR-0177): the liquid region a cellular owner +// declares when it upgrades to owner format 10. Taken from the Git tuning file and a seed when +// the region opens and persisted with the owner, so replay and restore never read the file. +namespace evo::server { +struct CellularLiquidRules { + biology::CellularCurrentConfig currents{}; // Its area is the owner's area. + biology::CellularHandling founder{}; // Per-tick founder handling; costs unused. + biology::CellularDepositMotionRules deposits{}; + auto operator<=>(const CellularLiquidRules&) const = default; +}; + +// Every field is within the kinematic, current and deposit bounds for `area`. +[[nodiscard]] bool cellular_liquid_valid(const CellularLiquidRules& rules, + biology::CellularArea area) noexcept; +// Rules for a region of `area` from the tuning file and a current seed. +[[nodiscard]] CellularLiquidRules cellular_liquid_rules(const biology::CellularTuning& tuning, + biology::CellularArea area, + std::uint64_t seed); +// An organism's handling: its genome's arrangement scaled from the declared founder handling, +// with full-output costs from its metabolic budget. +[[nodiscard]] std::expected +cellular_liquid_handling(const biology::Genome& genome, const biology::MetabolicBudget& budget, + const CellularLiquidRules& rules); +} // namespace evo::server diff --git a/include/evo/server/lifecycle/cellular_lives.hpp b/include/evo/server/lifecycle/cellular_lives.hpp index 1fe3882..900b50e 100644 --- a/include/evo/server/lifecycle/cellular_lives.hpp +++ b/include/evo/server/lifecycle/cellular_lives.hpp @@ -3,6 +3,7 @@ #include "evo/biology/cellular_region_step.hpp" #include "evo/biology/mutation.hpp" #include "evo/server/lifecycle/cellular_light.hpp" +#include "evo/server/lifecycle/cellular_liquid.hpp" #include "evo/server/lifecycle/primitive_lives.hpp" #include @@ -55,19 +56,25 @@ inline constexpr std::uint32_t cellular_lives_inheritance_rules = 10; // Format 9 is format 8 with the region's declared light and cumulative capture. inline constexpr std::uint32_t cellular_lives_light_format = 9; inline constexpr std::uint32_t cellular_lives_photosynthesis_rules = 11; -// Rules that retain offspring plans (formats 8 and 9): 10 and 11. +// Rules 12 (Cellular_Region_Movement_Plan.md, ADR-0177): rules 11 with founder 5 (genome +// schema 6, movement arrangement) in a liquid region. Format 10 is format 9 with the declared +// liquid rules and each life's motion state, on a format-3 habitat whose food moves. +inline constexpr std::uint32_t cellular_lives_liquid_format = 10; +inline constexpr std::uint32_t cellular_lives_liquid_rules = 12; +// Rules that retain offspring plans (formats 8 to 10): 10 to 12. [[nodiscard]] constexpr bool cellular_retained_plans(std::uint32_t rules) noexcept { return rules == cellular_lives_inheritance_rules || - rules == cellular_lives_photosynthesis_rules; + rules == cellular_lives_photosynthesis_rules || rules == cellular_lives_liquid_rules; } inline constexpr std::uint32_t cellular_growth_per_tick = 5; // Per 50 ms; trial rate. // The founder a region of these rules creates. [[nodiscard]] constexpr biology::FounderVersion cellular_founder_version(std::uint32_t rules) noexcept { - return rules >= cellular_lives_photosynthesis_rules ? biology::primitive_founder_v4 - : rules >= cellular_lives_reproduction_rules ? biology::primitive_founder_v3 - : rules >= cellular_lives_balance_rules ? biology::primitive_founder_v2 - : biology::primitive_founder_v1; + return rules >= cellular_lives_liquid_rules ? biology::primitive_founder_v5 + : rules >= cellular_lives_photosynthesis_rules ? biology::primitive_founder_v4 + : rules >= cellular_lives_reproduction_rules ? biology::primitive_founder_v3 + : rules >= cellular_lives_balance_rules ? biology::primitive_founder_v2 + : biology::primitive_founder_v1; } // ADR-0137: a bud action also yields a twin with probability reproduction / 2 per thousand // (founders: 25 %), when the reserve funds it and there is room. Seeded per parent and tick. @@ -119,7 +126,8 @@ struct CellularOwnedLife { // Format 6 (ADR-0128): presence and the tick its freeze began (zero while active). CellularPresence presence{CellularPresence::active}; std::uint64_t frozen_since{}; - std::uint64_t offspring_genome{}; // Format 8; older formats retain zero. + std::uint64_t offspring_genome{}; // Format 8; older formats retain zero. + biology::CellularMotionState motion{}; // Format 10; older formats retain zero. auto operator<=>(const CellularOwnedLife&) const = default; }; struct CellularOwnedCorpse { @@ -300,6 +308,14 @@ class CellularLives { // afterwards can evolve photosynthesis. [[nodiscard]] std::expected, CellularLivesError> photosynthesis_upgrade_candidate(CellularLight light) const; + // Rules 12: explicit no-tick format-9/rules-11 -> format-10/rules-12 upgrade declaring + // the region's liquid rules. The habitat becomes format 3 (every bubble counts one merged + // bubble) and lives start at rest. Founders born afterwards are founder 5. + [[nodiscard]] std::expected, CellularLivesError> + liquid_upgrade_candidate(const CellularLiquidRules& rules) const; + // Format 10: the declared liquid rules and the current field they generate (null before). + [[nodiscard]] const CellularLiquidRules& liquid_rules() const noexcept; + [[nodiscard]] const biology::CellularFlowField* flow_field() const noexcept; // Format 9: declared light and the energy captured from it, cumulatively. [[nodiscard]] const CellularLight& light() const noexcept; [[nodiscard]] accounting::Picojoules captured_light() const noexcept; diff --git a/src/biology/cellular_tuning.cpp b/src/biology/cellular_tuning.cpp index 6957c3c..55b4c05 100644 --- a/src/biology/cellular_tuning.cpp +++ b/src/biology/cellular_tuning.cpp @@ -252,17 +252,20 @@ CellularHandling founder_cellular_handling(const CellularTuning& tuning, std::expected 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}; + return derive_cellular_handling(genome, budget, founder_cellular_handling(tuning, {}, {})); +} + +std::expected +derive_cellular_handling(const Genome& genome, const MetabolicBudget& budget, + const CellularHandling& founder) { + // Genomes from before schema 6 carry no arrangement and handle as founders do. + const auto a = genome.movement_arrangement().value_or(founder_movement_arrangement); 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; diff --git a/src/server/lifecycle/cellular_batch.cpp b/src/server/lifecycle/cellular_batch.cpp index c960eb0..2166c4b 100644 --- a/src/server/lifecycle/cellular_batch.cpp +++ b/src/server/lifecycle/cellular_batch.cpp @@ -57,7 +57,7 @@ bool valid_intent(const CellularLifeIntent& life) { step.movement.y <= movement_limit && !(step.engulf && step.intake_target) && !(step.bud && (step.intake_target || step.engulf)) && !(step.frozen && (step.movement != biology::CellularIntent{} || step.intake_target || - step.engulf || step.bud)); + step.engulf || step.bud || step.brake)); } bool valid_ticks(std::span ticks) { std::set identities; @@ -162,7 +162,10 @@ void put_intent(std::vector& out, const CellularLifeIntent& life) : life.intent.engulf ? 2 : life.intent.bud ? 3 : 0); - out.push_back(life.intent.frozen ? 1 : 0); // Flags (ADR-0128): bit 0 frozen. + // Flags: bit 0 frozen (ADR-0128), bit 1 brake (rules 12). SQL never parses this byte, and + // player action records keep it zero: the trace alone carries a brake. + out.push_back( + static_cast((life.intent.frozen ? 1U : 0U) | (life.intent.brake ? 2U : 0U))); put(out, 0, 2); put(out, life.intent.intake_target ? life.intent.intake_target->x_um : 0, 4); put(out, life.intent.intake_target ? life.intent.intake_target->y_um : 0, 4); @@ -301,7 +304,7 @@ decode_cellular_batch(std::span bytes) { step.lives.reserve(static_cast(count)); for (std::uint64_t i = 0; i < count; ++i) { const auto record = bytes.subspan(offset, cellular_batch_intent_bytes); - if (record[12] > 3 || record[13] > 1 || !all_zero(record.subspan(14, 2))) + if (record[12] > 3 || record[13] > 3 || !all_zero(record.subspan(14, 2))) return std::unexpected{CellularBatchError::format}; CellularLifeIntent life; life.life_id = get(record, 0, 8); @@ -316,9 +319,10 @@ decode_cellular_batch(std::span bytes) { } else if (!all_zero(record.subspan(16, 8))) { return std::unexpected{CellularBatchError::format}; } - life.intent.engulf = record[12] == 2; // ADR-0124 target kind. - life.intent.bud = record[12] == 3; // ADR-0125. - life.intent.frozen = record[13] == 1; // ADR-0128. + life.intent.engulf = record[12] == 2; // ADR-0124 target kind. + life.intent.bud = record[12] == 3; // ADR-0125. + life.intent.frozen = (record[13] & 1U) != 0; // ADR-0128. + life.intent.brake = (record[13] & 2U) != 0; // Rules 12; owners below refuse it. if (!valid_intent(life) || (!step.lives.empty() && step.lives.back().life_id >= life.life_id)) return std::unexpected{CellularBatchError::format}; diff --git a/src/server/lifecycle/cellular_liquid.cpp b/src/server/lifecycle/cellular_liquid.cpp new file mode 100644 index 0000000..4f9d210 --- /dev/null +++ b/src/server/lifecycle/cellular_liquid.cpp @@ -0,0 +1,47 @@ +#include "evo/server/lifecycle/cellular_liquid.hpp" + +namespace evo::server { +bool cellular_liquid_valid(const CellularLiquidRules& rules, biology::CellularArea area) noexcept { + const auto& c = rules.currents; + const auto& f = rules.founder; + const auto& d = rules.deposits; + // Generation itself is checked once, by the owner that keeps the generated field. + return c.width_um == area.width_um && c.height_um == area.height_um && c.pitch_um != 0 && + c.pitch_um <= biology::max_cellular_current_pitch_um && c.min_count <= c.max_count && + f.thrust_q10 <= static_cast(biology::cellular_velocity_limit_q10) && + f.reverse_thrust_q10 <= + static_cast(biology::cellular_velocity_limit_q10) && + f.forward_drag_ppm < biology::cellular_drag_ppm_limit && + f.lateral_drag_ppm < biology::cellular_drag_ppm_limit && + f.turn <= biology::cellular_heading_turn / 2 && f.thrust_cost.value == 0 && + f.reverse_cost.value == 0 && d.merged_cap != 0 && d.bubble_radius_um != 0 && + d.bubble_radius_um <= biology::max_cellular_deposit_radius_um && d.max_drift_q10 >= 0 && + d.max_drift_q10 <= biology::cellular_velocity_limit_q10 && + d.drift_decay_ppm < biology::cellular_drag_ppm_limit; +} + +CellularLiquidRules cellular_liquid_rules(const biology::CellularTuning& t, + biology::CellularArea area, std::uint64_t seed) { + const auto u32 = [](std::int64_t value) { return static_cast(value); }; + return { + .currents = {seed, u32(static_cast(area.width_um)), + u32(static_cast(area.height_um)), u32(t.currents_grid_pitch_um), + u32(t.currents_min_count), u32(t.currents_max_count), + u32(t.currents_min_width_um), u32(t.currents_max_width_um), + u32(t.currents_min_speed_um_per_s), u32(t.currents_max_speed_um_per_s)}, + .founder = biology::founder_cellular_handling(t, {}, {}), + .deposits = {.drift_radius_um = u32(t.food_induced_drift_radius_um), + .max_drift_q10 = + static_cast(t.food_induced_drift_max_um_per_s * + biology::cellular_velocity_q10_per_um_s), + .drift_decay_ppm = u32(t.food_induced_drift_decay_ppm_per_tick), + .merged_cap = static_cast(t.food_merged_bubble_cap_multiple), + .bubble_radius_um = biology::cellular_mote_radius_um}}; +} + +std::expected +cellular_liquid_handling(const biology::Genome& genome, const biology::MetabolicBudget& budget, + const CellularLiquidRules& rules) { + return biology::derive_cellular_handling(genome, budget, rules.founder); +} +} // namespace evo::server diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index 5207e0a..66fb1e2 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -14,15 +14,16 @@ namespace evo::server { namespace { -constexpr std::uint64_t cellular_lives_v1_magic = 0x3130564C43564541ULL; // AEVCLV01 -constexpr std::uint64_t cellular_lives_v2_magic = 0x3230564C43564541ULL; // AEVCLV02 -constexpr std::uint64_t cellular_lives_v3_magic = 0x3330564C43564541ULL; // AEVCLV03 -constexpr std::uint64_t cellular_lives_v4_magic = 0x3430564C43564541ULL; // AEVCLV04 -constexpr std::uint64_t cellular_lives_v5_magic = 0x3530564C43564541ULL; // AEVCLV05 -constexpr std::uint64_t cellular_lives_v6_magic = 0x3630564C43564541ULL; // AEVCLV06 -constexpr std::uint64_t cellular_lives_v7_magic = 0x3730564C43564541ULL; // AEVCLV07 -constexpr std::uint64_t cellular_lives_v8_magic = 0x3830564C43564541ULL; // AEVCLV08 -constexpr std::uint64_t cellular_lives_v9_magic = 0x3930564C43564541ULL; // AEVCLV09 +constexpr std::uint64_t cellular_lives_v1_magic = 0x3130564C43564541ULL; // AEVCLV01 +constexpr std::uint64_t cellular_lives_v2_magic = 0x3230564C43564541ULL; // AEVCLV02 +constexpr std::uint64_t cellular_lives_v3_magic = 0x3330564C43564541ULL; // AEVCLV03 +constexpr std::uint64_t cellular_lives_v4_magic = 0x3430564C43564541ULL; // AEVCLV04 +constexpr std::uint64_t cellular_lives_v5_magic = 0x3530564C43564541ULL; // AEVCLV05 +constexpr std::uint64_t cellular_lives_v6_magic = 0x3630564C43564541ULL; // AEVCLV06 +constexpr std::uint64_t cellular_lives_v7_magic = 0x3730564C43564541ULL; // AEVCLV07 +constexpr std::uint64_t cellular_lives_v8_magic = 0x3830564C43564541ULL; // AEVCLV08 +constexpr std::uint64_t cellular_lives_v9_magic = 0x3930564C43564541ULL; // AEVCLV09 +constexpr std::uint64_t cellular_lives_v10_magic = 0x3031564C43564541ULL; // AEVCLV10 constexpr std::size_t cellular_lives_header_bytes = 212; constexpr std::size_t cellular_site_bytes = 8; constexpr std::size_t cellular_life_v1_bytes = 168; @@ -43,6 +44,20 @@ constexpr std::size_t cellular_lives_v8_header_bytes = cellular_lives_v7_header_ // Format 9 (ADR-0175): light numerator, denominator, entitlement, moving share and // reserved (4 each for the last two), and the cumulative captured energy. constexpr std::size_t cellular_lives_v9_header_bytes = cellular_lives_v8_header_bytes + 40; +// Format 10 (rules 12): the current seed and nine 4-byte current fields (44), five founder +// handling fields (20), five deposit motion fields and reserved (24): 88 bytes. Each life adds +// its motion state (two velocities, heading, reserved, two carries), 20 bytes. +constexpr std::size_t cellular_lives_v10_header_bytes = cellular_lives_v9_header_bytes + 88; +constexpr std::size_t cellular_life_motion_bytes = 20; + +bool valid_motion(const biology::CellularMotionState& m) noexcept { + constexpr std::int64_t carry = biology::cellular_velocity_q10_per_um_s * 1'000'000; + return m.velocity_x_q10 >= -biology::cellular_velocity_limit_q10 && + m.velocity_x_q10 <= biology::cellular_velocity_limit_q10 && + m.velocity_y_q10 >= -biology::cellular_velocity_limit_q10 && + m.velocity_y_q10 <= biology::cellular_velocity_limit_q10 && m.remainder_x >= 0 && + m.remainder_x < carry && m.remainder_y >= 0 && m.remainder_y < carry; +} constexpr std::size_t cellular_offspring_revision_bytes = 32; std::uint64_t checksum(std::span bytes) noexcept { @@ -591,6 +606,8 @@ struct CellularLives::State { std::vector offspring_revisions; CellularLight light{}; // Format 9 (ADR-0175). accounting::Picojoules captured{}; // Format 9: light credited to reserves so far. + CellularLiquidRules liquid{}; // Format 10 (rules 12). + std::shared_ptr field; // Generated from `liquid`. State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id, CellularLivesConfig cfg, NurseryConfig nursery_definition, @@ -912,6 +929,45 @@ CellularLives::photosynthesis_upgrade_candidate(CellularLight light) const { (*candidate)->state_->light = light; return candidate; } +std::expected, CellularLivesError> +CellularLives::liquid_upgrade_candidate(const CellularLiquidRules& rules) const { + if (state_->format_version != cellular_lives_light_format || + state_->rules_version != cellular_lives_photosynthesis_rules) + return std::unexpected{CellularLivesError::version}; + if (!cellular_liquid_valid(rules, state_->config.area)) + return std::unexpected{CellularLivesError::invalid_config}; + auto field = biology::CellularFlowField::generate(rules.currents); + if (!field) + return std::unexpected{CellularLivesError::invalid_config}; + auto config = state_->habitat->config(); + if (config.format != biology::cellular_habitat_deposit_format || + config.patches.size() > biology::max_cellular_liquid_deposits) + return std::unexpected{CellularLivesError::habitat}; + config.format = biology::cellular_habitat_liquid_format; + for (auto& patch : config.patches) + patch.merged = 1; + auto habitat = biology::CellularHabitat::create(std::move(config)); + if (!habitat) + return std::unexpected{CellularLivesError::habitat}; + auto candidate = restore(snapshot(), world(), region(), frame(), tick()); + if (!candidate) + return std::unexpected(candidate.error()); + auto& next = *(*candidate)->state_; + next.habitat = std::move(*habitat); + next.format_version = cellular_lives_liquid_format; + next.rules_version = cellular_lives_liquid_rules; + next.liquid = rules; + next.field = std::make_shared(std::move(*field)); + for (auto& life : next.lives) + life.motion = {}; + return candidate; +} +const CellularLiquidRules& CellularLives::liquid_rules() const noexcept { + return state_->liquid; +} +const biology::CellularFlowField* CellularLives::flow_field() const noexcept { + return state_->field.get(); +} const CellularLight& CellularLives::light() const noexcept { return state_->light; } @@ -952,8 +1008,10 @@ std::vector CellularLives::snapshot() const { const bool parents = state_->format_version >= cellular_lives_bud_format; const bool presence = state_->format_version >= cellular_lives_presence_format; const bool inheritance = state_->format_version >= cellular_lives_inheritance_format; - const bool lit = state_->format_version == cellular_lives_light_format; - const auto life_bytes = inheritance ? cellular_life_v6_bytes + 8 + const bool lit = state_->format_version >= cellular_lives_light_format; + const bool liquid = state_->format_version == cellular_lives_liquid_format; + const auto life_bytes = liquid ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + : inheritance ? cellular_life_v6_bytes + 8 : state_->format_version == cellular_lives_legacy_format ? cellular_life_v1_bytes : presence ? cellular_life_v6_bytes @@ -965,7 +1023,8 @@ std::vector CellularLives::snapshot() const { : causes ? cellular_corpse_v4_bytes : cellular_corpse_bytes; const bool migration = state_->format_version >= cellular_lives_migration_format; - const auto header_bytes = lit ? cellular_lives_v9_header_bytes + const auto header_bytes = liquid ? cellular_lives_v10_header_bytes + : lit ? cellular_lives_v9_header_bytes : inheritance ? cellular_lives_v8_header_bytes : migration ? cellular_lives_v7_header_bytes : parents ? cellular_lives_v5_header_bytes @@ -994,6 +1053,7 @@ std::vector CellularLives::snapshot() const { : state_->format_version == cellular_lives_engulf_format ? cellular_lives_v4_magic : state_->format_version == cellular_lives_bud_format ? cellular_lives_v5_magic : state_->format_version == cellular_lives_presence_format ? cellular_lives_v6_magic + : liquid ? cellular_lives_v10_magic : lit ? cellular_lives_v9_magic : inheritance ? cellular_lives_v8_magic : migration ? cellular_lives_v7_magic @@ -1038,6 +1098,25 @@ std::vector CellularLives::snapshot() const { out.put(0, 4); out.put(state_->captured.value); } + if (liquid) { + const auto& c = state_->liquid.currents; + const auto& f = state_->liquid.founder; + const auto& d = state_->liquid.deposits; + out.put(c.seed); + for (const auto value : + {c.width_um, c.height_um, c.pitch_um, c.min_count, c.max_count, c.min_route_width_um, + c.max_route_width_um, c.min_speed_um_per_s, c.max_speed_um_per_s}) + out.put(value, 4); + for (const auto value : {f.thrust_q10, f.reverse_thrust_q10, f.forward_drag_ppm, + f.lateral_drag_ppm, static_cast(f.turn)}) + out.put(value, 4); + out.put(d.drift_radius_um, 4); + out.put(static_cast(d.max_drift_q10), 4); + out.put(d.drift_decay_ppm, 4); + out.put(d.merged_cap, 4); + out.put(d.bubble_radius_um, 4); + out.put(0, 4); + } for (const auto site : state_->nursery_config.sites) out.site(site); for (const auto& life : state_->lives) { @@ -1098,6 +1177,14 @@ std::vector CellularLives::snapshot() const { } if (inheritance) out.put(life.offspring_genome); + if (liquid) { + out.put(static_cast(life.motion.velocity_x_q10), 4); + out.put(static_cast(life.motion.velocity_y_q10), 4); + out.put(life.motion.heading, 2); + out.put(0, 2); + out.put(static_cast(life.motion.remainder_x), 4); + out.put(static_cast(life.motion.remainder_y), 4); + } } for (const auto& corpse : state_->corpses) { out.put(corpse.life_id); @@ -1336,6 +1423,8 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c candidate->state_->offspring_revisions = state_->offspring_revisions; candidate->state_->light = state_->light; candidate->state_->captured = state_->captured; + candidate->state_->liquid = state_->liquid; + candidate->state_->field = state_->field; return candidate; } @@ -1359,9 +1448,14 @@ CellularLives::restore(std::span bytes, std::uint64_t world, rules_version == cellular_lives_rules; // Format 6 carries rules 5, 6 (founder 2) or 7 (founder 3, ADR-0137); no new state. // Format 9 is exactly rules 11; format 8 exactly rules 10. - const bool light_version = magic == cellular_lives_v9_magic && - format_version == cellular_lives_light_format && - rules_version == cellular_lives_photosynthesis_rules; + // Format 10 is exactly rules 12. + const bool liquid_version = magic == cellular_lives_v10_magic && + format_version == cellular_lives_liquid_format && + rules_version == cellular_lives_liquid_rules; + const bool light_version = + liquid_version || + (magic == cellular_lives_v9_magic && format_version == cellular_lives_light_format && + rules_version == cellular_lives_photosynthesis_rules); const bool inheritance_version = light_version || (magic == cellular_lives_v8_magic && format_version == cellular_lives_inheritance_format && @@ -1399,6 +1493,8 @@ CellularLives::restore(std::span bytes, std::uint64_t world, return std::unexpected(CellularLivesError::format); if (light_version && bytes.size() < cellular_lives_v9_header_bytes + 8) return std::unexpected(CellularLivesError::format); + if (liquid_version && bytes.size() < cellular_lives_v10_header_bytes + 8) + return std::unexpected(CellularLivesError::format); const auto saved_world = in.get(); const auto saved_region = in.get(); const auto saved_frame = in.get(); @@ -1457,16 +1553,55 @@ CellularLives::restore(std::span bytes, std::uint64_t world, captured.value > light.entitlement.value) return std::unexpected{CellularLivesError::format}; } - const auto life_bytes = inheritance_version ? cellular_life_v6_bytes + 8 - : legacy ? cellular_life_v1_bytes - : presence_version ? cellular_life_v6_bytes - : bud_version ? cellular_life_v5_bytes - : cellular_life_v2_bytes; + CellularLiquidRules liquid{}; + std::shared_ptr field; + if (liquid_version) { + auto& c = liquid.currents; + auto& f = liquid.founder; + auto& d = liquid.deposits; + const auto u32 = [&in] { return static_cast(in.get(4)); }; + c.seed = in.get(); + c.width_um = u32(); + c.height_um = u32(); + c.pitch_um = u32(); + c.min_count = u32(); + c.max_count = u32(); + c.min_route_width_um = u32(); + c.max_route_width_um = u32(); + c.min_speed_um_per_s = u32(); + c.max_speed_um_per_s = u32(); + f.thrust_q10 = u32(); + f.reverse_thrust_q10 = u32(); + f.forward_drag_ppm = u32(); + f.lateral_drag_ppm = u32(); + const auto turn = u32(); + f.turn = static_cast(turn); + d.drift_radius_um = u32(); + d.max_drift_q10 = static_cast(u32()); + d.drift_decay_ppm = u32(); + const auto cap = u32(); + d.merged_cap = static_cast(cap); + d.bubble_radius_um = u32(); + if (in.get(4) != 0 || turn > 0xFFFFU || cap > 0xFFFFU || + !cellular_liquid_valid(liquid, config.area)) + return std::unexpected{CellularLivesError::format}; + auto generated = biology::CellularFlowField::generate(liquid.currents); + if (!generated) + return std::unexpected{CellularLivesError::format}; + field = std::make_shared(std::move(*generated)); + } + const auto life_bytes = liquid_version ? cellular_life_v6_bytes + 8 + cellular_life_motion_bytes + : inheritance_version ? cellular_life_v6_bytes + 8 + : legacy ? cellular_life_v1_bytes + : presence_version ? cellular_life_v6_bytes + : bud_version ? cellular_life_v5_bytes + : cellular_life_v2_bytes; const auto corpse_bytes = inheritance_version ? cellular_corpse_v5_bytes + 8 : bud_version ? cellular_corpse_v5_bytes : engulf_version ? cellular_corpse_v4_bytes : cellular_corpse_bytes; - const auto expected_size = (light_version ? cellular_lives_v9_header_bytes + const auto expected_size = (liquid_version ? cellular_lives_v10_header_bytes + : light_version ? cellular_lives_v9_header_bytes : inheritance_version ? cellular_lives_v8_header_bytes : migration_version ? cellular_lives_v7_header_bytes : bud_version ? cellular_lives_v5_header_bytes @@ -1559,6 +1694,18 @@ CellularLives::restore(std::span bytes, std::uint64_t world, } if (inheritance_version) life.offspring_genome = in.get(); + if (liquid_version) { + life.motion.velocity_x_q10 = + static_cast(static_cast(in.get(4))); + life.motion.velocity_y_q10 = + static_cast(static_cast(in.get(4))); + life.motion.heading = static_cast(in.get(2)); + const auto padding = in.get(2); + life.motion.remainder_x = static_cast(in.get(4)); + life.motion.remainder_y = static_cast(in.get(4)); + if (padding != 0 || !valid_motion(life.motion)) + return std::unexpected{CellularLivesError::noncanonical}; + } lives.push_back(life); } @@ -1607,9 +1754,12 @@ CellularLives::restore(std::span bytes, std::uint64_t world, return std::unexpected{CellularLivesError::checksum}; return std::unexpected{CellularLivesError::habitat}; } - // Rules 8 run on a deposit habitat, and nothing else does (ADR-0136). - if ((rules_version >= cellular_lives_foraging_rules) != - ((*habitat)->config().format == biology::cellular_habitat_deposit_format)) + // Rules 8 to 11 run on a deposit habitat, rules 12 on a liquid one (ADR-0136, rules 12). + const auto habitat_format = (*habitat)->config().format; + if ((rules_version >= cellular_lives_liquid_rules) + ? habitat_format != biology::cellular_habitat_liquid_format + : (rules_version >= cellular_lives_foraging_rules) != + (habitat_format == biology::cellular_habitat_deposit_format)) return std::unexpected{CellularLivesError::habitat}; auto archive = biology::LineageArchive::decode(archive_payload); if (!archive) { @@ -1672,6 +1822,8 @@ CellularLives::restore(std::span bytes, std::uint64_t world, restored->state_->offspring_revisions = std::move(plan_history); restored->state_->light = light; restored->state_->captured = captured; + restored->state_->liquid = liquid; + restored->state_->field = std::move(field); if (!std::ranges::equal(bytes, restored->snapshot())) return std::unexpected{CellularLivesError::noncanonical}; return restored; @@ -1708,6 +1860,9 @@ CellularLives::advance_tick_with_mutations(std::span i const bool bud_rules = state_->rules_version >= cellular_lives_bud_rules; const bool presence_rules = state_->rules_version >= cellular_lives_presence_rules; const bool inheritance_rules = cellular_retained_plans(state_->rules_version); + const bool liquid_rules = state_->rules_version >= cellular_lives_liquid_rules; + if (liquid_rules && !state_->field) + return std::unexpected{CellularLivesError::invalid_config}; for (std::size_t i = 0; i < ordered.size(); ++i) { const auto& intent = ordered[i].intent; // Below rules 4 a bud is ignored, as engulfment is below rules 3 (ADR-0124/0125). @@ -1717,7 +1872,9 @@ CellularLives::advance_tick_with_mutations(std::span i // carries nothing else. if (intent.frozen && (!presence_rules || state_->lives[i].account == LifeAccount{} || intent.movement != biology::CellularIntent{} || - intent.intake_target || intent.engulf || intent.bud)) + intent.intake_target || intent.engulf || intent.bud || intent.brake)) + return std::unexpected{CellularLivesError::invalid_intents}; + if (intent.brake && !liquid_rules) return std::unexpected{CellularLivesError::invalid_intents}; } for (std::size_t i = 0; i < selections.size(); ++i) { @@ -1776,6 +1933,15 @@ CellularLives::advance_tick_with_mutations(std::span i *budget, *membrane, life.source}); + if (liquid_rules) { + const auto handling = cellular_liquid_handling(*genome, *budget, state_->liquid); + if (!handling) + return std::unexpected{CellularLivesError::biology}; + inputs.back().liquid = biology::CellularLiquidInput{ + life.motion, *handling, + state_->field->at_footprint(life.position, budget->phenotype.extent), + ordered[i].intent.brake}; + } } auto proposal = biology::propose_cellular_region_step(state_->config.tick, state_->config.area, inputs, @@ -1796,6 +1962,8 @@ CellularLives::advance_tick_with_mutations(std::span i return std::unexpected{CellularLivesError::invalid_life}; found->position = result.candidate.position; found->reserve = result.candidate.reserve_after; + if (liquid_rules) + found->motion = result.candidate.motion; if (!add_inventory(next_heat, result.candidate.heat_after)) return std::unexpected{CellularLivesError::overflow}; // Only owned lives earn mutation offers; wildlife never mutates in M11 (ADR-0098). @@ -2157,7 +2325,8 @@ CellularLives::advance_tick_with_mutations(std::span i // Rules 3 detritus at empty cells becomes new patches; create() revalidates the map. // Format 2 (ADR-0136): new bubbles take the next deposit ids, and a deposit emptied this // tick is gone. - const bool deposits = habitat_config.format == biology::cellular_habitat_deposit_format; + const bool deposits = habitat_config.format == biology::cellular_habitat_deposit_format || + habitat_config.format == biology::cellular_habitat_liquid_format; for (auto made : proposal->new_patches) { const auto at = std::ranges::lower_bound(habitat_config.patches, made.address, {}, [](const auto& patch) { return patch.address; }); @@ -2174,6 +2343,29 @@ CellularLives::advance_tick_with_mutations(std::span i std::erase_if(habitat_config.patches, [](const biology::CellularPatch& patch) { return patch.stock == accounting::Inventory{}; }); + // Rules 12: after every life fed where the food was, bubbles move with the current and + // the drift that this tick's moving cells induce, then touching bubbles merge. + if (liquid_rules) { + std::vector wakes; + wakes.reserve(proposal->lives.size()); + for (const auto& result : proposal->lives) { + const auto input = std::ranges::lower_bound( + inputs, result.life_id, {}, + [](const biology::CellularLifeStepInput& value) { return value.life_id; }); + if (input == inputs.end() || input->life_id != result.life_id || input->intent.frozen) + continue; + const auto flow = + state_->field->at_footprint(result.candidate.position, input->extent_um); + wakes.push_back({result.candidate.position, input->extent_um, + result.candidate.motion.velocity_x_q10 + flow.x_q10, + result.candidate.motion.velocity_y_q10 + flow.y_q10}); + } + auto moved = biology::advect_cellular_deposits(habitat_config, *state_->field, wakes, + state_->liquid.deposits); + if (!moved) + return std::unexpected{CellularLivesError::habitat}; + habitat_config = std::move(moved->config); + } auto next_habitat = biology::CellularHabitat::create(std::move(habitat_config)); if (!next_habitat) return std::unexpected{CellularLivesError::habitat}; @@ -2200,6 +2392,8 @@ CellularLives::advance_tick_with_mutations(std::span i next->offspring_revisions = std::move(next_offspring_revisions); next->light = state_->light; next->captured = state_->captured; + next->liquid = state_->liquid; + next->field = state_->field; // ADR-0175: light, from this tick's own intentions, credited to every active, // unfrozen photosynthetic survivor's reserve and to the boundary inflow together. std::vector> lit_lives; diff --git a/tests/cellular_liquid_owner_tests.cpp b/tests/cellular_liquid_owner_tests.cpp new file mode 100644 index 0000000..7c65347 --- /dev/null +++ b/tests/cellular_liquid_owner_tests.cpp @@ -0,0 +1,189 @@ +#include "evo/server/lifecycle/cellular_batch.hpp" +#include "fixtures/cellular_ecology.hpp" + +#include +#include +#include + +// Rules 12 owner (Cellular_Region_Movement_Plan.md phase 2): the format 9 -> 10 upgrade, liquid +// motion inside the owner's tick, moving food and exact restore. +namespace { +using namespace evo; +using namespace evo::server; +using namespace evo::fixture; + +constexpr biology::CellularArea area{48'000, 48'000}; + +CellularLiquidRules rules(std::uint64_t seed = 5) { + return {.currents = {seed, area.width_um, area.height_um, 250, 2, 4, 3'000, 6'000, 60, 300}, + .founder = {.thrust_q10 = 20'480, + .reverse_thrust_q10 = 20'480, + .forward_drag_ppm = 95'163, + .lateral_drag_ppm = 95'163, + .turn = 3'276}, + .deposits = {.drift_radius_um = 200, + .max_drift_q10 = 100 * 1'024, + .drift_decay_ppm = 95'163, + .merged_cap = 8, + .bubble_radius_um = biology::cellular_mote_radius_um}}; +} + +// A rules-12 region whose founder is born after the upgrade (founder 5, schema 6). +Owner liquid_region() { + auto state = opening(7, true, 1, false); + checked(state->advance_tick({}), "genesis tick"); + state = checked(state->migration_upgrade_candidate(), "boundary upgrade"); + state = checked(state->maturation_upgrade_candidate(), "maturation upgrade"); + state = checked(state->inheritance_upgrade_candidate(), "inheritance upgrade"); + state = checked(state->photosynthesis_upgrade_candidate({0, 1, {0}}), "light upgrade"); + require(!state->liquid_upgrade_candidate(CellularLiquidRules{}), "empty rules accepted"); + auto wrong = rules(); + wrong.currents.width_um = 30'000; + require(!state->liquid_upgrade_candidate(wrong), "rules for another area accepted"); + state = checked(state->liquid_upgrade_candidate(rules()), "liquid upgrade"); + require(state->format_version() == cellular_lives_liquid_format && + state->rules_version() == cellular_lives_liquid_rules && + state->liquid_rules() == rules() && state->flow_field() != nullptr && + state->habitat().config().format == biology::cellular_habitat_liquid_format && + !state->liquid_upgrade_candidate(rules()), + "liquid upgrade repeated, wrong versions or lost rules"); + for (const auto& patch : state->habitat().patches()) + require(patch.merged == 1, "upgraded deposit without a merged count"); + LifeAccount account{}; + account.back() = 1; + state = checked(state->birth_candidate({account, 1}, {100, 100, 100, 100, {state->tick()}}), + "founder 5 birth"); + const auto genome = state->archive().find(100); + require(genome && genome->schema_version() == biology::genome_schema_v6 && + genome->movement_arrangement() == biology::founder_movement_arrangement, + "founder 5 is not schema 6 with the founder arrangement"); + return state; +} + +std::vector swim(const CellularLives& state, biology::CellularIntent movement, + bool brake = false) { + std::vector result; + for (const auto& life : state.lives()) { + CellularLifeIntent input{life.identity.life, {}}; + input.intent.movement = movement; + input.intent.brake = brake; + result.push_back(input); + } + return result; +} + +void closed(const CellularLives& state) { + const auto& ledger = state.boundary_ledger(); + auto expected = state.opening_total(); + expected.energy.value += ledger.incoming.energy.value - ledger.outgoing.energy.value; + for (std::size_t channel = 0; channel < expected.matter.size(); ++channel) + expected.matter[channel].value += + ledger.incoming.matter[channel].value - ledger.outgoing.matter[channel].value; + require(state.current_total() == expected, "liquid region broke closure"); +} + +void upgrade_and_restore() { + auto state = liquid_region(); + const auto copy = restore(*state); + require(copy->snapshot() == state->snapshot() && copy->liquid_rules() == rules() && + copy->flow_field()->digest() == state->flow_field()->digest(), + "format 10 did not restore exactly"); +} + +void swimming_moves_and_pays() { + auto state = liquid_region(); + const auto start = state->lives().front(); + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {1'000, 0})), "swim tick"); + const auto& life = state->lives().front(); + require(life.motion.velocity_x_q10 > 150 * 1'024, "the founder did not reach swimming speed"); + require(life.position.x_um > start.position.x_um + 100, "the founder did not move east"); + closed(*state); + // Braking brings the relative velocity to rest. + for (int tick = 0; tick < 40; ++tick) + checked(state->advance_tick(swim(*state, {}, true)), "brake tick"); + require(state->lives().front().motion.velocity_x_q10 == 0 && + state->lives().front().motion.velocity_y_q10 == 0, + "braking did not stop the founder relative to the liquid"); + closed(*state); +} + +void food_moves_and_merges_without_loss() { + auto state = liquid_region(); + const auto before = state->habitat().config().patches; + for (int tick = 0; tick < 400; ++tick) + checked(state->advance_tick(swim(*state, {})), "drift tick"); + const auto after = state->habitat().config().patches; + const auto moved = std::ranges::count_if(after, [&before](const biology::CellularPatch& p) { + const auto old = std::ranges::find(before, p.id, &biology::CellularPatch::id); + return old != before.end() && old->address != p.address; + }); + require(moved > 0, "no bubble moved with the current"); + for (const auto& patch : after) + if (patch.kind == biology::CellularDepositKind::pool) + require(std::ranges::any_of(before, + [&patch](const biology::CellularPatch& old) { + return old.id == patch.id && + old.address == patch.address; + }), + "a pool moved"); + closed(*state); +} + +void restore_continues_exactly() { + auto continuous = liquid_region(); + for (int tick = 0; tick < 30; ++tick) + checked(continuous->advance_tick(swim(*continuous, {600, 800})), "continuous tick"); + auto resumed = restore(*continuous); + for (int tick = 0; tick < 30; ++tick) { + checked(continuous->advance_tick(swim(*continuous, {-700, 300})), "continuous tick"); + checked(resumed->advance_tick(swim(*resumed, {-700, 300})), "resumed tick"); + } + require(continuous->snapshot() == resumed->snapshot(), "restore diverged from a live run"); +} + +// A trace of swimming and braking replays to the exact live result (brake is flag bit 1). +void trace_replays_brakes() { + auto live = liquid_region(); + const auto base = restore(*live); + CellularBatch batch; + batch.format_version = cellular_batch_inheritance_format; + batch.header = {live->world(), live->region(), live->frame(), {}, {}, live->tick(), 0}; + batch.header.predecessor.fill(1); // Any bound commit; this test replays portably. + batch.header.predecessor_digest.fill(2); + for (int tick = 0; tick < 24; ++tick) { + const auto intents = + swim(*live, {static_cast(tick < 12 ? 1'000 : 0), 0}, tick >= 12); + checked(live->advance_tick(intents), "recorded tick"); + batch.ticks.push_back({intents, {}, {}}); + } + batch.header.end_tick = live->tick(); + const auto bytes = checked(encode_cellular_batch(batch), "brake trace encodes"); + const auto decoded = checked(decode_cellular_batch(bytes), "brake trace decodes"); + require(decoded == batch && decoded.ticks.back().lives.front().intent.brake, + "the brake did not survive the trace"); + const auto replayed = checked(replay_cellular_batch(*base, decoded), "brake trace replays"); + require(replayed->snapshot() == live->snapshot(), "replay diverged from the live run"); +} + +void older_rules_refuse_brake() { + auto state = opening(7, true, 1); + require(!state->advance_tick(swim(*state, {}, true)), "rules 8 accepted a brake"); +} +} // namespace + +int main() { + try { + upgrade_and_restore(); + swimming_moves_and_pays(); + food_moves_and_merges_without_loss(); + restore_continues_exactly(); + trace_replays_brakes(); + older_rules_refuse_brake(); + } catch (const std::exception& error) { + std::fprintf(stderr, "%s\n", error.what()); + return 1; + } + std::puts("cellular liquid owner contracts passed"); + return 0; +} diff --git a/tests/cellular_lives_tests.cpp b/tests/cellular_lives_tests.cpp index 1fe62ab..c929a9b 100644 --- a/tests/cellular_lives_tests.cpp +++ b/tests/cellular_lives_tests.cpp @@ -872,9 +872,18 @@ void rules_five_owner_freezes_lingers_suspends_and_resumes() { const auto frozen_bytes = encode_cellular_batch(frozen_batch); CHECK(frozen_bytes); CHECK(decode_cellular_batch(*frozen_bytes) == frozen_batch); - auto flag_two = *frozen_bytes; - flag_two[cellular_batch_header_bytes + cellular_batch_tick_header_bytes + 13] = 2; - CHECK(!decode_cellular_batch(flag_two)); + // Bit 1 is the rules-12 brake: frozen and braking together, or unknown bits, are refused. + const auto flags_at = cellular_batch_header_bytes + cellular_batch_tick_header_bytes + 13; + auto brake = *frozen_bytes; + brake[flags_at] = 2; + const auto braking = decode_cellular_batch(brake); + CHECK(braking && braking->ticks[0].lives[0].intent.brake && + !braking->ticks[0].lives[0].intent.frozen); + for (const std::uint8_t refused : {std::uint8_t{3}, std::uint8_t{4}}) { + auto bad = *frozen_bytes; + bad[flags_at] = refused; + CHECK(!decode_cellular_batch(bad)); + } // A frozen intent carries nothing else. auto moving = frozen; moving.movement = {100, 0}; diff --git a/tests/cellular_tuning_tests.cpp b/tests/cellular_tuning_tests.cpp index 271d2e2..9762e8c 100644 --- a/tests/cellular_tuning_tests.cpp +++ b/tests/cellular_tuning_tests.cpp @@ -199,7 +199,11 @@ void derived_handling() { 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())); + // Genomes from before schema 6 handle as founders. + CHECK(old_budget); + const auto old_handling = derive_cellular_handling(*old, *old_budget, v0()); + CHECK(old_handling && old_handling->thrust_q10 == base.thrust_q10 && + old_handling->forward_drag_ppm == base.forward_drag_ppm); } // The checked-in DEV tuning file must parse; CTest passes its path when it is present.