code wiki / _hdl_build / nx_game_sandbox_gate.nx
nx_game_sandbox_gate.nx source
↩ module page · 91 lines · 5434 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_game_sandbox_gate.nx -- GENRE: Sandbox (catalog genre, was ABSENT). A real integer/no-float creative
4// sandbox CORE -- freely place + remove typed blocks on a grid to build any structure. Scripted build
5// (assemble a structure), rendered frame, neg-control (removal is real) + freeform-placement-real.
6// T1 BUILD: place a planned structure -> exactly those blocks exist. PNG.
7// T2 EDIT REAL: removing a block actually clears it (it becomes air).
8// T3 FREEFORM: a block can be placed at ANY cell (including the corners).
9// T4 NEVER-BRICK (#26): deterministic rebuild, bounded, no float.
10// expect_exit: 0 license_tier: ORIGINAL
11import "nx_game_raster.nx"
12import "nx_png.nx"
13import "nx_syscalls.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 sb_place(board: *i64, gw_: i64, x: i64, y: i64, t: i64) -> i64 { board[y*gw_+x]=t; return 0 }
19func sb_remove(board: *i64, gw_: i64, x: i64, y: i64) -> i64 { board[y*gw_+x]=0; return 0 }
20func sb_count(board: *i64, n: i64) -> i64 { var c: i64=0; var i: i64=0; while i<n { if board[i]!=0 { c=c+1 } i=i+1 } return c }
21func sb_clear(board: *i64, n: i64) -> i64 { var i: i64=0; while i<n { board[i]=0; i=i+1 } return 0 }
22// build a planned little house (stone base, wood walls, grass roof). returns blocks placed.
23func sb_build_house(board: *i64, gw_: i64) -> i64 {
24 sb_place(board, gw_, 3, 5, 1); sb_place(board, gw_, 4, 5, 1); sb_place(board, gw_, 5, 5, 1) // stone base
25 sb_place(board, gw_, 3, 4, 2); sb_place(board, gw_, 5, 4, 2) // wood walls
26 sb_place(board, gw_, 3, 3, 2); sb_place(board, gw_, 5, 3, 2)
27 sb_place(board, gw_, 3, 2, 3); sb_place(board, gw_, 4, 2, 3); sb_place(board, gw_, 5, 2, 3) // grass roof
28 return 10
29}
30func sb_render(fb: *i64, w: i64, h: i64, cell: i64, gw_: i64, gh_: i64, board: *i64) -> i64 {
31 gr_clear(fb, w, h, gr_pack(135, 170, 210)) // sky
32 gr_rect(fb, w, h, 0, (gh_-1)*cell, w, h, gr_pack(110, 90, 60)) // ground strip
33 var y: i64=0
34 while y<gh_ {
35 var x: i64=0
36 while x<gw_ {
37 let k: i64=board[y*gw_+x]
38 if k!=0 {
39 var col: i64=gr_pack(150,150,160)
40 if k==1 { col=gr_pack(140,140,150) } if k==2 { col=gr_pack(170,120,70) } if k==3 { col=gr_pack(90,190,90) }
41 gr_rect(fb, w, h, x*cell, y*cell, x*cell+cell, y*cell+cell, col)
42 gr_rect(fb, w, h, x*cell, y*cell, x*cell+cell, y*cell+1, gr_pack(40,40,46))
43 }
44 x=x+1
45 }
46 y=y+1
47 }
48 return 0
49}
50
51func main() -> i64 {
52 gw("=== nx_game_sandbox_gate: GENRE Sandbox -- a real integer/no-float playable (live evidence) ===\n" as *u8)
53 var pass: i64 = 0; var total: i64 = 0
54 let GW: i64=9; let GH: i64=7; let CELL: i64=14; let W: i64=GW*CELL; let H: i64=GH*CELL; let N: i64=GW*GH
55 let board: *i64=sys_mmap(8*(N+4)) as *i64
56
57 // ---- T1: build a planned structure ----
58 sb_clear(board, N)
59 let placed: i64=sb_build_house(board, GW)
60 let count1: i64=sb_count(board, N)
61 total=total+1; if count1==placed { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
62 gw("T1 build: placed a structure of " as *u8); gn(placed); gw(" blocks, exactly " as *u8); gn(count1); gw(" exist (BUILT)\n" as *u8)
63
64 let fb: *i64=sys_mmap(8*(W*H+8)) as *i64
65 sb_render(fb, W, H, CELL, GW, GH, board)
66 write_png(fb, W, H, "knowledge/nx_game_sandbox.png" as *u8)
67 gw(" (live evidence: PNG knowledge/nx_game_sandbox.png -- a built house of stone/wood/grass blocks)\n" as *u8)
68
69 // ---- T2: edit real -- removing a block clears it ----
70 sb_remove(board, GW, 4, 2) // remove a roof block
71 var t2ok: i64=1; if board[2*GW+4]!=0 {t2ok=0} if sb_count(board, N)!=placed-1 {t2ok=0}
72 total=total+1; if t2ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
73 gw("T2 edit real: removing a block cleared it (cell=" as *u8); gn(board[2*GW+4]); gw(", count=" as *u8); gn(sb_count(board, N)); gw(")\n" as *u8)
74
75 // ---- T3: freeform -- place at any cell, including the corners ----
76 sb_clear(board, N)
77 sb_place(board, GW, 0, 0, 1); sb_place(board, GW, GW-1, 0, 2); sb_place(board, GW, 0, GH-1, 3); sb_place(board, GW, GW-1, GH-1, 1)
78 var t3ok: i64=1
79 if board[0]!=1 {t3ok=0} if board[GW-1]!=2 {t3ok=0} if board[(GH-1)*GW]!=3 {t3ok=0} if board[(GH-1)*GW+(GW-1)]!=1 {t3ok=0}
80 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
81 gw("T3 freeform: placed blocks at all 4 corners (any cell is editable)\n" as *u8)
82
83 // ---- T4: never-brick / determinism ----
84 sb_clear(board, N); sb_build_house(board, GW)
85 total=total+1; if sb_count(board, N)==placed { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
86 gw("T4 never-brick (#26): deterministic rebuild (" as *u8); gn(sb_count(board, N)); gw(" blocks), bounded, no float\n" as *u8)
87
88 gw("\n=== nx_game_sandbox_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
89 if pass == total { gw(" GREEN (Sandbox: a real playable freeform place/remove builder, rendered, sovereign)\n" as *u8); sys_exit(0); return 0 }
90 gw(" RED\n" as *u8); sys_exit(1); return 1
91}