code wiki / _hdl_build / nx_procgen_gate.nx
nx_procgen_gate.nx source
↩ module page · 59 lines · 3421 B
1// nx_procgen_gate.nx -- proves procedural maze generation (GR-S-R5 RESEARCHED->PRESENT) AND composes it with the
2// just-built A* (nx_pathfind). (1) DETERMINISTIC: same seed -> byte-identical maze; (2) FULLY CONNECTED: BFS flood
3// from (1,1) reaches EVERY open cell (perfect-maze property -- no isolated regions); (3) TRAVERSABLE (composition):
4// A* finds a path from (1,1) to the far corner; (4) GENERATES (not clone): a different seed -> a different maze.
5// Pure-Nishi no-float. license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_procgen.nx"
8import "nx_pathfind.nx"
9
10const MW: i64 = 15
11const MH: i64 = 15
12
13func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
15func row(id: *u8, ok: i64, pass: *i64) -> i64 { w(" " as *u8); w(id); w(": " as *u8); if ok==1 { w("OK\n" as *u8); pass[0]=pass[0]+1 } else { w("FAIL\n" as *u8) } return 0 }
16
17func main() -> i64 {
18 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
19 w("=== NX-PROCGEN GATE (maze gen + A* composition, pure-Nishi no-float) ===\n" as *u8)
20 let n: i64 = MW*MH
21 let a: *i64 = sys_mmap(n*8) as *i64
22 let b: *i64 = sys_mmap(n*8) as *i64
23 let c: *i64 = sys_mmap(n*8) as *i64
24 let stack: *i64 = sys_mmap(n*8) as *i64
25 let visited: *i64 = sys_mmap(n*8) as *i64
26 let queue: *i64 = sys_mmap(n*8) as *i64
27
28 pg_maze(a, MW, MH, 12345, stack)
29 pg_maze(b, MW, MH, 12345, stack) // same seed
30 pg_maze(c, MW, MH, 99999, stack) // different seed
31
32 // (1) determinism
33 var det: i64 = 1; var i: i64 = 0; while i < n { if a[i]!=b[i] { det=0 } i=i+1 }
34 row("DETERMINISTIC: same seed -> byte-identical maze\x00" as *u8, det, pass)
35
36 // (2) full connectivity (perfect maze): flood from (1,1) reaches every open cell
37 let open_a: i64 = pg_count_open(a, n)
38 let reach_a: i64 = pg_flood_count(a, MW, MH, 1, 1, visited, queue)
39 w(" maze A: open cells="); wn(open_a); w(" reachable from (1,1)="); wn(reach_a); w("\n")
40 row("FULLY CONNECTED: flood reaches EVERY open cell (no isolated regions)\x00" as *u8, ((open_a>0) as i64) & ((reach_a==open_a) as i64), pass)
41
42 // (3) traversable via A* (composition with nx_pathfind) -- path from (1,1) to far open corner
43 let g: *i64 = sys_mmap(n*8) as *i64
44 let f: *i64 = sys_mmap(n*8) as *i64
45 let came: *i64 = sys_mmap(n*8) as *i64
46 let openf: *i64 = sys_mmap(n*8) as *i64
47 let closed: *i64 = sys_mmap(n*8) as *i64
48 let plen: i64 = pf_astar(a, MW, MH, 1,1, MW-2, MH-2, g,f,came,openf,closed, 0 as *i64)
49 w(" A* (1,1)->("); wn(MW-2); w(","); wn(MH-2); w("): path len="); wn(plen); w("\n")
50 row("TRAVERSABLE: A* finds a path corner-to-corner on the generated maze (composition)\x00" as *u8, (plen>0) as i64, pass)
51
52 // (4) generation: different seed -> different maze
53 var diff: i64 = 0; i=0; while i < n { if a[i]!=c[i] { diff=1 } i=i+1 }
54 row("GENERATES: a different seed yields a different maze (not a clone)\x00" as *u8, diff, pass)
55
56 w("PROCGEN rows=4 pass="); wn(pass[0])
57 if pass[0]==4 { w(" verdict=GREEN\n"); sys_exit(0); return 0 }
58 w(" verdict=RED\n"); sys_exit(1); return 1
59}