code wiki / (root) / nx_indoorgen_gate.nx

nx_indoorgen_gate.nx source

↩ module page · 147 lines · 6984 B

1// nx_indoorgen_gate.nx -- GATE for the constraint-solved room generator (GR6, /compare/graphics 2// contract ig_room_solve). Teeth: every shipped (archetype,variant) SOLVES; determinism; the 3// three accept-rule conjuncts re-verified BY THIS GATE'S OWN ARITHMETIC (never by trusting the 4// generator's checker); an anti-vacuity plant proving the checker can FIRE; the named negative 5// control (an unsatisfiable room REFUSES with the worst constraint NAMED, emitting nothing); and 6// the freshness byte-pin (the imported data table equals a live regeneration byte-for-byte). 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_part_solver_lib.nx" 10import "nx_indoorgen_lib.nx" 11import "nx_gate_verdict.nx" 12 13const GG_DATA_PATH_S: i64 = 0 // placeholder to keep consts non-empty 14 15func main() -> i64 { 16 let ctr: *i64 = gv_ctr() 17 gv_head("nx_indoorgen_gate -- rooms by constraint: solved, disjoint, walkable, refusing, fresh" as *u8) 18 19 // T1 every shipped (arch,variant) solves within the salt ladder -- full population, no sample 20 var okc: i64 = 0 21 var rowtot: i64 = 0 22 var a: i64 = 0 23 while a < IG_NARCH { 24 var v2: i64 = 0 25 while v2 < IG_NVAR { 26 let salt: i64 = ig_solve_salted(a, v2) 27 if salt >= 0 { okc = okc + 1; rowtot = rowtot + ig_nrows() } 28 v2 = v2 + 1 29 } 30 a = a + 1 31 } 32 gv_puts(" population: archs=" as *u8); gv_num(IG_NARCH) 33 gv_puts(" vars=" as *u8); gv_num(IG_NVAR) 34 gv_puts(" solved=" as *u8); gv_num(okc) 35 gv_puts(" rows_total=" as *u8); gv_num(rowtot) 36 gv_puts("\n" as *u8) 37 gv_check("T1 every shipped (arch,variant) room SOLVES within the salt ladder" as *u8, (okc == IG_NARCH*IG_NVAR)*(rowtot > 0) == 1, ctr) 38 39 // T2 determinism: re-solving (0,0) reproduces every quantized row exactly 40 let snap: *i64 = sys_mmap(IG_MAXF*8) as *i64 41 ig_solve_salted(0, 0) 42 let n1: i64 = ig_nrows() 43 var i: i64 = 0 44 while i < n1 { snap[i] = ig_row(i); i = i + 1 } 45 ig_solve_salted(0, 0) 46 var t2: i64 = 1 47 if ig_nrows() != n1 { t2 = 0 } 48 i = 0 49 while i < n1 { if ig_row(i) != snap[i] { t2 = 0 } i = i + 1 } 50 gv_check("T2 deterministic: identical quantized rows on re-solve" as *u8, (t2 == 1)*(n1 > 0) == 1, ctr) 51 52 // T3/T4/T5 the accept rule re-verified by THIS gate's arithmetic over the FULL population 53 var viol_overlap: i64 = 0 54 var viol_door: i64 = 0 55 var viol_bounds: i64 = 0 56 var checked: i64 = 0 57 a = 0 58 while a < IG_NARCH { 59 var v3: i64 = 0 60 while v3 < IG_NVAR { 61 if ig_solve_salted(a, v3) >= 0 { 62 let dims: i64 = ig_dims(a) 63 let w: i64 = dims & 255 64 let d: i64 = (dims >> 8) & 255 65 let dx: i64 = ig_doorx(a) 66 var r1: i64 = 0 67 while r1 < ig_nrows() { 68 let ra: i64 = ig_row(r1) 69 let cx: i64 = ra & 255 70 let cz: i64 = (ra >> 8) & 255 71 let dy: i64 = (ra >> 24) & 255 72 checked = checked + 1 73 if cx >= w { viol_bounds = viol_bounds + 1 } 74 if cz >= d { viol_bounds = viol_bounds + 1 } 75 if dy == 1 { 76 if cx == dx { if cz <= 1 { viol_door = viol_door + 1 } } 77 var r2: i64 = r1 + 1 78 while r2 < ig_nrows() { 79 let rb: i64 = ig_row(r2) 80 if ((rb >> 24) & 255) == 1 { 81 if (rb & 255) == cx { if ((rb >> 8) & 255) == cz { viol_overlap = viol_overlap + 1 } } 82 } 83 r2 = r2 + 1 84 } 85 } 86 r1 = r1 + 1 87 } 88 } 89 v3 = v3 + 1 90 } 91 a = a + 1 92 } 93 gv_puts(" accept-rule recheck: cells_checked=" as *u8); gv_num(checked) 94 gv_puts(" overlaps=" as *u8); gv_num(viol_overlap) 95 gv_puts(" door_blocks=" as *u8); gv_num(viol_door) 96 gv_puts(" out_of_bounds=" as *u8); gv_num(viol_bounds) 97 gv_puts("\n" as *u8) 98 gv_check("T3 no two furniture cells coincide, over every shipped layout" as *u8, (viol_overlap == 0)*(checked > 0) == 1, ctr) 99 gv_check("T4 the door approach stays walkable in every shipped layout" as *u8, (viol_door == 0)*(checked > 0) == 1, ctr) 100 gv_check("T5 every furniture cell lies inside its room interior" as *u8, (viol_bounds == 0)*(checked > 0) == 1, ctr) 101 102 // T6 anti-vacuity: a PLANTED collision, a planted door-block and a planted out-of-bounds row 103 // must each make the accept checker refuse -- a checker that has only ever passed is unverified 104 let bad: *i64 = sys_mmap(4*8) as *i64 105 bad[0] = 2 | (2 << 8) | (6 << 16) | (1 << 24) 106 bad[1] = 2 | (2 << 8) | (6 << 16) | (1 << 24) 107 let f1: i64 = ig_ck_accept(bad, 2, 6, 5, 3) 108 bad[0] = 3 | (0 << 8) | (6 << 16) | (1 << 24) 109 let f2: i64 = ig_ck_accept(bad, 1, 6, 5, 3) 110 bad[0] = 9 | (2 << 8) | (6 << 16) | (1 << 24) 111 let f3: i64 = ig_ck_accept(bad, 1, 6, 5, 3) 112 gv_puts(" planted-bad verdicts (must all be 0): collision=" as *u8); gv_num(f1) 113 gv_puts(" door_block=" as *u8); gv_num(f2) 114 gv_puts(" oob=" as *u8); gv_num(f3) 115 gv_puts("\n" as *u8) 116 gv_check("T6 anti-vacuity: the accept checker FIRES on planted collision, door-block and bounds" as *u8, f1 + f2 + f3 == 0, ctr) 117 118 // T7 the named negative control: the 1x2 room cannot hold a bed -- REFUSED, worst NAMED, zero rows 119 let rneg: i64 = ig_room_solve(IG_NEGCTL, 0, 0) 120 var t7: i64 = 0 121 if rneg == 0 { if ig_nrows() == 0 { if ps_worst() >= 0 { t7 = 1 } } } 122 gv_puts(" neg-control worst=" as *u8); gv_puts(ps_kindname(ps_ckind(ps_worst()))) 123 gv_puts(" violation=" as *u8); gv_num(ps_worstv()) 124 gv_puts("\n" as *u8) 125 gv_check("T7 neg-control-unsatisfiable: the impossible room REFUSES with the worst constraint NAMED, emitting nothing" as *u8, t7, ctr) 126 127 // T8 freshness byte-pin: the data table the engine imports equals a live regeneration 128 let fresh: *u8 = sys_mmap(32768) as *u8 129 let fn2: i64 = ige_emit(fresh) 130 let box: *i64 = sys_mmap(16) as *i64 131 let disk: *u8 = sys_read_file("buildroot/runtime/nx_indoorgen_data.nx" as *u8, box) 132 var t8: i64 = 0 133 if fn2 > 0 { if (disk as i64) != 0 { if box[0] == fn2 { 134 var eq: i64 = 1 135 var ci: i64 = 0 136 while ci < fn2 { if disk[ci] != fresh[ci] { eq = 0; ci = fn2 } ci = ci + 1 } 137 t8 = eq 138 } } } 139 gv_puts(" freshness: regen_bytes=" as *u8); gv_num(fn2) 140 gv_puts(" disk_bytes=" as *u8); gv_num(box[0]) 141 gv_puts("\n" as *u8) 142 gv_check("T8 fresh: buildroot/runtime/nx_indoorgen_data.nx byte-matches a live regeneration" as *u8, t8, ctr) 143 144 let rc: i64 = gv_verdict("INDOORGEN-GATE" as *u8, ctr, "rooms are solved, never fabricated: disjoint, walkable, refusable, fresh" as *u8) 145 sys_exit(rc) 146 return rc 147}