Files
aevolution/include/evo/biology/cellular_offers.hpp
T
dingoandClaude Opus 5.5 732d008aa1
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
feat(biology): rules 13 mutation catalog, behaviour triggers and offer draw
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>
2026-10-22 18:46:21 -04:00

45 lines
2.2 KiB
C++

#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <vector>
// Mutation offers (rules 13, ADR-0179; Cellular_mutation_plan.md section 3): a mutation's
// weight from its affinity score, every eligible mutation's chance of appearing in an offer
// (floored and capped, summing to the number of options), and a systematic draw whose
// inclusion frequencies equal those chances. Chances are parts per million (1,000,000 = 100%).
namespace evo::biology {
inline constexpr std::uint32_t cellular_chance_whole = 1'000'000;
struct CellularOfferRules {
std::uint32_t options{3};
std::uint32_t floor_ppm{10}; // 0.001%.
std::uint32_t cap_ppm{700'000}; // 70%.
std::int32_t score_min{-1'000}, score_max{1'000};
std::uint32_t max_multiplier_per_mille{10'000}; // At score_max: 10x.
std::uint32_t min_multiplier_per_mille{0}; // At score_min: 0x.
auto operator<=>(const CellularOfferRules&) const = default;
};
// base_weight times the score's multiplier: 1 at score 0, rising linearly to the maximum at
// score_max and falling to the minimum at score_min.
[[nodiscard]] std::uint64_t cellular_offer_weight(std::uint32_t base_weight, std::int32_t score,
const CellularOfferRules& rules) noexcept;
// Each weight's chance: clamp(k x weight, floor, cap) with k chosen so the chances sum to
// `options` x 100%, in the weights' order. Nothing when no such allocation exists (too few
// mutations for the cap, too many for the floor, or weights too large).
[[nodiscard]] std::optional<std::vector<std::uint32_t>>
cellular_offer_chances(std::span<const std::uint64_t> weights, const CellularOfferRules& rules);
// Systematic draw over chances summing to `options` x 100%: the indices at
// u, u + 100%, u + 200%, ... along the cumulative chances, `u` in [0, 100%). Distinct by
// construction; each index appears with exactly its chance over uniform `u`.
[[nodiscard]] std::vector<std::size_t>
cellular_systematic_draw(std::span<const std::uint32_t> chances, std::uint32_t options,
std::uint32_t u) noexcept;
} // namespace evo::biology