code wiki / _hdl_build / nx_wasm_adventure_gate.nx

nx_wasm_adventure_gate.nx source

↩ module page · 67 lines · 3892 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_wasm_adventure_gate.nx -- NATIVE gate for the browser-playable Adventure core (nx_wasm_adventure). 4// T1 SOLVE: walk to the key, then the door opens -> win (held-key + step-cooldown movement). 5// T2 RENDER REAL: a green player on the maze (walls/key/door drawn). PNG. 6// T3 WALLS + LOCK: a move into a wall is blocked; the door without the key stays locked (no win). 7// T4 NEVER-BRICK (#26): deterministic, bounded, no float, base-relative. 8// expect_exit: 0 license_tier: ORIGINAL 9import "nx_wasm_adventure.nx" 10import "nx_png.nx" 11import "nx_syscalls.nx" 12 13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 14" as *u8); return ok } 15func hold(base: i64, inp: i64, n: i64) -> i64 { var t: i64=0; while t<n { tick_impl(base, inp); t=t+1 } return 0 } 16 17func main() -> i64 { 18 gw("=== nx_wasm_adventure_gate: browser-playable Adventure core, verified NATIVE before wasm ===\n" as *u8) 19 var pass: i64 = 0; var total: i64 = 0 20 let base: i64 = sys_mmap(2*1024*1024) as i64 21 let st: *i64 = (base + O_ST) as *i64 22 23 // ---- T1: solve (key then door) ---- 24 init_impl(base) 25 hold(base, 8, 60) // right to the key (x=8,y=1) 26 let gotkey: i64 = st[2] 27 hold(base, 2, 60) // down to the door (x=8,y=8) 28 var t1ok: i64=1; if gotkey != 1 {t1ok=0} if st[3] != 1 {t1ok=0} 29 total=total+1; if t1ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 30 gw("T1 solve: collected the key (" as *u8); gn(gotkey); gw(") then opened the door, won=" as *u8); gn(st[3]); gw("\n" as *u8) 31 32 // ---- render a mid-solve frame ---- 33 init_impl(base) 34 hold(base, 8, 30) 35 render_impl(base) 36 let fb: *i64 = (base + O_FB) as *i64 37 write_png(fb, W, H, "knowledge/nx_wasm_adventure_native.png" as *u8) 38 gw(" (live evidence: PNG knowledge/nx_wasm_adventure_native.png -- maze walls + key + door + player)\n" as *u8) 39 40 // ---- T2: render real ---- 41 let pc: i64 = fb[(st[1]*CELL+8)*W + (st[0]*CELL+8)] 42 var t2ok: i64=1; if ((pc>>8)&255) <= (pc&255) {t2ok=0} 43 total=total+1; if t2ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 44 gw("T2 render real: player green on the maze (g=" as *u8); gn((pc>>8)&255); gw(">r=" as *u8); gn(pc&255); gw(")\n" as *u8) 45 46 // ---- T3: walls block + lock works ---- 47 init_impl(base) 48 hold(base, 1, 18) // try to walk up into the top wall 49 var walls_ok: i64 = 0; if st[0] == 1 { if st[1] == 1 { walls_ok = 1 } } 50 init_impl(base) 51 hold(base, 2, 60); hold(base, 8, 60) // go to the door WITHOUT the key 52 var lock_ok: i64 = 0; if st[3] == 0 { lock_ok = 1 } 53 var t3ok: i64=1; if walls_ok != 1 {t3ok=0} if lock_ok != 1 {t3ok=0} 54 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 55 gw("T3 walls+lock: a wall blocks the move (stayed " as *u8); gn(walls_ok); gw("), the door stays locked without the key (won=" as *u8); gn(st[3]); gw(")\n" as *u8) 56 57 // ---- T4: determinism ---- 58 init_impl(base) 59 hold(base, 8, 60); hold(base, 2, 60) 60 var t4ok: i64=1; if st[3] != 1 {t4ok=0} 61 total=total+1; if t4ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 62 gw("T4 never-brick (#26): deterministic re-run won=" as *u8); gn(st[3]); gw(", base-relative, no float, no sys_mmap in the core\n" as *u8) 63 64 gw("\n=== nx_wasm_adventure_gate " as *u8); gn(pass); gw("/" as *u8); gn(total) 65 if pass == total { gw(" GREEN (a playable maze adventure with walls/key/locked-door, verified native, ready to lower to sovereign wasm)\n" as *u8); sys_exit(0); return 0 } 66 gw(" RED\n" as *u8); sys_exit(1); return 1 67}