code wiki / _hdl_build / nx_gamefeel_oracle_gate.nx

nx_gamefeel_oracle_gate.nx source

↩ module page · 206 lines · 8241 B

1// nx_gamefeel_oracle_gate.nx -- FEEL PROVES AGAINST BANKED REFERENCES (operator 2026-08-02: 2// "mine the modding communities and published work as oracles to SKIP guess-and-test"). 3// The crypto lane's KAT law applied to game feel: every tunable the engine ships must sit 4// inside a band banked in knowledge/gamefeel_oracle.conf WITH its sources named; a tunable 5// whose row is MISSING is RED by construction (no unbanked numbers), and every compare is 6// CROSS-MULTIPLIED (the banked truncation law). Values are read from the LIVE symbols the 7// engine itself uses (wc_spec arena + the lib/engine constants) -- the gate cannot drift 8// from the game because they share one definition. 9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 10import "nx_wasm_craft.nx" 11import "nx_gate_verdict.nx" 12const GF_MAGIC_4096: i64 = 4096 13 14const GF_CONF: *u8 = "knowledge/gamefeel_oracle.conf" 15const GF_ROWCAP: i64 = 32 16const GF_TAB: i64 = 9 17const GF_NL: i64 = 10 18const GF_HASH: i64 = 35 19 20static gf_n: i64 21// parsed rows: key offsets into the raw buf + min/max 22static gf_raw: i64 23static gf_keys: i64 // *i64: per row, offset of key start (NUL-terminated in place) 24static gf_min: i64 25static gf_max: i64 26 27func gf_load() -> i64 { 28 let lp: *i64 = sys_mmap(16) as *i64 29 let b: *u8 = sys_read_file("knowledge/gamefeel_oracle.conf\x00" as *u8, lp) 30 if (b as i64) == 0 { return 0 - 1 } 31 let n: i64 = lp[0] 32 gf_raw = b as i64 33 gf_keys = sys_mmap(GF_ROWCAP*8) 34 gf_min = sys_mmap(GF_ROWCAP*8) 35 gf_max = sys_mmap(GF_ROWCAP*8) 36 let ka: *i64 = gf_keys as *i64 37 let mna: *i64 = gf_min as *i64 38 let mxa: *i64 = gf_max as *i64 39 gf_n = 0 40 var i: i64 = 0 41 while i < n { 42 // one LINE per outer pass; inner walks stop AT the newline via a flag -- an `i = n` 43 // sentinel breaks the OUTER walk too (the bug that read a full table as zero rows) 44 if b[i] == (GF_HASH as u8) { 45 var sk: i64 = 1 46 while sk == 1 { 47 if i >= n { sk = 0 } else { 48 if b[i] == (GF_NL as u8) { sk = 0 } else { i = i + 1 } 49 } 50 } 51 } else { 52 let ks: i64 = i 53 var field: i64 = 0 54 var v: i64 = 0 55 var mn: i64 = 0 56 var mx: i64 = 0 57 var sk2: i64 = 1 58 while sk2 == 1 { 59 if i >= n { sk2 = 0 } else { 60 let c: i64 = b[i] 61 if c == GF_NL { sk2 = 0 } else { 62 if c == GF_TAB { 63 if field == 0 { b[i] = 0 as u8 } 64 if field == 1 { mn = v } 65 if field == 2 { mx = v } 66 field = field + 1 67 v = 0 68 } 69 if c >= 48 { if c <= 57 { v = v*10 + (c - 48) } } 70 i = i + 1 71 } 72 } 73 } 74 if field >= 3 { if gf_n < GF_ROWCAP { 75 ka[gf_n] = ks 76 mna[gf_n] = mn 77 mxa[gf_n] = mx 78 gf_n = gf_n + 1 79 } } 80 } 81 i = i + 1 82 } 83 return gf_n 84} 85func gf_eq(a: *u8, b: *u8) -> i64 { 86 var i: i64 = 0 87 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 88 if b[i] != (0 as u8) { return 0 } 89 return 1 90} 91// find a band; returns row index or -1 (a MISSING row must read as failure, never as pass) 92func gf_find(key: *u8) -> i64 { 93 let ka: *i64 = gf_keys as *i64 94 var i: i64 = 0 95 while i < gf_n { 96 if gf_eq(((gf_raw + ka[i]) as *u8), key) == 1 { return i } 97 i = i + 1 98 } 99 return 0 - 1 100} 101// one banded check: value inside [min,max] of its cited row (all integer, no division) 102func gf_band(name: *u8, key: *u8, val: i64, ctr: *i64) -> i64 { 103 let r: i64 = gf_find(key) 104 gv_puts(" " as *u8) 105 gv_puts(name) 106 gv_puts(" = " as *u8) 107 gv_num(val) 108 if r < 0 { 109 gv_puts(" [UNBANKED -- no oracle row]" as *u8) 110 gv_check(name, 0, ctr) 111 return 0 112 } 113 let mnp: *i64 = gf_min as *i64 114 let mxp: *i64 = gf_max as *i64 115 let mn: i64 = mnp[r] 116 let mx: i64 = mxp[r] 117 gv_puts(" band [" as *u8) 118 gv_num(mn) 119 gv_puts(".." as *u8) 120 gv_num(mx) 121 gv_puts("]" as *u8) 122 var ok: i64 = 0 123 if val >= mn { if val <= mx { ok = 1 } } 124 gv_puts("\n" as *u8) 125 gv_check(name, ok, ctr) 126 return ok 127} 128 129func main() -> i64 { 130 let ctr: *i64 = gv_ctr() 131 gv_head("nx_gamefeel_oracle gate -- every feel tunable inside a BANKED, CITED reference band" as *u8) 132 let nrows: i64 = gf_load() 133 if nrows <= 0 { 134 // two DIFFERENT failures, two messages (the ambiguous-return class bit this very 135 // gate on its first run: a parser bug read as "cannot read") 136 if nrows < 0 { gv_puts(" cannot READ knowledge/gamefeel_oracle.conf\n" as *u8) } 137 if nrows == 0 { gv_puts(" table read but ZERO rows parsed\n" as *u8) } 138 gv_check("oracle table present" as *u8, 0, ctr) 139 let rcx: i64 = gv_verdict("GAMEFEEL-ORACLE" as *u8, ctr, "no table" as *u8) 140 sys_exit(rcx) 141 return rcx 142 } 143 // live values from the ENGINE'S OWN definitions (one arena, spec identity 0) 144 let base: i64 = sys_mmap(CRAFT_TOTAL + GF_MAGIC_4096) as i64 145 wc_spec(base, 0) 146 let sp: *i64 = wsp(base) 147 gf_band("day length (s)" as *u8, "day_len_s" as *u8, sp[P_DAYLEN]/60, ctr) 148 gf_band("crop roll cadence (s)" as *u8, "crop_roll_s" as *u8, sp[P_GROWE]/60, ctr) 149 // the BRED chest band: all four firmness stops must sit inside the oracle band 150 var f: i64 = 0 151 var kall: i64 = 1 152 var zall: i64 = 1 153 while f < 4 { 154 let K: i64 = SB_K_CHEST_BASE + f*SB_K_CHEST_STEP 155 let C: i64 = SB_C_CHEST_BASE + f*SB_C_CHEST_STEP 156 let r: i64 = gf_find("chest_k_q10" as *u8) 157 if r < 0 { kall = 0 } 158 if r >= 0 { 159 let mnp2: *i64 = gf_min as *i64 160 let mxp2: *i64 = gf_max as *i64 161 if K < mnp2[r] { kall = 0 } 162 if K > mxp2[r] { kall = 0 } 163 } 164 // zeta band, CROSS-MULTIPLIED: lo^2*4096K <= C^2*10^6 <= hi^2*4096K 165 let rz: i64 = gf_find("chest_zeta_permil" as *u8) 166 if rz < 0 { zall = 0 } 167 if rz >= 0 { 168 let mnp3: *i64 = gf_min as *i64 169 let mxp3: *i64 = gf_max as *i64 170 let lo: i64 = mnp3[rz] 171 let hi: i64 = mxp3[rz] 172 let lhs: i64 = C*C*1000000 173 if lhs < lo*lo*4096*K { zall = 0 } 174 if lhs > hi*hi*4096*K { zall = 0 } 175 } 176 f = f + 1 177 } 178 gv_check("chest K: all 4 bred firmness stops inside the cited band" as *u8, kall, ctr) 179 gv_check("chest zeta: all 4 stops underdamped inside the cited envelope (cross-multiplied)" as *u8, zall, ctr) 180 gf_band("hair K (per-1024)" as *u8, "hair_k_q10" as *u8, SB_K_HAIR, ctr) 181 gf_band("gait bob (q8)" as *u8, "gait_bob_q8" as *u8, WC_GAIT_BOB_Q8, ctr) 182 gf_band("step ease up (q8/t)" as *u8, "step_ease_up_q8" as *u8, WC_STEP_EASE_UP, ctr) 183 gf_band("night start (eighths)" as *u8, "night_x8" as *u8, WC_NIGHT_X8, ctr) 184 // BITE (non-vacuity): a deliberately out-of-band value must FAIL, an in-band one must PASS 185 let rb: i64 = gf_find("gait_bob_q8" as *u8) 186 var bad: i64 = 0 187 var good: i64 = 0 188 if rb >= 0 { 189 let mnp4: *i64 = gf_min as *i64 190 let mxp4: *i64 = gf_max as *i64 191 let bmn: i64 = mnp4[rb] 192 let bmx: i64 = mxp4[rb] 193 // out-of-band probe must FIRE (bad=1); the band's own min must stay SILENT (good=0) 194 let probe: i64 = bmx + 100 195 if probe < bmn { bad = 1 } 196 if probe > bmx { bad = 1 } 197 var silent: i64 = 1 198 if bmn < bmn { silent = 0 } 199 if bmn > bmx { silent = 0 } 200 good = 1 - silent 201 } 202 gv_bite("band check bites out-of-band and passes in-band" as *u8, bad, good, ctr) 203 let rc: i64 = gv_verdict("GAMEFEEL-ORACLE" as *u8, ctr, "feel is cited, never tasted" as *u8) 204 sys_exit(rc) 205 return rc 206}