Something went wrong. Try again.
WIP generalized fluoddity web viewer and evolution app
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Morphology genes — the directly-encoded half of the genotype (docs/evolution_model.md, "Two// loci"). The rule is indirectly encoded (CPPN); these ~8 organism scalars are plain numbers that// evolve by small Gaussian jitter and stay hand-tunable in the editor.//// Pure TS (no Svelte, no WebGL): this is the single source of truth for the organism morphology// parameters — their slider ranges (UI) AND their mutation strengths (operator config). Per the// data-model discipline, the sigmas live HERE, not in the saved record: sigma is how hard the// breeder pushes a gene, not a property of the organism. sigma = 0 freezes a gene.
import type { Rng } from "../genome/rng";
export interface MorphParam { key: string; label: string; min: number; max: number; step?: number; /** Gaussian std-dev per breeding step (in the parameter's own units). 0 = fixed gene. */ sigma: number;}
// Ranges mirror Wild7-tweak3.json's slider_ranges. Sensor angle/distance carry the largest sigmas// — they're the sensitive shape controls the user wants to evolve; the rest drift gently, and// depositGain stays fixed for now (it's an energy knob; jittering it risks dead candidates).export const MORPH_PARAMS = [ { key: "sensorGain", label: "Sensor Gain", min: 0, max: 10, sigma: 0.25 }, { key: "sensorAngle", label: "Sensor Angle", min: -1, max: 1, sigma: 0.08 }, { key: "sensorDistance", label: "Sensor Distance", min: 0, max: 3, sigma: 0.15 }, { key: "forceGain", label: "Force Gain", min: 0, max: 2, sigma: 0.05 }, { key: "strafePower", label: "Strafe Power", min: 0, max: 0.5, sigma: 0.02 }, { key: "axialForce", label: "Axial Force", min: -1, max: 1, sigma: 0.05 }, { key: "lateralForce", label: "Lateral Force", min: -1, max: 1, sigma: 0.05 }, { key: "depositGain", label: "Deposit Gain", min: 0, max: 300, step: 1, sigma: 0 },] as const satisfies readonly MorphParam[];
export type MorphKey = (typeof MORPH_PARAMS)[number]["key"];
/** The organism morphology vector — exactly the keys in MORPH_PARAMS. */export type Morph = Record<MorphKey, number>;
const clamp = (x: number, lo: number, hi: number) => (x < lo ? lo : x > hi ? hi : x);
/** A child morphology: the parent's, with each non-fixed gene jittered and clamped to range. */export function mutateMorph(parent: Morph, rng: Rng): Morph { const out = { ...parent }; for (const p of MORPH_PARAMS) { if (p.sigma > 0) out[p.key] = clamp(parent[p.key] + rng.normal(0, p.sigma), p.min, p.max); } return out;}