Selection established that a context was unchanged by regenerating the candidate list and comparing it. That cannot establish it. Four of nine operators is only 126 distinct lists, so different contexts draw the same one routinely, and an offer from event 1 was accepted under event 239. An offer now records what produced it: the parent's identity and digest, and the context itself. Selection compares those directly, before anything else. Because the context and parent then determine the draw, a list that still differs means the offer itself was altered, which is now reported as its own error rather than as a context having moved. The regression searches for a context whose draw collides with the offer's and asserts that such a collision exists rather than assuming one, then requires selection to reject it. It was confirmed to fail against the previous implementation. One expectation of mine was wrong and is now stated correctly: rewriting an offer's recorded context to name the colliding one is accepted, and should be. Those candidates genuinely are what that context draws, so the result is a legitimate offer for it rather than a forgery. The check is that the recorded context matches the current one, not provenance. Editing a candidate remains caught, as an altered offer. Native Release, clang-tidy analysis, ASan and format checks pass 20/20. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
70 lines
2.9 KiB
C++
70 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "evo/biology/metabolism.hpp"
|
|
|
|
namespace evo::biology {
|
|
enum class MutationEffect : std::uint8_t { adjust_up, adjust_down, acquire, shed };
|
|
// One entry of the static catalog. The ID is stable: it orders candidates and
|
|
// names them across calls, and it carries no ranking.
|
|
struct MutationOperator {
|
|
std::uint16_t id;
|
|
Capability target;
|
|
MutationEffect effect;
|
|
auto operator<=>(const MutationOperator&) const = default;
|
|
};
|
|
// What the recorded context is. The draw reads this and the parent genome and
|
|
// nothing else, so events elsewhere in a world cannot move a candidate set.
|
|
struct MutationContext {
|
|
std::uint64_t seed;
|
|
std::uint32_t stream; // explicit stream identity, never a shared global
|
|
std::uint64_t event_index; // a new event earns a new draw; a retry does not
|
|
std::uint16_t candidate_count;
|
|
GrowthState growth;
|
|
EnvironmentState environment;
|
|
auto operator<=>(const MutationContext&) const = default;
|
|
};
|
|
// A proposal. It reserves nothing. Maintenance and mass are what ADR-0032 would
|
|
// charge for the successor, not a price invented here and not a score.
|
|
struct MutationCandidate {
|
|
std::uint16_t operator_id;
|
|
Capability target;
|
|
MutationEffect effect;
|
|
std::uint32_t parameter; // the successor's value; zero when shed
|
|
std::uint64_t maintenance;
|
|
std::uint64_t total_mass;
|
|
auto operator<=>(const MutationCandidate&) const = default;
|
|
};
|
|
// What was offered, and what it was drawn from. The record carries its own
|
|
// context and parent because a candidate list cannot stand in for them: a small
|
|
// catalog yields few distinct lists, so different contexts draw the same one
|
|
// often, and comparing lists would accept a stale offer.
|
|
struct MutationOffer {
|
|
std::uint64_t parent;
|
|
std::uint64_t parent_digest;
|
|
MutationContext context;
|
|
std::vector<MutationCandidate> candidates;
|
|
auto operator<=>(const MutationOffer&) const = default;
|
|
};
|
|
enum class MutationError : std::uint8_t {
|
|
invalid_context,
|
|
no_candidates,
|
|
unknown_candidate,
|
|
context_changed,
|
|
altered_offer,
|
|
invalid_successor
|
|
};
|
|
inline constexpr std::size_t max_candidates = 8;
|
|
|
|
[[nodiscard]] std::span<const MutationOperator> mutation_catalog() noexcept;
|
|
// Identical inputs always yield identical candidates, sorted by operator ID.
|
|
// The order is canonical and means nothing: nothing here is ranked.
|
|
[[nodiscard]] std::expected<MutationOffer, MutationError>
|
|
mutation_candidates(const Genome& genome, const MutationContext& context);
|
|
// Compares the offer's recorded context and parent against the current ones
|
|
// before anything else, so a changed context is rejected rather than answered
|
|
// with a different mutation.
|
|
[[nodiscard]] std::expected<Genome, MutationError>
|
|
select_mutation(const Genome& genome, const MutationContext& context, const MutationOffer& offered,
|
|
std::uint16_t chosen, std::uint64_t successor_id, std::uint64_t origin_event);
|
|
} // namespace evo::biology
|