code wiki / _hdl_build / nx_game_web_emit_gate.nx
nx_game_web_emit_gate.nx source
↩ module page · 71 lines · 3320 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_game_web_emit_gate.nx -- proves the mechanistic browser emitter generates DISTINCT playable games
4// from DISTINCT specs (autonomous generation, not a hand-clone). Emits two arcade specs, reads them back,
5// asserts each is a valid playable (canvas + input + win-logic) carrying its own spec, and that the two
6// differ. license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_game_web_emit.nx"
9
10func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
11" as *u8); return ok }
12
13func contains(buf: *u8, n: i64, ndl: *u8) -> i64 {
14 var m: i64=0; while ndl[m]!=(0 as u8){m=m+1}
15 if m==0 { return 0 }
16 var i: i64=0
17 while i + m <= n {
18 var j: i64=0; var ok: i64=1
19 while j<m { if buf[i+j]!=ndl[j] { ok=0; j=m } else { j=j+1 } }
20 if ok==1 { return 1 }
21 i=i+1
22 }
23 return 0
24}
25
26func has(buf: *u8, n: i64, ndl: *u8, tot: *i64, label: *u8) -> i64 {
27 tot[1] = tot[1] + 1
28 if contains(buf, n, ndl) == 1 { tot[0] = tot[0] + 1; return 1 }
29 gw(" MISS: "); gw(label); gw("\n"); return 0
30}
31
32func main() -> i64 {
33 emit_arcade("knowledge/nx_arcade_a.html" as *u8, "Coin Dash" as *u8, 10, 10, 5, 3, 7)
34 emit_arcade("knowledge/nx_arcade_b.html" as *u8, "Gem Hunt" as *u8, 14, 8, 8, 5, 42)
35
36 let la: *i64 = sys_mmap(8) as *i64
37 let lb: *i64 = sys_mmap(8) as *i64
38 let a: *u8 = sys_read_file("knowledge/nx_arcade_a.html" as *u8, la)
39 let b: *u8 = sys_read_file("knowledge/nx_arcade_b.html" as *u8, lb)
40 let tot: *i64 = sys_mmap(16) as *i64
41 tot[0]=0; tot[1]=0
42
43 if a == (0 as *u8) { gw("EMIT-FAIL A\n"); return 1 }
44 if b == (0 as *u8) { gw("EMIT-FAIL B\n"); return 1 }
45
46 // both are valid playables (front-end canvas + input + win logic = back-end rules)
47 has(a, la[0], "<canvas" as *u8, tot, "A canvas")
48 has(a, la[0], "getContext" as *u8, tot, "A render ctx")
49 has(a, la[0], "keydown" as *u8, tot, "A input")
50 has(a, la[0], "won=1" as *u8, tot, "A win-rule")
51 has(b, lb[0], "<canvas" as *u8, tot, "B canvas")
52 has(b, lb[0], "keydown" as *u8, tot, "B input")
53 has(b, lb[0], "won=1" as *u8, tot, "B win-rule")
54 // spec-driven distinctness: each carries its own spec/title
55 has(a, la[0], "Coin Dash" as *u8, tot, "A title")
56 has(a, la[0], "GW=10" as *u8, tot, "A spec gw=10")
57 has(b, lb[0], "Gem Hunt" as *u8, tot, "B title")
58 has(b, lb[0], "GW=14" as *u8, tot, "B spec gw=14")
59 // NEG/distinctness: A must NOT carry B's spec (proves not a static clone)
60 tot[1]=tot[1]+1; if contains(a, la[0], "GW=14" as *u8)==0 { tot[0]=tot[0]+1 } else { gw(" MISS: A leaked B spec\n") }
61 // different sizes = genuinely different artifacts
62 tot[1]=tot[1]+1; if la[0] != lb[0] { tot[0]=tot[0]+1 } else { gw(" MISS: A,B same size\n") }
63
64 gw("=== nx_game_web_emit: 2 specs -> 2 playable browser games ===\n")
65 gw(" A 'Coin Dash' 10x10/5g/3h bytes="); gn(la[0]); gw("\n")
66 gw(" B 'Gem Hunt' 14x8/8g/5h bytes="); gn(lb[0]); gw("\n")
67 gw("WEB-EMIT "); gn(tot[0]); gw("/"); gn(tot[1]); gw("\n")
68 if tot[0] == tot[1] { gw("WEB-EMIT ALL-PASS (distinct specs -> distinct playable LLM-free browser games; autonomous generation)\n"); sys_exit(0) }
69 sys_exit(1)
70 return 1
71}