#pragma once #include #include #include #include #include #include // 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> cellular_offer_chances(std::span 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 cellular_systematic_draw(std::span chances, std::uint32_t options, std::uint32_t u) noexcept; } // namespace evo::biology