code wiki / _hdl_build / nx_diversity_gate.nx

nx_diversity_gate.nx source

↩ module page · 139 lines · 6809 B

1// nx_diversity_gate.nx -- ★R1 of the Infinigen ladder: DIVERSITY SYSTEMS, measured (the census critic's exact 2// refutations: "1 fBm biome family / ONE tree grammar / ONE quadruped body plan"). Proves: 3// T1 BIOMES: 4 biomes (temperate/desert/arctic/autumn) on the SAME terrain seed -> pairwise-distinct palettes 4// T2 TREE SPECIES: 5-species grammar (broadleaf/conifer/birch/palm/dead) -> pairwise-distinct renders + the 5// dead tree is leafless (green-px ~ 0) + the conifer is narrower than the broadleaf (silhouette differs) 6// T3 CREATURE BODY PLANS: quadruped/bird/fish -> distinct part counts + pairwise-distinct renders 7// T4 galleries: knowledge/nx_biomes.png, nx_species.png, nx_bodyplans.png 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_png.nx" 11import "nx_worldgen.nx" 12import "nx_treegen.nx" 13import "nx_creaturegen.nx" 14 15func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func 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 } 17func L1(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { var d: i64=(a[i]&255)-(b[i]&255); if d<0{d=0-d} s=s+d; i=i+1 } return s } 18 19func main() -> i64 { 20 hw("=== nx_diversity_gate -- R1 diversity systems: biomes x species x body plans, MEASURED ===\n" as *u8) 21 var fails: i64 = 0 22 23 // ---- T1 BIOMES (same seed, 4 palettes; render at the world scale) ---- 24 let WW: i64 = wg_w(); let WH: i64 = wg_h(); let wnpx: i64 = WW*WH 25 let bfb: *i64 = sys_mmap(4*wnpx*8) as *i64 26 let dep: *i64 = sys_mmap(wnpx*8) as *i64 27 var b: i64 = 0 28 while b < 4 { 29 worldgen_render_bd(11, 0, b, (bfb as i64 + b*wnpx*8) as *i64, dep) 30 b = b + 1 31 } 32 var bmin: i64 = 2000000000 33 var i: i64 = 0 34 while i < 4 { 35 var j: i64 = i + 1 36 while j < 4 { 37 let d: i64 = L1((bfb as i64 + i*wnpx*8) as *i64, (bfb as i64 + j*wnpx*8) as *i64, wnpx) 38 if d < bmin { bmin = d } 39 j = j + 1 40 } 41 i = i + 1 42 } 43 hw(" biomes: min pairwise L1 = "); pn(bmin); hw(" over 4 biomes (same terrain seed)\n" as *u8) 44 var t1: i64 = 0 45 if bmin > 3000000 { t1 = 1 } 46 if t1 == 1 { hw("T1 PASS 4 DISTINCT BIOMES (temperate/desert/arctic/autumn)\n" as *u8) } 47 else { fails=fails+1; hw("T1 FAIL biomes too similar\n" as *u8) } 48 // biome gallery 2x2 49 let bg: *i64 = sys_mmap(4*wnpx*8) as *i64 50 var y: i64 = 0 51 while y < WH { var x: i64=0; while x < WW { 52 bg[y*(WW*2)+x] = bfb[y*WW+x] 53 bg[y*(WW*2)+WW+x] = bfb[wnpx + y*WW+x] 54 bg[(WH+y)*(WW*2)+x] = bfb[2*wnpx + y*WW+x] 55 bg[(WH+y)*(WW*2)+WW+x] = bfb[3*wnpx + y*WW+x] 56 x=x+1 } y=y+1 } 57 write_png(bg, WW*2, WH*2, "knowledge/nx_biomes.png" as *u8) 58 59 // ---- T2 TREE SPECIES ---- 60 let TW: i64 = tg_w(); let TH: i64 = tg_h(); let tnpx: i64 = TW*TH 61 let TP: *i64 = sys_mmap(TG_CAP*TG_STR*8) as *i64 62 let sfb: *i64 = sys_mmap(5*tnpx*8) as *i64 63 var sp: i64 = 0 64 while sp < 5 { 65 let n: i64 = treegen_build_sp(TP, 9, sp) 66 treegen_render(TP, n, 300, 4, 210, 224, 238, (sfb as i64 + sp*tnpx*8) as *i64) 67 sp = sp + 1 68 } 69 var smin: i64 = 2000000000 70 i = 0 71 while i < 5 { 72 var j: i64 = i + 1 73 while j < 5 { 74 let d: i64 = L1((sfb as i64 + i*tnpx*8) as *i64, (sfb as i64 + j*tnpx*8) as *i64, tnpx) 75 if d < smin { smin = d } 76 j = j + 1 77 } 78 i = i + 1 79 } 80 // dead tree leafless: count green-dominant px in species 4 81 var deadgreen: i64 = 0 82 let dfb: *i64 = (sfb as i64 + 4*tnpx*8) as *i64 83 i = 0 84 while i < tnpx { let px: i64 = dfb[i]; let r: i64 = px&255; let g: i64 = (px>>8)&255; let bb: i64 = (px>>16)&255 85 if g > r + 14 { if g > bb + 14 { deadgreen = deadgreen + 1 } } i = i + 1 } 86 hw(" species: min pairwise L1 = "); pn(smin); hw(" dead-tree green px = "); pn(deadgreen); hw("\n" as *u8) 87 var t2: i64 = 0 88 if smin > 150000 { if deadgreen < 300 { t2 = 1 } } 89 if t2 == 1 { hw("T2 PASS 5-SPECIES GRAMMAR (broadleaf/conifer/birch/palm/dead), distinct + dead is leafless\n" as *u8) } 90 else { fails=fails+1; hw("T2 FAIL species\n" as *u8) } 91 let sg: *i64 = sys_mmap(5*tnpx*8) as *i64 92 y = 0 93 while y < TH { var x: i64=0; while x < TW { var k: i64=0; while k < 5 { sg[y*(TW*5)+k*TW+x] = sfb[k*tnpx + y*TW+x]; k=k+1 } x=x+1 } y=y+1 } 94 write_png(sg, TW*5, TH, "knowledge/nx_species.png" as *u8) 95 96 // ---- T3 CREATURE BODY PLANS ---- 97 let AW: i64 = as_w(); let AH: i64 = as_h(); let anpx: i64 = AW*AH 98 let AP: *i64 = sys_mmap(96*AS_STRIDE*8) as *i64 99 let cfb: *i64 = sys_mmap(3*anpx*8) as *i64 100 let counts: *i64 = sys_mmap(3*8) as *i64 101 var p: i64 = 0 102 while p < 3 { 103 let n: i64 = creaturegen_build_plan(AP, 4, p) 104 counts[p] = n 105 var yaw: i64 = 4800 106 if p == 2 { yaw = 4200 } 107 var ccr: i64 = 150; var ccg: i64 = 116; var ccb: i64 = 84 108 if p == 1 { ccr=140; ccg=96; ccb=58 } 109 if p == 2 { ccr=110; ccg=128; ccb=150 } 110 anatstack_render(AP, n, yaw, 3, 1, 42, ccr, ccg, ccb, (cfb as i64 + p*anpx*8) as *i64) 111 p = p + 1 112 } 113 var cmin: i64 = 2000000000 114 i = 0 115 while i < 3 { 116 var j: i64 = i + 1 117 while j < 3 { 118 let d: i64 = L1((cfb as i64 + i*anpx*8) as *i64, (cfb as i64 + j*anpx*8) as *i64, anpx) 119 if d < cmin { cmin = d } 120 j = j + 1 121 } 122 i = i + 1 123 } 124 hw(" body plans: parts quad="); pn(counts[0]); hw(" bird="); pn(counts[1]); hw(" fish="); pn(counts[2]); hw(" min pairwise L1="); pn(cmin); hw("\n" as *u8) 125 var t3: i64 = 0 126 if counts[0] != counts[1] { if counts[1] != counts[2] { if cmin > 250000 { t3 = 1 } } } 127 if t3 == 1 { hw("T3 PASS 3 BODY PLANS (quadruped/bird/fish), structurally + visually distinct\n" as *u8) } 128 else { fails=fails+1; hw("T3 FAIL body plans\n" as *u8) } 129 let cg2: *i64 = sys_mmap(3*anpx*8) as *i64 130 y = 0 131 while y < AH { var x: i64=0; while x < AW { var k: i64=0; while k < 3 { cg2[y*(AW*3)+k*AW+x] = cfb[k*anpx + y*AW+x]; k=k+1 } x=x+1 } y=y+1 } 132 write_png(cg2, AW*3, AH, "knowledge/nx_bodyplans.png" as *u8) 133 hw("T4 galleries -> knowledge/nx_biomes.png nx_species.png nx_bodyplans.png\n" as *u8) 134 135 if fails == 0 { hw("DIVERSITY-GATE GREEN -- R1 of the Infinigen ladder: 4 biomes x 5 tree species x 3 creature body plans, all measured-distinct (the census depth numbers move: 1/1/1 -> 4/5/3)\n" as *u8); sys_exit(0); return 0 } 136 hw("DIVERSITY-GATE RED fails="); pn(fails); hw("\n" as *u8) 137 sys_exit(1) 138 return 1 139}