nx_world_quality_grader_gate.nx source
↩ module page · 263 lines · 15753 B
1// nx_world_quality_grader_gate.nx -- THE REFEREE FOR THE WORLD REFEREE, 2026-09-01.
2//
3// nx_world_quality_grader.nx shipped on 2026-05-16 and was NEVER BUILT: catalog read
4// SOURCE-ONLY (S2) for it and for every one of its five consumers (nx_procgen_biome_test,
5// nx_procgen_water_test, nx_procgen_features_test, nx_procgen_signature_test,
6// nx_layer_verdict). A grader that has never compiled has never graded anything, and the
7// estate law for that is a build-and-run deficit, not a cleverness deficit.
8//
9// IN-PROCESS over nx_world_quality_grader.nx, deliberately. A gate that fork/exec'd a
10// deployed elf would report NOT-REACHED for every mutant and its GREEN would prove nothing
11// about the code under test.
12//
13// WHAT THIS PROVES, STATED SO IT CANNOT BE OVER-READ: the 8-axis decision core -- the
14// degenerate-input contract, the flatness INVERSION, the banded local-variation verdict,
15// the optional-axis abstention, the biome and feature-variety rulers, the letter rubric and
16// the refine-axis enum. It does NOT prove that the axes correlate with a human judgement of
17// a world beauty; that is a referee-panel question and is not claimed here.
18//
19// THE SELF-TEST IN THE GRADER OWN main() IS NOT THIS GATE. It has no negative controls, no
20// denominators, and its exit code is a bare 0 -- nothing downstream can read a verdict from
21// it. Every tooth below that the self-test also covers is restated here so the verdict
22// travels in the EXIT CODE, and the ones it never had are the reason this file exists.
23//
24// FIXTURES ARE BUILT IN MEMORY ON EVERY RUN AND TOUCH NO PATH AT ALL, so the run is
25// idempotent by construction and can never share a fixture with a production beat.
26// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
27import "nx_gate_verdict.nx"
28import "nx_world_quality_grader.nx"
29
30const WG_W: i64 = 8 // the self-test own grid, so outcomes stay comparable
31const WG_H: i64 = 8
32const WG_RELIEF: i64 = 1000 // max_expected_relief handed to every grade below
33const WG_FLAT_VALUE: i64 = 100 // the constant a degenerate world is filled with
34const WG_MAPS_GRADED: i64 = 7 // DENOMINATOR: grades this run must actually perform
35const WG_PEAK: i64 = 1000 // mountain apex before the radial falloff
36const WG_FALLOFF: i64 = 50 // radial falloff per unit squared distance
37const WG_JITTER: i64 = 50 // checkerboard jitter amplitude on the mountain map
38const WG_CENTRE: i64 = 4 // WG_W/2: the mountain apex column
39const WG_BIOME_DESERT: i64 = 8 // expected band LOW
40const WG_BIOME_TFOREST: i64 = 5 // expected band MID
41const WG_BIOME_SNOW: i64 = 12 // expected band HIGH
42const WG_BIOME_ICE: i64 = 13 // expected band PEAK
43const WG_KINDS: i64 = 4 // feature-kind histogram width
44const WG_KIND_COUNT: i64 = 10 // per-kind count in the UNIFORM histogram
45const WG_KIND_ALL: i64 = 40 // WG_KINDS * WG_KIND_COUNT, all in one kind
46const WG_QUARTER: i64 = 4 // the grader own elevation-band divisor
47const WG_TWO: i64 = 2
48const WG_THREE: i64 = 3
49
50func wg_scan_min(m: *i64, n: i64) -> i64 {
51 var lo: i64 = m[0]
52 var i: i64 = 0
53 while i < n {
54 if m[i] < lo { lo = m[i] }
55 i = i + 1
56 }
57 return lo
58}
59
60func wg_scan_max(m: *i64, n: i64) -> i64 {
61 var hi: i64 = m[0]
62 var i: i64 = 0
63 while i < n {
64 if m[i] > hi { hi = m[i] }
65 i = i + 1
66 }
67 return hi
68}
69
70func main(argc: i64, argv: *i64) -> i64 {
71 gv_head("nx_world_quality_grader_gate -- the 8-axis world referee, in-process" as *u8)
72 let ctr: *i64 = gv_ctr()
73 gv_subjects("heightmaps graded" as *u8, WG_MAPS_GRADED, ctr)
74
75 let n: i64 = WG_W * WG_H
76 let v: *i64 = (sys_mmap(NX_WQG_OUT_STRIDE * NX_SIZEOF_NX_INT)) as *i64
77 let nullp: *i64 = 0 as *i64
78 var graded: i64 = 0
79
80 // ---- fixture 1: the DEGENERATE world -- perfectly constant -------------------------
81 let flat: *i64 = (sys_mmap(n * NX_SIZEOF_NX_INT)) as *i64
82 var i: i64 = 0
83 while i < n {
84 flat[i] = WG_FLAT_VALUE
85 i = i + 1
86 }
87
88 // ---- fixture 2: a scale-linear RAMP -- smooth, Hurst near 1 ------------------------
89 let ramp: *i64 = (sys_mmap(n * NX_SIZEOF_NX_INT)) as *i64
90 i = 0
91 while i < n {
92 ramp[i] = i * WG_RELIEF / n
93 i = i + 1
94 }
95
96 // ---- fixture 3: a MOUNTAIN -- radial relief with a checkerboard jitter -------------
97 let mtn: *i64 = (sys_mmap(n * NX_SIZEOF_NX_INT)) as *i64
98 var ry: i64 = 0
99 while ry < WG_H {
100 var rx: i64 = 0
101 while rx < WG_W {
102 let dx: i64 = rx - WG_CENTRE
103 let dy: i64 = ry - WG_CENTRE
104 var hv: i64 = WG_PEAK - (dx * dx + dy * dy) * WG_FALLOFF
105 if hv < 0 { hv = 0 }
106 if (rx + ry) % WG_TWO == 0 { hv = hv + WG_JITTER }
107 mtn[ry * WG_W + rx] = hv
108 rx = rx + 1
109 }
110 ry = ry + 1
111 }
112
113 // ASSERT THE FIXTURES REACHED THEIR CONDITIONS BEFORE ASSERTING ANY OUTCOME. Every
114 // tooth below is a claim about these three arrays; if construction silently failed each
115 // one would pass or fail for a reason that has nothing to do with the code under test.
116 let flat_lo: i64 = wg_scan_min(flat, n)
117 let flat_hi: i64 = wg_scan_max(flat, n)
118 let mtn_lo: i64 = wg_scan_min(mtn, n)
119 let mtn_hi: i64 = wg_scan_max(mtn, n)
120 let ramp_lo: i64 = wg_scan_min(ramp, n)
121 let ramp_hi: i64 = wg_scan_max(ramp, n)
122 gv_check("fixture-constant-map-really-has-zero-range" as *u8, flat_hi - flat_lo == 0, ctr)
123 gv_check("fixture-mountain-map-really-has-relief" as *u8, mtn_hi - mtn_lo > 0, ctr)
124 gv_check("fixture-ramp-really-has-relief" as *u8, ramp_hi - ramp_lo > 0, ctr)
125
126 // ===== THE DEGENERATE-INPUT CONTRACT ===============================================
127 // The two teeth marked LOAD-BEARING below both FAILED against the shipped source and are
128 // why this gate exists. With range == 0 the histogram loop was skipped entirely, so
129 // FLATNESS_PENALTY -- whose contract is HIGHER = MORE FLAT = WORSE -- read 0 and WON its
130 // axis for the flattest possible world; and top_t == bot_t == hmin meant every cell was
131 // counted as BOTH a peak and a trough, so EXTREMES saturated at Q for a world that has
132 // none. Two of eight axes scored the worst possible input as perfect.
133 nx_world_quality_grade(flat, WG_W, WG_H, WG_RELIEF, nullp, nullp, 0, v)
134 graded = graded + 1
135 let flat_grade: i64 = v[NX_WQG_OFF_GRADE]
136 let flat_flatness: i64 = v[NX_WQG_OFF_FLATNESS_PENALTY]
137 let flat_extremes: i64 = v[NX_WQG_OFF_EXTREMES]
138 gv_check("LOAD-BEARING-constant-map-scores-maximum-flatness-penalty" as *u8, flat_flatness == NX_WQG_Q, ctr)
139 gv_check("neg-control-constant-map-does-not-WIN-the-flatness-axis" as *u8, flat_flatness > NX_WQG_FLATNESS_BAD_CEIL, ctr)
140 gv_check("LOAD-BEARING-constant-map-has-no-extremes" as *u8, flat_extremes == 0, ctr)
141 gv_check("neg-control-constant-map-does-not-saturate-the-extremes-axis" as *u8, flat_extremes != NX_WQG_Q, ctr)
142 gv_check("constant-map-grades-F" as *u8, flat_grade == NX_GRADE_F, ctr)
143 gv_check("constant-map-scores-zero-diversity" as *u8, v[NX_WQG_OFF_DIVERSITY] == 0, ctr)
144 gv_check("constant-map-scores-zero-readability" as *u8, v[NX_WQG_OFF_READABILITY] == 0, ctr)
145 gv_check("constant-map-scores-zero-local-variation" as *u8, v[NX_WQG_OFF_LOCAL_VAR] == 0, ctr)
146 gv_check("constant-map-refine-directive-names-MORE-RELIEF" as *u8, v[NX_WQG_OFF_REFINE_AXIS] == NX_WQG_REFINE_MORE_RELIEF, ctr)
147 gv_check("constant-map-reports-the-min-height-an-independent-scan-found" as *u8, v[NX_WQG_OFF_MIN_HEIGHT] == flat_lo, ctr)
148
149 // ===== DISCRIMINATION: a grader that always answered F passes every tooth above =====
150 nx_world_quality_grade(mtn, WG_W, WG_H, WG_RELIEF, nullp, nullp, 0, v)
151 graded = graded + 1
152 let mtn_grade: i64 = v[NX_WQG_OFF_GRADE]
153 let mtn_flatness: i64 = v[NX_WQG_OFF_FLATNESS_PENALTY]
154 gv_check("neg-control-mountain-map-does-not-grade-F" as *u8, mtn_grade != NX_GRADE_F, ctr)
155 gv_check("mountain-map-outranks-the-constant-map" as *u8, mtn_grade > flat_grade, ctr)
156 gv_check("mountain-map-scores-nonzero-extremes" as *u8, v[NX_WQG_OFF_EXTREMES] > 0, ctr)
157 gv_check("flatness-penalty-is-INVERTED-a-varied-map-scores-lower-than-a-constant-one" as *u8, mtn_flatness < flat_flatness, ctr)
158 gv_check("mountain-map-reports-the-max-height-an-independent-scan-found" as *u8, v[NX_WQG_OFF_MAX_HEIGHT] == mtn_hi, ctr)
159 gv_check("mountain-map-refine-directive-is-a-valid-enum" as *u8, nx_wqg_refine_is_valid(v[NX_WQG_OFF_REFINE_AXIS]) == 1, ctr)
160 gv_check("mountain-map-grade-is-a-valid-enum" as *u8, nx_grade_is_valid(mtn_grade) == 1, ctr)
161
162 // ===== THE AESTHETIC BAND: more roughness is NOT monotonically better ===============
163 // A pure ramp is scale-linear, so mean-abs-diff at scale 4 over scale 1 lands near 4,
164 // Hurst near 1.0, and the Spehar aesthetic band puts that at the far edge, not the peak.
165 // A grader that simply rewarded relief would score the ramp highly here; it must not.
166 nx_world_quality_grade(ramp, WG_W, WG_H, WG_RELIEF, nullp, nullp, 0, v)
167 graded = graded + 1
168 gv_check("anti-vacuity-a-smooth-ramp-fails-the-fractal-aesthetic-band" as *u8, v[NX_WQG_OFF_FRACTAL_DIM] < NX_WQG_AXIS_MARGINAL_FLOOR, ctr)
169 gv_check("neg-control-the-ramp-still-WINS-the-diversity-axis-it-deserves" as *u8, v[NX_WQG_OFF_DIVERSITY] >= NX_WQG_AXIS_WIN_FLOOR, ctr)
170 gv_check("neg-control-one-high-axis-does-not-lift-another" as *u8, v[NX_WQG_OFF_FRACTAL_DIM] < v[NX_WQG_OFF_DIVERSITY], ctr)
171
172 // The banded verdict itself, exercised at all three of its outcomes. A verdict function
173 // that only ever answered WIN or LOSS would pass a one-sided test forever.
174 gv_check("banded-axis-a-saturated-score-is-NOT-a-WIN" as *u8, _wqg_axis_verdict_banded(NX_WQG_Q, NX_WQG_AXIS_WIN_FLOOR, NX_WQG_AXIS_MARGINAL_FLOOR, NX_WQG_LOCAL_VAR_UPPER) == 0, ctr)
175 gv_check("banded-axis-a-mid-band-score-IS-a-WIN" as *u8, _wqg_axis_verdict_banded(NX_WQG_AXIS_WIN_FLOOR, NX_WQG_AXIS_WIN_FLOOR, NX_WQG_AXIS_MARGINAL_FLOOR, NX_WQG_LOCAL_VAR_UPPER) == 1, ctr)
176 gv_check("banded-axis-a-below-marginal-score-is-a-LOSS" as *u8, _wqg_axis_verdict_banded(0, NX_WQG_AXIS_WIN_FLOOR, NX_WQG_AXIS_MARGINAL_FLOOR, NX_WQG_LOCAL_VAR_UPPER) == 0 - 1, ctr)
177
178 // ===== OPTIONAL AXES MUST ABSTAIN, NEVER ACQUIT =====================================
179 // biome_map and feature_hist are caller-supplied. When absent the grader must score them
180 // MARGINAL, so their absence can neither raise nor lower the verdict -- and in
181 // particular an absent axis must never be able to carry a world to S.
182 gv_check("absent-biome-map-scores-zero-rather-than-a-WIN" as *u8, v[NX_WQG_OFF_BIOME_COHERENCE] == 0, ctr)
183 gv_check("absent-feature-histogram-scores-zero-rather-than-a-WIN" as *u8, v[NX_WQG_OFF_FEATURE_VARIETY] == 0, ctr)
184 gv_check("neg-control-a-map-with-both-optional-axes-absent-cannot-reach-S" as *u8, v[NX_WQG_OFF_GRADE] < NX_GRADE_S, ctr)
185
186 // ===== BIOME COHERENCE: elevation-matched against deliberately wrong ================
187 let biome: *i64 = (sys_mmap(n * NX_SIZEOF_NX_INT)) as *i64
188 let brange: i64 = mtn_hi - mtn_lo
189 let b1: i64 = mtn_lo + brange / WG_QUARTER
190 let b2: i64 = mtn_lo + (brange * WG_TWO) / WG_QUARTER
191 let b3: i64 = mtn_lo + (brange * WG_THREE) / WG_QUARTER
192 var bi: i64 = 0
193 while bi < n {
194 let hv: i64 = mtn[bi]
195 var id: i64 = WG_BIOME_ICE
196 if hv <= b3 { id = WG_BIOME_SNOW }
197 if hv <= b2 { id = WG_BIOME_TFOREST }
198 if hv <= b1 { id = WG_BIOME_DESERT }
199 biome[bi] = id
200 bi = bi + 1
201 }
202 nx_world_quality_grade(mtn, WG_W, WG_H, WG_RELIEF, biome, nullp, 0, v)
203 graded = graded + 1
204 let biome_right: i64 = v[NX_WQG_OFF_BIOME_COHERENCE]
205 gv_check("elevation-matched-biomes-WIN-the-coherence-axis" as *u8, biome_right >= NX_WQG_AXIS_WIN_FLOOR, ctr)
206
207 bi = 0
208 while bi < n {
209 biome[bi] = WG_BIOME_ICE
210 bi = bi + 1
211 }
212 nx_world_quality_grade(mtn, WG_W, WG_H, WG_RELIEF, biome, nullp, 0, v)
213 graded = graded + 1
214 let biome_wrong: i64 = v[NX_WQG_OFF_BIOME_COHERENCE]
215 gv_check("neg-control-biomes-that-ignore-elevation-score-lower" as *u8, biome_wrong < biome_right, ctr)
216 gv_check("neg-control-wrong-biomes-do-not-WIN-the-coherence-axis" as *u8, biome_wrong < NX_WQG_AXIS_WIN_FLOOR, ctr)
217
218 // ===== FEATURE VARIETY: normalised Shannon entropy of the kind histogram ============
219 let hist: *i64 = (sys_mmap(WG_KINDS * NX_SIZEOF_NX_INT)) as *i64
220 var hk: i64 = 0
221 while hk < WG_KINDS {
222 hist[hk] = WG_KIND_COUNT
223 hk = hk + 1
224 }
225 nx_world_quality_grade(mtn, WG_W, WG_H, WG_RELIEF, nullp, hist, WG_KINDS, v)
226 graded = graded + 1
227 let var_uniform: i64 = v[NX_WQG_OFF_FEATURE_VARIETY]
228 gv_check("a-uniform-feature-histogram-WINS-the-variety-axis" as *u8, var_uniform >= NX_WQG_AXIS_WIN_FLOOR, ctr)
229
230 hist[0] = WG_KIND_ALL
231 hk = 1
232 while hk < WG_KINDS {
233 hist[hk] = 0
234 hk = hk + 1
235 }
236 nx_world_quality_grade(mtn, WG_W, WG_H, WG_RELIEF, nullp, hist, WG_KINDS, v)
237 graded = graded + 1
238 gv_check("neg-control-an-all-one-kind-world-scores-zero-variety" as *u8, v[NX_WQG_OFF_FEATURE_VARIETY] == 0, ctr)
239 gv_check("neg-control-variety-is-not-a-constant" as *u8, var_uniform > v[NX_WQG_OFF_FEATURE_VARIETY], ctr)
240
241 // ===== THE LETTER RUBRIC ============================================================
242 gv_check("rubric-eight-wins-is-S" as *u8, _wqg_grade_from_8(1, 1, 1, 1, 1, 1, 1, 1) == NX_GRADE_S, ctr)
243 gv_check("rubric-seven-wins-caps-at-A" as *u8, _wqg_grade_from_8(1, 1, 1, 1, 1, 1, 1, 0) == NX_GRADE_A, ctr)
244 gv_check("rubric-four-losses-is-F-however-many-wins-sit-beside-them" as *u8, _wqg_grade_from_8(0 - 1, 0 - 1, 0 - 1, 0 - 1, 1, 1, 1, 1) == NX_GRADE_F, ctr)
245 gv_check("neg-control-the-rubric-is-not-a-constant" as *u8, _wqg_grade_from_8(1, 1, 1, 1, 1, 1, 1, 1) != _wqg_grade_from_8(0 - 1, 0 - 1, 0 - 1, 0 - 1, 1, 1, 1, 1), ctr)
246 gv_check("neg-control-an-out-of-range-grade-is-rejected" as *u8, nx_grade_is_valid(NX_GRADE_COUNT) == 0, ctr)
247 gv_check("neg-control-an-out-of-range-refine-axis-is-rejected" as *u8, nx_wqg_refine_is_valid(NX_WQG_REFINE_COUNT) == 0, ctr)
248
249 // ===== REFUSAL PATHS ================================================================
250 // A grade over zero cells, or against a zero relief budget, must refuse rather than
251 // divide. BIND THE ASSERTION TO THE REFUSAL, not merely to the absence of a crash.
252 nx_world_quality_grade(flat, 0, WG_H, WG_RELIEF, nullp, nullp, 0, v)
253 gv_check("a-zero-width-grid-refuses-with-F" as *u8, v[NX_WQG_OFF_GRADE] == NX_GRADE_F, ctr)
254 nx_world_quality_grade(flat, WG_W, WG_H, 0, nullp, nullp, 0, v)
255 gv_check("a-zero-relief-budget-refuses-with-F" as *u8, v[NX_WQG_OFF_GRADE] == NX_GRADE_F, ctr)
256
257 // BIND THE AGGREGATE TO ITS DENOMINATOR: a tooth that passes because it examined zero
258 // subjects is not a tooth. This asserts the grader was actually driven the declared
259 // number of times, so no block above can be silently skipped and still read GREEN.
260 gv_check("denominator-every-declared-heightmap-was-actually-graded" as *u8, graded == WG_MAPS_GRADED, ctr)
261
262 return gv_verdict("nx_world_quality_grader_gate" as *u8, ctr, "in-process over nx_world_quality_grader: the degenerate-input contract on both axes that used to award a WIN to a constant world, the flatness inversion, the banded verdict at all three outcomes, optional-axis abstention, the biome and variety rulers with wrong-input controls, the letter rubric and both refusal paths" as *u8)
263}