code wiki / _hdl_build / nx_game_render_gate.nx

nx_game_render_gate.nx source

↩ module page · 105 lines · 7335 B

1// nx_game_render_gate.nx -- GATE: the GAME loop closed. Teach a temp catalog the game emitters, RUN the level 2// through the deterministic spec->runtime, and assert: the world is built from the catalog (coins/foes/exit/ 3// tilemap), the mechanic PHYSICS is consumed (two different gravities -> two different jump apexes = not a 4// hardcode), the traversal actually PLAYS (every declared coin collected, every patroller cleared, damage = 5// foes*hp, exit reached), GROW->consume (a newly-taught level plays with NO code change), a NEGATIVE CONTROL 6// (an unknown level id REFUSES instead of fabricating a run), and SOVEREIGNTY (the transcript carries 0 7// third-party JS and the detector still FIRES on a planted tag). Emits a preview to 8// knowledge/staging/game/run_1-1.txt. license_tier: ORIGINAL 9import "nx_game_render.nx" 10import "nx_nishi_builder.nx" 11import "nx_ad_serve.nx" 12import "nx_syscalls.nx" 13 14const GG_PATH: *u8 = "/tmp/nishi_game_gate.tsv" 15 16func g_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 g_i(v: i64) -> i64 { let t: *u8 = sys_mmap(24); var m: i64 = v; var k: i64 = 0; if m == 0 { t[0]=48 as u8; k=1 } while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 } 18 19func main(argc: i64, argv: *i64) -> i64 { 20 g_p("=== nx_game_render_gate ===\n" as *u8) 21 let fd: i64 = sys_openat_wr(GG_PATH, 420); if fd >= 0 { sys_close(fd) } 22 nb_register(GG_PATH, "game" as *u8, "tilemap" as *u8, "overworld" as *u8, "Overworld" as *u8, "32x32|grass,dirt,water,stone|autotile" as *u8) 23 nb_register(GG_PATH, "game" as *u8, "mechanic" as *u8, "platform-jump" as *u8, "Platform jump" as *u8, "impulse=12|gravity=0.6|coyote=80|jumpbuffer=120" as *u8) 24 nb_register(GG_PATH, "game" as *u8, "mechanic" as *u8, "moon" as *u8, "Moon jump" as *u8, "impulse=12|gravity=0.3" as *u8) 25 nb_register(GG_PATH, "game" as *u8, "entity" as *u8, "patroller" as *u8, "Patrol enemy" as *u8, "hp=3|speed=2|ai=patrol|drop=coin" as *u8) 26 nb_register(GG_PATH, "game" as *u8, "level" as *u8, "1-1" as *u8, "First level" as *u8, "overworld|coin*12|patroller*3|exit-right" as *u8) 27 28 let st: *i64 = sys_mmap(512) as *i64 29 30 // ---- run the seeded level with the platform-jump mechanic ---- 31 ng_sim_run(GG_PATH, "1-1" as *u8, "platform-jump" as *u8, "patroller" as *u8, st) 32 let valid: i64 = st[15]; let coins: i64 = st[1]; let patr: i64 = st[3]; let exitx: i64 = st[5] 33 let tmok: i64 = st[14]; let win: i64 = st[7]; let cc: i64 = st[2]; let pd: i64 = st[4] 34 let dmg: i64 = st[13]; let ticks: i64 = st[6]; let apex_pj: i64 = st[8] 35 36 // emit the sovereign transcript artifact 37 let buf: *u8 = sys_mmap(4096) 38 let blen: i64 = ng_transcript(st, "1-1" as *u8, buf) 39 sys_mkdir("knowledge/staging/game" as *u8, 0x1ed) 40 let wfd: i64 = sys_openat_wr("knowledge/staging/game/run_1-1.txt" as *u8, 420); if wfd >= 0 { sys_write(wfd, buf, blen); sys_close(wfd) } 41 g_p("ran level 1-1 -> transcript " as *u8); g_i(blen); g_p("B to knowledge/staging/game/run_1-1.txt\n" as *u8) 42 43 var pass: i64 = 0; var tot: i64 = 0 44 45 // T1 world built from the catalog 46 tot = tot + 1; var ok1: i64 = 1 47 if valid != 1 { ok1 = 0 } 48 if coins != 12 { ok1 = 0 } 49 if patr != 3 { ok1 = 0 } 50 if exitx != 16 { ok1 = 0 } 51 if tmok != 1 { ok1 = 0 } 52 if win != 1 { ok1 = 0 } 53 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 world from catalog: coins=12 patrollers=3 exit_x=16 tilemap resolved, win\n" as *u8) } else { g_p("FAIL T1 coins=" as *u8); g_i(coins); g_p(" patr=" as *u8); g_i(patr); g_p(" exit=" as *u8); g_i(exitx); g_p(" tmok=" as *u8); g_i(tmok); g_p("\n" as *u8) } 54 55 // T2 PHYSICS consumed -- two gravities -> two apexes (anti-hardcode) 56 ng_sim_run(GG_PATH, "1-1" as *u8, "moon" as *u8, "patroller" as *u8, st) 57 let apex_moon: i64 = st[8] 58 tot = tot + 1; var ok2: i64 = 1 59 if apex_pj != 126000 { ok2 = 0 } 60 if apex_moon != 246000 { ok2 = 0 } 61 if apex_moon <= apex_pj { ok2 = 0 } 62 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 physics consumed: platform apex=126000, moon apex=246000 (gravity drives apex, not a hardcode)\n" as *u8) } else { g_p("FAIL T2 apex_pj=" as *u8); g_i(apex_pj); g_p(" apex_moon=" as *u8); g_i(apex_moon); g_p("\n" as *u8) } 63 64 // T3 the runtime actually PLAYS 65 tot = tot + 1; var ok3: i64 = 1 66 if cc != 12 { ok3 = 0 } 67 if pd != 3 { ok3 = 0 } 68 if dmg != 9 { ok3 = 0 } 69 if ticks != 16 { ok3 = 0 } 70 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 playthrough: collected 12/12 coins, cleared 3/3 patrollers, dmg=9 (3*hp), 16 ticks to exit\n" as *u8) } else { g_p("FAIL T3 cc=" as *u8); g_i(cc); g_p(" pd=" as *u8); g_i(pd); g_p(" dmg=" as *u8); g_i(dmg); g_p(" ticks=" as *u8); g_i(ticks); g_p("\n" as *u8) } 71 72 // T4 GROW -> consume: teach a NEW level, the SAME runtime plays it (no code change) 73 nb_register(GG_PATH, "game" as *u8, "level" as *u8, "2-1" as *u8, "Second level" as *u8, "overworld|coin*20|patroller*5|exit-right" as *u8) 74 ng_sim_run(GG_PATH, "2-1" as *u8, "platform-jump" as *u8, "patroller" as *u8, st) 75 tot = tot + 1; var ok4: i64 = 1 76 if st[15] != 1 { ok4 = 0 } 77 if st[1] != 20 { ok4 = 0 } 78 if st[2] != 20 { ok4 = 0 } 79 if st[3] != 5 { ok4 = 0 } 80 if st[5] != 26 { ok4 = 0 } 81 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 grow->consume: newly-taught level 2-1 plays (20 coins, 5 patrollers, exit_x=26), no code change\n" as *u8) } else { g_p("FAIL T4 coins=" as *u8); g_i(st[1]); g_p(" cc=" as *u8); g_i(st[2]); g_p(" patr=" as *u8); g_i(st[3]); g_p(" exit=" as *u8); g_i(st[5]); g_p("\n" as *u8) } 82 83 // T5 NEGATIVE CONTROL: an unknown level id REFUSES (no fabricated playthrough) 84 ng_sim_run(GG_PATH, "9-9" as *u8, "platform-jump" as *u8, "patroller" as *u8, st) 85 tot = tot + 1; var ok5: i64 = 1 86 if st[15] != 0 { ok5 = 0 } 87 if st[7] != 0 { ok5 = 0 } 88 if st[2] != 0 { ok5 = 0 } 89 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 negative control: unknown level 9-9 refused (valid=0, win=0, 0 coins) -- no fabricated run\n" as *u8) } else { g_p("FAIL T5 valid=" as *u8); g_i(st[15]); g_p(" win=" as *u8); g_i(st[7]); g_p(" cc=" as *u8); g_i(st[2]); g_p("\n" as *u8) } 90 91 // T6 SOVEREIGNTY: transcript has 0 third-party JS, and the detector still fires on a planted tag 92 tot = tot + 1; var ok6: i64 = 1 93 if as_has_thirdparty_js(buf, blen) != 0 { ok6 = 0 } 94 let ltpl: *u8 = sys_mmap(256) 95 if nb_lookup(GG_PATH, "game" as *u8, "level" as *u8, "1-1" as *u8, ltpl) == 1 { if nb_template_safe(ltpl) != 1 { ok6 = 0 } } else { ok6 = 0 } 96 if nb_template_safe("<script>x</script>" as *u8) != 0 { ok6 = 0 } 97 if nb_template_safe("<img src='//cdn/x'>" as *u8) != 0 { ok6 = 0 } 98 if as_has_thirdparty_js("<script>x</script>" as *u8, 18) != 1 { ok6 = 0 } 99 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereignty: 0 third-party JS in the transcript; <script/src= REJECTED; detector fires on a planted tag\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 100 101 g_p("nx_game_render_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 102 if pass == tot { g_p(" verdict=GREEN (game domain loop CLOSED: catalog -> deterministic playthrough)\n" as *u8); return 0 } 103 g_p(" verdict=RED\n" as *u8) 104 return 1 105}