code wiki / _hdl_build / nx_breeding.nx
nx_breeding.nx
buildroot/runtime/_hdl_build/nx_breeding.nx
about
nx_breeding.nx -- certified composable game part: GENETICS / BREEDING (RENAMED from nx_genome.nx 2026-07-26:
the basename collided with runtime/nx_genome.nx, an unrelated CREATURE body-plan genome. Two different
capabilities, one filename -- whichever a build resolved depended on the include path. Both names were
right in their own domain, so the collision was the defect, not either name.) (gamebench capability 30, the
Breeders-of-the-Nephelym keystone; program plan Lane B1, board row F1066).
A GENOME is a bounded integer trait vector. BREEDING is seeded, deterministic, per-trait
inheritance (pick a parent, apply a bounded mutation, clamp to the trait's legal range).
This is the axis where a GENERATIVE emitter beats a hand-authored roster BY CONSTRUCTION:
a roster is finite; a genome space this size is not (vsbench carries that as HYPOTHESIS until a
head-to-head cell measures it -- this part is what makes the hypothesis testable).
THE CONTRACT (each clause is a gate tooth):
- DETERMINISTIC: same (parents, seed) -> bit-identical child. Replay/lockstep-safe.
- BOUNDED HERITABILITY: every continuous trait of a child lies within the parents' span
widened by at most the trait's mutation step. Inheritance, not reroll.
- UNIQUE OFFSPRING: different seeds -> distinct children (the loottable 0-dup law applied to
creatures -- every bred creature is genuinely YOURS, the ownership pillar).
- ADULT INVARIANT FAIL-CLOSED: breeding involving a parent below the adult age REFUSES
(GN_E_MINOR) with the output untouched, and every emitted child carries age = GN_ADULT_AGE
by construction (the nx_card_compile / nx_wardrobe_state law, inherited into the bloodline).
- MORPH = the CoC transformation mechanism: a bounded delta to ONE trait, every other word
bit-identical -- transformation is a genome edit re-emitted, not a second asset set.
- Serializable span rides nx_gamesave like every certified part.
LIB, no main (ecosystem convention). license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_genome_gate.nx
structs
| none |
consts
| 29 | const GN_T_SPECIES: i64 = 0 // 0..7 humanoid morph archetypes (matches WS_NMORPH) |
| 30 | const GN_T_SEX: i64 = 1 // 0/1 |
| 31 | const GN_T_BUILD: i64 = 2 // 0..1000 body-proc knob space |
| 32 | const GN_T_MUSC: i64 = 3 |
| 33 | const GN_T_FAT: i64 = 4 |
| 34 | const GN_T_STYLIZE: i64 = 5 |
| 35 | const GN_T_HUE: i64 = 6 |
| 36 | const GN_T_VIGOR: i64 = 7 // 0..31 IVs (companion lineage) |
| 37 | const GN_T_INSTINCT: i64 = 8 |
| 38 | const GN_T_TEMPER: i64 = 9 |
| 39 | const GN_T_FERT: i64 = 10 |
| 40 | const GN_T_RARITY: i64 = 11 |
| 41 | const GN_NT: i64 = 12 |
| 43 | const GN_F_AGE: i64 = 0 |
| 44 | const GN_O_TRAIT: i64 = 1 // [1..13) |
| 45 | const GN_F_LINE: i64 = 13 // lineage hash |
| 46 | const GN_LEN: i64 = 16 |
| 47 | const GN_ADULT_AGE: i64 = 18 |
| 48 | const GN_SCHEMA: i64 = 1066 // F1066 lineage |
| 50 | const GN_E_MINOR: i64 = 0-1 |
| 51 | const GN_E_TRAIT: i64 = 0-2 |
| 52 | const GN_E_RANGE: i64 = 0-3 |
| 53 | const GN_CK_SEED: i64 = 2166136261 |
| 54 | const GN_CK_PRIME: i64 = 16777619 |
| 55 | const GN_CK_MASK: i64 = 4611686018427387903 |
| 56 | const GN_SPECIES_JUMP: i64 = 37 // 1-in-37 breedings shift species one step (rare, bounded) |
functions
| 58 | func gn_mix(c0: i64, v: i64) -> i64 |
| 64 | func gn_hash3(a: i64, b: i64, c: i64) -> i64 |
| 73 | func gn_lo(t: i64) -> i64 { return 0 } |
| 74 | func gn_hi(t: i64) -> i64 |
| 80 | func gn_mut(t: i64) -> i64 |
| 88 | func gn_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v<lo { return lo } if v>hi { return hi } return v } |
| 90 | func gn_get(g: *i64, t: i64) -> i64 { return g[GN_O_TRAIT + t] } |
| 91 | func gn_ck(g: *i64) -> i64 |
| 99 | func gn_wild(g: *i64, seed: i64, age: i64) -> i64 |
| 114 | func gn_breed(a: *i64, b: *i64, seed: i64, out: *i64) -> i64 |
| 142 | func gn_morph(g: *i64, t: i64, delta: i64) -> i64 |
| 151 | func gn_dist(a: *i64, b: *i64) -> i64 |