code wiki / _hdl_build / nx_game_breed_gate.nx
nx_game_breed_gate.nx source
↩ module page · 322 lines · 16302 B
1// nx_game_breed_gate.nx -- proves the breeders mechanic end-to-end with the lane's discipline.
2// The flagship claims, each with its refutation path designed in:
3// dominance is EARNED (a scrape-by win must NOT dominate -- T2's found-seed control)
4// the game is LOSABLE (a weak player genuinely loses -- T1b)
5// the one you dominated is the one you OWN (byte-equal genes across capture -- T3)
6// inheritance is REAL (every child gene provably near a parent slot -- T4; the mutation target)
7// breeding never mass-produces (uniqueness at roster scale -- T5)
8// persistence is transparent (save -> load -> SAME child from the same pair+seed -- T6)
9// beats are causal + the whole thing replays bit-exact (T7)
10// MUTATION TARGET (documented): brd_gene -> pure rng ignoring parents => T4 RED, T5/T7 stay GREEN.
11// license_tier: ORIGINAL
12import "nx_syscalls.nx"
13import "nx_game_breed.nx"
14import "nx_gamesave.nx"
15
16func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
17func pn(v: i64) -> i64 {
18 let t: *u8 = sys_mmap(32) as *u8
19 var m: i64 = v
20 var w: i64 = 0
21 if m < 0 { t[w] = 45 as u8; w = w + 1; m = 0 - m }
22 if m == 0 { t[w] = 48 as u8; sys_write(1, t, w + 1); return 0 }
23 let d: *u8 = sys_mmap(32) as *u8
24 var k: i64 = 0
25 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
26 var j: i64 = 0
27 while j < k { t[w] = d[k - 1 - j]; w = w + 1; j = j + 1 }
28 sys_write(1, t, w)
29 return 0
30}
31func nl() -> i64 { p("\n" as *u8); return 0 }
32
33// spawn a companion with EXACT genes (test authoring helper)
34func mk(ros: *i64, sp: i64, a: i64, b: i64, c: i64, d: i64, lvl: i64) -> i64 {
35 let h: i64 = en_spawn(ros)
36 en_set(ros, h, C_SPEC, sp)
37 en_set(ros, h, C_IV0, a); en_set(ros, h, C_IV1, b)
38 en_set(ros, h, C_IV2, c); en_set(ros, h, C_IV3, d)
39 en_set(ros, h, C_XP, 0); en_set(ros, h, C_LVL, lvl)
40 en_set(ros, h, C_NICK, en_count(ros) - 1)
41 return h
42}
43
44func main() -> i64 {
45 p("=== nx_game_breed_gate (win -> dominate -> submit -> own -> breed) ===\n" as *u8)
46 var pass: i64 = 0
47 let checks: i64 = 8
48 let tbl: *i64 = sys_mmap(64 * 8) as *i64
49 brd_species_default(tbl)
50 let buf: *u8 = sys_mmap(65536) as *u8
51 let out: *i64 = sys_mmap(64) as *i64
52 let bt: *i64 = sys_mmap((1 + 512*BRD_BEAT_STRIDE) * 8) as *i64
53 bt[0] = 0
54
55 // ---------- T1: crushing win DOMINATES + weak player LOSES ----------
56 let rosP: *i64 = sys_mmap(en_bytes(64, COMP_NC)) as *i64
57 en_init(rosP, 64, COMP_NC)
58 let rosW: *i64 = sys_mmap(en_bytes(64, COMP_NC)) as *i64
59 en_init(rosW, 64, COMP_NC)
60 let champ: i64 = mk(rosP, 1, 28, 30, 26, 29, 8) // strong Flamia, lvl 8
61 let prey: i64 = mk(rosW, 0, 3, 2, 4, 3, 2) // weak gentle Sylph, lvl 2 (bar 350)
62 let win1: i64 = brd_duel(rosP, champ, rosW, prey, tbl, 4242, buf, bt, 512, 1, out)
63 var t1a: i64 = 0
64 if win1 == 0 { if out[1] == 1 { if out[0] >= 350 { t1a = 1 } } }
65 let runt: i64 = mk(rosP, 0, 2, 2, 2, 2, 1) // hopeless challenger
66 let alpha: i64 = mk(rosW, 3, 30, 31, 29, 30, 9) // proud Voltra, lvl 9
67 let win1b: i64 = brd_duel(rosP, runt, rosW, alpha, tbl, 777, buf, bt, 512, 2, out)
68 var t1: i64 = 0
69 if t1a == 1 { if win1b == 1 { t1 = 1 } }
70 if t1 == 1 { pass = pass + 1; p("T1 GREEN dominance earned + LOSABLE: crushing win margin cleared the bar (submit), and the runt genuinely LOST\n" as *u8) }
71 if t1 == 0 { p("T1 RED t1a=" as *u8); pn(t1a); p(" win1b=" as *u8); pn(win1b); nl() }
72
73 // ---------- T2: a SCRAPE-BY win must NOT dominate (found-seed control) ----------
74 var found2: i64 = 0
75 var resist_ok: i64 = 0
76 var sd2: i64 = 1
77 while sd2 < 200 {
78 if found2 == 0 {
79 let rA: *i64 = sys_mmap(en_bytes(8, COMP_NC)) as *i64
80 en_init(rA, 8, COMP_NC)
81 let rB: *i64 = sys_mmap(en_bytes(8, COMP_NC)) as *i64
82 en_init(rB, 8, COMP_NC)
83 let ha: i64 = mk(rA, 3, 15, 15, 15, 15, 5) // proud Voltra mirror match (bar 500)
84 let hb: i64 = mk(rB, 3, 15, 15, 15, 15, 5)
85 let w2: i64 = brd_duel(rA, ha, rB, hb, tbl, sd2, buf, bt, 512, 10 + sd2, out)
86 if w2 == 0 { if out[0] < 500 {
87 found2 = 1
88 if out[1] == 0 { resist_ok = 1 }
89 } }
90 }
91 sd2 = sd2 + 1
92 }
93 var t2: i64 = 0
94 if found2 == 1 { if resist_ok == 1 { t2 = 1 } }
95 if t2 == 1 { pass = pass + 1; p("T2 GREEN scrape-by win does NOT dominate: found a sub-bar victory margin=" as *u8); pn(out[0]); p(" -> she RESISTS, no capture\n" as *u8) }
96 if t2 == 0 { p("T2 RED found=" as *u8); pn(found2); p(" resist=" as *u8); pn(resist_ok); nl() }
97
98 // ---------- T3: capture preserves the EXACT gene vector (ownership law) ----------
99 comp_new_roster(rosW, 64, 6, 987654321, 1)
100 var t3: i64 = 0
101 // find a wild, record genes, force-submit path via a champion duel then capture
102 let wild3: i64 = en_nth(rosW, 0)
103 let g0: i64 = en_get(rosW, wild3, C_SPEC)
104 let g1: i64 = en_get(rosW, wild3, C_IV0)
105 let g2: i64 = en_get(rosW, wild3, C_IV1)
106 let g3: i64 = en_get(rosW, wild3, C_IV2)
107 let g4: i64 = en_get(rosW, wild3, C_IV3)
108 let vec_before: i64 = comp_vec(rosW, wild3)
109 let nwild_before: i64 = en_count(rosW)
110 let cap3: i64 = brd_capture(rosP, rosW, wild3)
111 if cap3 > 0 {
112 if en_get(rosP, cap3, C_SPEC) == g0 { if en_get(rosP, cap3, C_IV0) == g1 {
113 if en_get(rosP, cap3, C_IV1) == g2 { if en_get(rosP, cap3, C_IV2) == g3 {
114 if en_get(rosP, cap3, C_IV3) == g4 {
115 if comp_vec(rosP, cap3) == vec_before {
116 if en_count(rosW) == nwild_before - 1 {
117 if en_valid(rosW, wild3) == 0 { t3 = 1 }
118 }
119 }
120 } } } } }
121 }
122 if t3 == 1 { pass = pass + 1; p("T3 GREEN the one you dominated is the one you own: gene vector byte-equal across capture, wild slot invalidated\n" as *u8) }
123 if t3 == 0 { p("T3 RED capture identity\n" as *u8) }
124
125 // ---------- T4: inheritance PROVABLE across 200 breedings (the mutation target) ----------
126 var t4: i64 = 0
127 var inherit_all: i64 = 1
128 var mutated_children: i64 = 0
129 var distinct_ck: i64 = 0
130 let seen4: *i64 = sys_mmap(256 * 8) as *i64
131 var b4: i64 = 0
132 while b4 < 200 {
133 let r4: *i64 = sys_mmap(en_bytes(8, COMP_NC)) as *i64
134 en_init(r4, 8, COMP_NC)
135 var s4: i64 = b4 * 2654435761 + 12345
136 if s4 < 0 { s4 = 0 - s4 }
137 let pa: i64 = mk(r4, s4 % 6, s4 % 32, (s4/32) % 32, (s4/1024) % 32, (s4/32768) % 32, 3)
138 var s4b: i64 = s4 * 48271 + 7
139 if s4b < 0 { s4b = 0 - s4b }
140 let pb: i64 = mk(r4, s4b % 6, s4b % 32, (s4b/32) % 32, (s4b/1024) % 32, (s4b/32768) % 32, 3)
141 let ch4: i64 = brd_breed(r4, pa, pb, 1, b4 + 1, bt, 512, 100 + b4)
142 if ch4 > 0 {
143 if brd_inherit_ok(r4, ch4, pa, pb) == 0 { inherit_all = 0 }
144 // did mutation actually move at least one gene off BOTH parents?
145 var moved: i64 = 0
146 var k4: i64 = 0
147 while k4 < 4 {
148 let cg: i64 = en_get(r4, ch4, C_IV0 + k4)
149 if cg != en_get(r4, pa, C_IV0 + k4) { if cg != en_get(r4, pb, C_IV0 + k4) { moved = 1 } }
150 k4 = k4 + 1
151 }
152 if moved == 1 { mutated_children = mutated_children + 1 }
153 let cv: i64 = comp_vec(r4, ch4) % 251
154 if seen4[cv] == 0 { seen4[cv] = 1; distinct_ck = distinct_ck + 1 }
155 }
156 if ch4 <= 0 { inherit_all = 0 }
157 b4 = b4 + 1
158 }
159 if inherit_all == 1 { if mutated_children > 30 { if distinct_ck > 60 { t4 = 1 } } }
160 if t4 == 1 { pass = pass + 1; p("T4 GREEN inheritance real: 200/200 children within the mutation bound of a parent slot; " as *u8); pn(mutated_children); p(" carried a real mutation; " as *u8); pn(distinct_ck); p(" distinct lines\n" as *u8) }
161 if t4 == 0 { p("T4 RED inherit_all=" as *u8); pn(inherit_all); p(" mutated=" as *u8); pn(mutated_children); p(" distinct=" as *u8); pn(distinct_ck); nl() }
162
163 // ---------- T5: breeding never mass-produces -- uniqueness at roster scale ----------
164 let ros5: *i64 = sys_mmap(en_bytes(128, COMP_NC)) as *i64
165 en_init(ros5, 128, COMP_NC)
166 comp_new_roster(ros5, 128, 8, 555777, 1)
167 var b5: i64 = 0
168 while b5 < 40 {
169 let pa5: i64 = en_nth(ros5, b5 % 8)
170 let pb5: i64 = en_nth(ros5, (b5 + 3) % 8)
171 brd_breed(ros5, pa5, pb5, b5 & 1, b5 * 7919 + 11, bt, 512, 300 + b5)
172 b5 = b5 + 1
173 }
174 var t5: i64 = 0
175 if comp_dup_count(ros5) == 0 { if en_count(ros5) == 48 { t5 = 1 } }
176 if t5 == 1 { pass = pass + 1; p("T5 GREEN uniqueness through breeding: 8 founders + 40 offspring = 48, ZERO duplicate identity vectors\n" as *u8) }
177 if t5 == 0 { p("T5 RED dups=" as *u8); pn(comp_dup_count(ros5)); p(" n=" as *u8); pn(en_count(ros5)); nl() }
178
179 // ---------- T6: save -> load -> the SAME pair+seed breeds the SAME child (transparent persistence) ----------
180 var t6: i64 = 0
181 let S6: *i64 = sys_mmap((1 + 128*COMP_NC) * 8) as *i64
182 let ns6: i64 = comp_serialize(ros5, S6)
183 let rcs: i64 = gs_save("knowledge/nx_breed_t6.sav" as *u8, 9202, S6, ns6, 2000)
184 let L6: *i64 = sys_mmap((1 + 128*COMP_NC) * 8) as *i64
185 let meta6: *i64 = sys_mmap(64) as *i64
186 let rcl: i64 = gs_load("knowledge/nx_breed_t6.sav" as *u8, L6, 1 + 128*COMP_NC, meta6)
187 if rcs > 0 { if rcl >= 0 {
188 let ros6: *i64 = sys_mmap(en_bytes(128, COMP_NC)) as *i64
189 comp_restore(ros6, 128, L6)
190 // breed the same (first,second) pair with the same seed in BOTH worlds
191 let a6: i64 = en_nth(ros5, 0)
192 let b6: i64 = en_nth(ros5, 1)
193 let a6r: i64 = en_nth(ros6, 0)
194 let b6r: i64 = en_nth(ros6, 1)
195 let c6: i64 = brd_breed(ros5, a6, b6, 1, 31415, bt, 512, 400)
196 let c6r: i64 = brd_breed(ros6, a6r, b6r, 1, 31415, bt, 512, 400)
197 if c6 > 0 { if c6r > 0 {
198 if comp_vec(ros5, c6) == comp_vec(ros6, c6r) {
199 if en_count(ros6) == en_count(ros5) { t6 = 1 }
200 }
201 } }
202 } }
203 if t6 == 1 { pass = pass + 1; p("T6 GREEN persistence transparent: loaded roster breeds the IDENTICAL child from the same pair+seed\n" as *u8) }
204 if t6 == 0 { p("T6 RED rcs=" as *u8); pn(rcs); p(" rcl=" as *u8); pn(rcl); nl() }
205
206 // ---------- T7: beat causality + determinism + anti-vacuity ----------
207 // causality: every SUBMIT immediately follows a DOMINATE (same tick); every BIRTH follows a MATE
208 var causal: i64 = 1
209 var i7: i64 = 0
210 let nb: i64 = brd_beats(bt)
211 while i7 < nb {
212 if brd_beat_kind(bt, i7) == BEAT_SUBMIT {
213 if i7 == 0 { causal = 0 }
214 if i7 > 0 { if brd_beat_kind(bt, i7 - 1) != BEAT_DOMINATE { causal = 0 } }
215 }
216 if brd_beat_kind(bt, i7) == BEAT_BIRTH {
217 if i7 == 0 { causal = 0 }
218 if i7 > 0 { if brd_beat_kind(bt, i7 - 1) != BEAT_MATE { causal = 0 } }
219 }
220 i7 = i7 + 1
221 }
222 // anti-vacuity: all the important beat kinds actually occurred in this gate run
223 var kw: i64 = 0
224 var kd: i64 = 0
225 var ks: i64 = 0
226 var kr: i64 = 0
227 var kdef: i64 = 0
228 var km: i64 = 0
229 var kb: i64 = 0
230 var j7: i64 = 0
231 while j7 < nb {
232 let bk: i64 = brd_beat_kind(bt, j7)
233 if bk == BEAT_WIN { kw = 1 }
234 if bk == BEAT_DOMINATE { kd = 1 }
235 if bk == BEAT_SUBMIT { ks = 1 }
236 if bk == BEAT_RESIST { kr = 1 }
237 if bk == BEAT_DEFEAT { kdef = 1 }
238 if bk == BEAT_MATE { km = 1 }
239 if bk == BEAT_BIRTH { kb = 1 }
240 j7 = j7 + 1
241 }
242 let kinds: i64 = kw + kd + ks + kr + kdef + km + kb
243 // determinism: replay the T1 crushing duel -- identical margin + beats appended identically
244 let btr: *i64 = sys_mmap((1 + 32*BRD_BEAT_STRIDE) * 8) as *i64
245 btr[0] = 0
246 let outr: *i64 = sys_mmap(64) as *i64
247 brd_duel(rosP, champ, rosW, prey, tbl, 4242, buf, btr, 32, 1, outr)
248 var det: i64 = 0
249 if outr[0] == out[0] { det = 1 } // margin bit-equal on replay
250 // NOTE: out[] was last written by T2's search loop; recompute the T1 duel fresh for both sides
251 let bt2: *i64 = sys_mmap((1 + 32*BRD_BEAT_STRIDE) * 8) as *i64
252 bt2[0] = 0
253 let outa: *i64 = sys_mmap(64) as *i64
254 let outb: *i64 = sys_mmap(64) as *i64
255 brd_duel(rosP, champ, rosW, prey, tbl, 4242, buf, bt2, 32, 1, outa)
256 brd_duel(rosP, champ, rosW, prey, tbl, 4242, buf, bt2, 32, 1, outb)
257 det = 0
258 if outa[0] == outb[0] { if outa[1] == outb[1] { if outa[0] > 0 { det = 1 } } }
259 var t7: i64 = 0
260 if causal == 1 { if kinds == 7 { if det == 1 { if nb > 240 { t7 = 1 } } } }
261 if t7 == 1 { pass = pass + 1; p("T7 GREEN beats causal (SUBMIT<-DOMINATE, BIRTH<-MATE), all 7 beat kinds real, duel replay bit-equal, " as *u8); pn(nb); p(" beats\n" as *u8) }
262 if t7 == 0 { p("T7 RED causal=" as *u8); pn(causal); p(" kinds=" as *u8); pn(kinds); p(" det=" as *u8); pn(det); p(" beats=" as *u8); pn(nb); nl() }
263
264 // ---------- T8: the MENDELIAN genome inherits THROUGH brd_breed (proves the A3 wiring, e2e) ----------
265 // Two heterozygous-horned parents bred through the REAL game verb must yield the 3:1 phenotype ratio
266 // in their children's genomes -- if brd_breed dropped the genome or re-rolled it, this collapses.
267 let ros8: *i64 = sys_mmap(en_bytes(600, COMP_NC)) as *i64
268 en_init(ros8, 600, COMP_NC)
269 let het8: i64 = gx_set(0, GX_HORN, 0, 1)
270 let ma: i64 = mk(ros8, 1, 16, 16, 16, 16, 5)
271 let pa8: i64 = mk(ros8, 1, 16, 16, 16, 16, 5)
272 en_set(ros8, ma, C_GENO, het8); en_set(ros8, pa8, C_GENO, het8)
273 en_set(ros8, ma, C_SEXG, gx_sexgene(GX_SEX_F, 1, 0))
274 en_set(ros8, pa8, C_SEXG, gx_sexgene(GX_SEX_M, 1, 0))
275 en_set(ros8, ma, C_POLY, 85); en_set(ros8, pa8, C_POLY, 85)
276 let info8: *i64 = sys_mmap(8 * 8) as *i64
277 var horned: i64 = 0
278 var kids: i64 = 0
279 var sons: i64 = 0
280 var recomb8: i64 = 0
281 // ANTI-VACUITY: all THREE genotype classes must actually appear (HH / Hh / hh). A breed path that
282 // returned a constant genome would still hit a phenotype ratio by luck if we only counted phenotypes.
283 var nHH: i64 = 0
284 var nHet: i64 = 0
285 var nhh: i64 = 0
286 var b8: i64 = 0
287 while b8 < 500 {
288 let k: i64 = brd_breed_info(ros8, ma, pa8, 1, 7000 + b8*13, bt, 512, 500 + b8, info8)
289 if k > 0 {
290 kids = kids + 1
291 let kg: i64 = en_get(ros8, k, C_GENO)
292 if gx_phenotype(kg, GX_HORN) == 1 { horned = horned + 1 }
293 let ka: i64 = gx_a0(kg, GX_HORN)
294 let kb: i64 = gx_a1(kg, GX_HORN)
295 if ka == 1 { if kb == 1 { nHH = nHH + 1 } }
296 if ka != kb { nHet = nHet + 1 }
297 if ka == 0 { if kb == 0 { nhh = nhh + 1 } }
298 if info8[3] == GX_SEX_M { sons = sons + 1 }
299 recomb8 = recomb8 + info8[0]
300 }
301 b8 = b8 + 1
302 }
303 var ratio8: i64 = 0
304 if kids > 0 { ratio8 = horned * 1000 / kids }
305 var sexr8: i64 = 0
306 if kids > 0 { sexr8 = sons * 1000 / kids }
307 var t8: i64 = 0
308 var d8: i64 = ratio8 - 750
309 if d8 < 0 { d8 = 0 - d8 }
310 var ds8: i64 = sexr8 - 500
311 if ds8 < 0 { ds8 = 0 - ds8 }
312 var allthree: i64 = 0
313 if nHH > 0 { if nHet > 0 { if nhh > 0 { allthree = 1 } } }
314 if kids == 500 { if d8 <= 60 { if ds8 <= 70 { if recomb8 > 0 { if allthree == 1 { t8 = 1 } } } } }
315 if t8 == 1 { pass = pass + 1; p("T8 GREEN genome inherits THROUGH the game verb: 500 children of Hh x Hh are " as *u8); pn(ratio8); p(" permil horned (Mendel's 3:1 = 750), genotypes HH/Hh/hh = " as *u8); pn(nHH); p("/" as *u8); pn(nHet); p("/" as *u8); pn(nhh); p(" (the 1:2:1), sex ratio " as *u8); pn(sexr8); p(", " as *u8); pn(recomb8); p(" crossing-over events -- the science survives the wiring\n" as *u8) }
316 if t8 == 0 { p("T8 RED genome-through-breed kids=" as *u8); pn(kids); p(" horned=" as *u8); pn(ratio8); p(" sex=" as *u8); pn(sexr8); p(" recomb=" as *u8); pn(recomb8); p(" HH/Het/hh=" as *u8); pn(nHH); p("/" as *u8); pn(nHet); p("/" as *u8); pn(nhh); nl() }
317
318 p("nx_game_breed_gate: " as *u8); pn(pass); p("/" as *u8); pn(checks); nl()
319 if pass == checks { p("VERDICT GREEN\n" as *u8); return 0 }
320 p("VERDICT RED\n" as *u8)
321 return 1
322}