code wiki / _hdl_build / nx_authorgame_gate.nx

nx_authorgame_gate.nx source

↩ module page · 110 lines · 6653 B

1// nx_authorgame_gate.nx -- ★AUTHORING, CONTENT TYPE 3: describe a GAME -> a real PLAYABLE BROWSER GAME (the closest 2// Orca analog: "describe a mod, get it built"). Integration, not new code: the NL front-end (nx_authorgen) maps the 3// description to difficulty params, and the EXISTING emitter (nx_game_web_emit.emit_arcade) writes the playable 4// canvas+JS game. T1 "an easy collect game" -> emitted HTML has the easy params + is playable-shaped. T2 "a hard 5// arcade game" -> harder params (causal). T3 the artifact is a REAL game (canvas + keydown + win logic), not a stub. 6// T4 refusal. T5 determinism. T6 showcase game for live deploy. license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_authorgen.nx" 9import "nx_game_web_emit.nx" 10 11func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 } 13func gslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 14func has(buf: *u8, n: i64, needle: *u8) -> i64 { 15 let m: i64 = gslen(needle) 16 if m == 0 { return 0 } 17 var i: i64 = 0 18 while i + m <= n { 19 var k: i64 = 0 20 while k < m { if buf[i+k] != needle[k] { k = m + 9 } else { k = k + 1 } } 21 if k == m { return 1 } 22 i = i + 1 23 } 24 return 0 25} 26// parse a game description and emit the playable game. returns the emitted file size (0 = not a game / refused). 27func author_game(text: *u8, path: *u8) -> i64 { 28 ag_parse(text) 29 if ag_kind() != 3 { return 0 } 30 emit_arcade(path, "THE NISHI GAME" as *u8, ag_game_gw(), ag_game_gh(), ag_game_ng(), ag_game_nh(), ag_game_seed()) 31 let szp: *i64 = sys_mmap(16) as *i64 32 let b: *u8 = sys_read_file(path, szp) 33 if (b as i64) == 0 { return 0 } 34 return szp[0] 35} 36 37func main() -> i64 { 38 hw("=== nx_authorgame_gate -- describe a GAME -> a real playable browser game (the Orca core) ===\n" as *u8) 39 var fails: i64 = 0 40 let szp: *i64 = sys_mmap(16) as *i64 41 42 // ---- T1 "an easy collect game" ---- 43 let sz1: i64 = author_game("an easy collect game" as *u8, "knowledge/_ag_easy.html" as *u8) 44 let e: *u8 = sys_read_file("knowledge/_ag_easy.html" as *u8, szp) 45 let en: i64 = szp[0] 46 let easyNG: i64 = has(e, en, "NG=4" as *u8) 47 let easyNH: i64 = has(e, en, "NH=2" as *u8) 48 let hasCanvas: i64 = has(e, en, "getElementById('c')" as *u8) 49 hw(" 'an easy collect game' -> kind="); pn(ag_kind()); hw(" bytes="); pn(sz1); hw(" NG=4?"); pn(easyNG); hw(" NH=2?"); pn(easyNH); hw(" canvas?"); pn(hasCanvas); hw("\n" as *u8) 50 var t1: i64 = 0 51 if ag_kind() == 3 { if sz1 > 600 { if easyNG == 1 { if hasCanvas == 1 { t1 = 1 } } } } 52 if t1 == 1 { hw("T1 PASS an EASY playable game was emitted with the easy params + a canvas\n" as *u8) } 53 else { fails=fails+1; hw("T1 FAIL\n" as *u8) } 54 55 // ---- T2 "a hard arcade game" -- causal difficulty ---- 56 author_game("a hard arcade game" as *u8, "knowledge/_ag_hard.html" as *u8) 57 let hbuf: *u8 = sys_read_file("knowledge/_ag_hard.html" as *u8, szp) 58 let hn: i64 = szp[0] 59 let hardNG: i64 = has(hbuf, hn, "NG=10" as *u8) 60 let hardNH: i64 = has(hbuf, hn, "NH=9" as *u8) 61 hw(" 'a hard arcade game' -> NG=10?"); pn(hardNG); hw(" NH=9?"); pn(hardNH); hw(" (easy was NH=2)\n" as *u8) 62 var t2: i64 = 0 63 if hardNG == 1 { if hardNH == 1 { if easyNH == 1 { t2 = 1 } } } 64 if t2 == 1 { hw("T2 PASS a HARD game has MORE goals + hazards than the easy one (difficulty causally drives the emit)\n" as *u8) } 65 else { fails=fails+1; hw("T2 FAIL\n" as *u8) } 66 67 // ---- T3 it is a REAL game (playable logic), not a stub ---- 68 let kd: i64 = has(hbuf, hn, "keydown" as *u8) 69 let stp: i64 = has(hbuf, hn, "function step" as *u8) 70 let win: i64 = has(hbuf, hn, "YOU WIN" as *u8) 71 let rng: i64 = has(hbuf, hn, "function rnd" as *u8) 72 hw(" playable logic: keydown?"); pn(kd); hw(" step?"); pn(stp); hw(" win?"); pn(win); hw(" rng?"); pn(rng); hw("\n" as *u8) 73 var t3: i64 = 0 74 if kd == 1 { if stp == 1 { if win == 1 { if rng == 1 { t3 = 1 } } } } 75 if t3 == 1 { hw("T3 PASS the artifact is a REAL playable game (input handling + movement + win/lose + PRNG), not a stub\n" as *u8) } 76 else { fails=fails+1; hw("T3 FAIL\n" as *u8) } 77 78 // ---- T4 refusal ---- 79 let sz4: i64 = author_game("a sad poem about rain" as *u8, "knowledge/_ag_no.html" as *u8) 80 hw(" 'a sad poem about rain' -> kind="); pn(ag_kind()); hw(" emit="); pn(sz4); hw("\n" as *u8) 81 var t4: i64 = 0 82 if ag_kind() == 0 { if sz4 == 0 { t4 = 1 } } 83 if t4 == 1 { hw("T4 PASS a non-game request is REFUSED (no fake game emitted)\n" as *u8) } 84 else { fails=fails+1; hw("T4 FAIL\n" as *u8) } 85 86 // ---- T5 determinism ---- 87 author_game("an easy collect game" as *u8, "knowledge/_ag_d1.html" as *u8) 88 let d1: *u8 = sys_read_file("knowledge/_ag_d1.html" as *u8, szp) 89 let d1n: i64 = szp[0] 90 author_game("an easy collect game" as *u8, "knowledge/_ag_d2.html" as *u8) 91 let d2: *u8 = sys_read_file("knowledge/_ag_d2.html" as *u8, szp) 92 let d2n: i64 = szp[0] 93 var same: i64 = 0 94 if d1n == d2n { same = 1; var i: i64 = 0; while i < d1n { if d1[i] != d2[i] { same = 0; i = d1n } i = i + 1 } } 95 var t5: i64 = 0 96 if same == 1 { t5 = 1 } 97 if t5 == 1 { hw("T5 PASS deterministic (same description -> byte-identical game)\n" as *u8) } else { fails=fails+1; hw("T5 FAIL\n" as *u8) } 98 99 // ---- T6 showcase for live deploy ---- 100 let szS: i64 = author_game("a hard arcade dungeon game" as *u8, "knowledge/nx_authorgame.html" as *u8) 101 hw(" showcase 'a hard arcade dungeon game' -> knowledge/nx_authorgame.html ("); pn(szS); hw(" bytes)\n" as *u8) 102 var t6: i64 = 0 103 if szS > 900 { t6 = 1 } 104 if t6 == 1 { hw("T6 PASS showcase game emitted for live deploy\n" as *u8) } else { fails=fails+1; hw("T6 FAIL\n" as *u8) } 105 106 if fails == 0 { hw("AUTHORGAME-GATE GREEN -- content type 3: describe a GAME -> the EXISTING emitter (nx_game_web_emit) produces a real playable browser game with difficulty-scaled params, causally + deterministically; non-games refused. This is INTEGRATION (wired the NL front-end to a shipped organ), the Orca core. Residual: genre breadth (puzzle/tower-defence via nx_game_gen registry), free-NL, edit-existing (nx_game_edit).\n" as *u8); sys_exit(0); return 0 } 107 hw("AUTHORGAME-GATE RED fails="); pn(fails); hw("\n" as *u8) 108 sys_exit(1) 109 return 1 110}