Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m30s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m10s
Foundation / image (push) Successful in 4m46s
Phase 3 of the cellular revamp build plan (ADR-0179), first part: the headless pieces the owner will use. - The named catalog: all 49 mutations of Cellular_mutation_plan.md as data (stable ids and tuning keys, name, pro, con, effect, availability, increase and decrease triggers, base weight). Applying one edits a schema-7 plan by fixed reference points (a point is a hundredth of the founder's value), with paired edits, spreads across a channel group, recipe shifts, photosynthesis acquire and shed, and Adhesion; bounds, gates (carbon burned, buds made) and the enabled switch close it. 43 mutations are open at birth, as planned. - Triggers: per-tick activity signals and eight trigger kinds (accumulate, absence, count in a window, event, share over a window, regular recurrence, straight heading, sharp turns) move each mutation's affinity score within bounds; integer state only, so replay reproduces scores. - Offers: weight = base x a score multiplier; chances clamp(k x weight, floor, cap) summing to the options, in parts per million (floor 0.001%, cap 70%), found exactly by water-filling over sorted weights; a systematic draw picks distinct mutations whose inclusion frequencies equal their chances exactly. Tests cover the catalog's identities, the pool at birth, every kind of edit, bounds and gates; every trigger kind; score bounds; weights; a 300-seed chance ensemble; and an exhaustive draw over all million draws. Refreshes the DEV session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.5 KiB
C++
57 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "evo/biology/cellular_catalog.hpp"
|
|
|
|
#include <array>
|
|
#include <compare>
|
|
#include <cstdint>
|
|
|
|
// Behaviour triggers (rules 13, ADR-0179; Cellular_mutation_plan.md section 3): what a cell did
|
|
// each tick raises or lowers its affinity score for each mutation. Integer state only, advanced
|
|
// once per tick by the owner, so replay reproduces every score exactly.
|
|
namespace evo::biology {
|
|
// One tick of a cell's activity: flags are 0 or 1, amounts are pJ or fg (CellularSignal).
|
|
struct CellularActivity {
|
|
std::array<std::uint64_t, cellular_signal_count> signal{};
|
|
std::uint16_t heading{}; // The cell's heading after the tick (65,536 per turn).
|
|
[[nodiscard]] std::uint64_t operator[](CellularSignal s) const noexcept {
|
|
return signal[static_cast<std::size_t>(s)];
|
|
}
|
|
std::uint64_t& operator[](CellularSignal s) noexcept {
|
|
return signal[static_cast<std::size_t>(s)];
|
|
}
|
|
};
|
|
|
|
// One trigger's progress. Its meaning depends on the trigger kind; all fields start at zero.
|
|
struct CellularTriggerState {
|
|
std::uint64_t first{}, second{};
|
|
std::uint32_t ticks{};
|
|
std::uint16_t heading{};
|
|
std::uint8_t running{};
|
|
auto operator<=>(const CellularTriggerState&) const = default;
|
|
};
|
|
|
|
// Advances one trigger by one tick; true when it fires. `threshold` replaces the spec's tick
|
|
// threshold (or window) when non-zero.
|
|
[[nodiscard]] bool cellular_trigger_tick(const CellularTriggerSpec& spec, std::uint32_t threshold,
|
|
CellularTriggerState& state,
|
|
const CellularActivity& activity) noexcept;
|
|
|
|
// Affinity: every mutation's score, and its increase and decrease triggers' progress.
|
|
struct CellularAffinity {
|
|
std::array<std::int16_t, cellular_catalog_size> score{};
|
|
std::array<CellularTriggerState, cellular_catalog_size> increase{}, decrease{};
|
|
auto operator<=>(const CellularAffinity&) const = default;
|
|
};
|
|
// Bounds of every score.
|
|
struct CellularScoreBounds {
|
|
std::int32_t min{-1'000}, max{1'000};
|
|
auto operator<=>(const CellularScoreBounds&) const = default;
|
|
};
|
|
// Advances every mutation's triggers by one tick and applies their points to its score
|
|
// (`tuning` is indexed like the catalog). Disabled mutations do not move.
|
|
void cellular_affinity_tick(CellularAffinity& affinity, const CellularActivity& activity,
|
|
std::span<const CellularMutationTuning> tuning,
|
|
CellularScoreBounds bounds) noexcept;
|
|
} // namespace evo::biology
|