code wiki / _hdl_build / nx_wasm_racing_gate.nx
nx_wasm_racing_gate.nx source
↩ module page · 102 lines · 6386 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_wasm_racing_gate.nx -- NATIVE gate for the browser-playable racing core (nx_wasm_racing). Verifies the
4// game + render with base = a real mmap BEFORE lowering to wasm.
5// T1 COLLISION REAL: an opponent overlapping the player ends the run; opponents far away do not.
6// T2 RENDER REAL: a green player car + a red opponent car on the road (PNG).
7// T3 GAME-OVER + RESTART: a crash ends the run; restart input resets it.
8// T4 NEVER-BRICK (#26): deterministic, bounded, no float, base-relative.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_wasm_racing.nx"
11import "nx_png.nx"
12import "nx_syscalls.nx"
13import "nx_gate_verdict.nx"
14
15func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
16" as *u8); return ok }
17
18func main() -> i64 {
19 gw("=== nx_wasm_racing_gate: browser-playable racing core, verified NATIVE before wasm ===\n" as *u8)
20 var pass: i64 = 0; var total: i64 = 0
21 let base: i64 = sys_mmap(2*1024*1024) as i64
22 let ox: *i64 = (base + O_OX) as *i64
23 let oy: *i64 = (base + O_OY) as *i64
24 let st: *i64 = (base + O_ST) as *i64
25
26 // ---- T1: collision real ----
27 init_impl(base)
28 ox[0] = st[0]; oy[0] = SY // force an opponent onto the player
29 tick_impl(base, 0)
30 let crashed: i64 = st[2]
31 init_impl(base)
32 tick_impl(base, 0) // opponents still off-screen -> no crash
33 let safe: i64 = st[2]
34 var t1ok: i64=1; if crashed != 1 {t1ok=0} if safe != 0 {t1ok=0}
35 total=total+1; if t1ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
36 gw("T1 collision real: an overlapping opponent crashed (" as *u8); gn(crashed); gw("), distant ones are safe (" as *u8); gn(safe); gw(")\n" as *u8)
37
38 // ---- render a mid-race frame ----
39 init_impl(base)
40 var a: i64=0; while a < 40 { tick_impl(base, 0); a=a+1 } // traffic descends into view
41 render_impl(base)
42 let fb: *i64 = (base + O_FB) as *i64
43 write_png(fb, W, H, "knowledge/nx_wasm_racing_native.png" as *u8)
44 gw(" (live evidence: PNG knowledge/nx_wasm_racing_native.png -- road + lane dashes + player + traffic)\n" as *u8)
45
46 // ---- T2/T5/T6: render real -- BOTH CARS ARE ACTUALLY IN THE PICTURE ----
47 // ★THE OLD TOOTH WAS HALF VACUOUS AND COMPOUND, so it could not say which half failed. It asked
48 // for "player greener than red" and "opponent redder than green" in ONE boolean. The road is
49 // rgb(38,40,46), whose g=40 EXCEEDS r=38 -- so the player conjunct passed on BARE ROAD and would
50 // have kept passing with the player car draw deleted. (The opponent conjunct was genuine.)
51 // Found 2026-08-14 by nx_vacuity_census, same class as nx_wasm_shmup_gate and the one that let
52 // nx_wasm_craft_gate ship a world with no characters under 58 green teeth.
53 // Both are now DIFFERENCES against the road, naming no colour, each its own counted tooth.
54 let player: i64 = fb[SY*W + st[0]]
55 let opp: i64 = fb[oy[0]*W + ox[0]]
56 // ⚠SAMPLED BELOW THE HUD AND INSIDE THE ROAD. y=4 landed on the HUD banner -- rgb(185,190,199),
57 // not road -- and T6 caught it on the first run rather than letting T2 and T5 quietly compare
58 // against HUD pixels. x is kept just right of the left edge stripe (x 8..12) and far from the
59 // centre lane dashes (x W/2 +/- 2), so both samples are bare road.
60 let road1: i64 = fb[(H/2)*W + 14]
61 let road2: i64 = fb[(H/2)*W + 16]
62 total=total+1; if player != road1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
63 gw("T2 render real: the PLAYER car is in frame -- its cell differs from the road (player=" as *u8); gn(player); gw(" road=" as *u8); gn(road1); gw(")\n" as *u8)
64
65 total=total+1; if opp != road1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
66 gw("T5 render real: the OPPONENT car is in frame -- its cell differs from the road (opp=" as *u8); gn(opp); gw(" road=" as *u8); gn(road1); gw(")\n" as *u8)
67
68 // neg-control: the two road samples must AGREE, or the teeth above could be passing on ordinary
69 // background variation. A car or lane dash landing on a sample point makes this FAIL LOUDLY
70 // rather than quietly weakening them.
71 total=total+1; if road1 == road2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
72 gw("T6 neg-control-background-uniform: two road samples agree (" as *u8); gn(road1); gw(" vs " as *u8); gn(road2); gw(")\n" as *u8)
73
74 // ---- T3: game-over + restart ----
75 init_impl(base)
76 ox[0] = st[0]; oy[0] = SY; tick_impl(base, 0) // crash
77 let over: i64 = st[2]
78 tick_impl(base, 4) // restart
79 var t3ok: i64=1; if over != 1 {t3ok=0} if st[2] != 0 {t3ok=0}
80 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
81 gw("T3 game-over+restart: a crash ended the run (over=" as *u8); gn(over); gw("), restart reset it (gameover now=" as *u8); gn(st[2]); gw(")\n" as *u8)
82
83 // ---- T4: determinism ----
84 init_impl(base)
85 var b2: i64=0; while b2 < 40 { tick_impl(base, 0); b2=b2+1 }
86 let dist2: i64 = st[1]
87 total=total+1; if dist2 == 40 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
88 gw("T4 never-brick (#26): deterministic re-run (distance=" as *u8); gn(dist2); gw("), base-relative, no float, no sys_mmap in the core\n" as *u8)
89
90 gw("\n=== nx_wasm_racing_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
91 // D001 ANCHOR: the rich line above stays as this gate's public signature; the canonical verdict
92 // goes LAST because the estate's judge anchors by POSITION, taking only the final line.
93 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
94 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
95 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
96 let ctr__dry: *i64 = gv_ctr()
97 ctr__dry[0] = pass
98 ctr__dry[1] = total
99 let rc__dry: i64 = gv_verdict("WASM-RACING-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
100 sys_exit(rc__dry)
101 return rc__dry
102}