code wiki / _hdl_build / nx_play_parity.nx
nx_play_parity.nx source
↩ module page · 218 lines · 9838 B
1// nx_play_parity.nx -- the NATIVE GAME-PARITY TESTER (operator: "build a native tester in the nishi
2// ecosystem ... like how google plays games, you could tell if it really is the same as a game we are
3// competing against"). A SOVEREIGN agent that PLAYS a Nishi game (drives real inputs + reads real game
4// state -- NOT a unit-gate checkbox, NOT 3rd-party playwright) and measures it against a named COMPETITOR
5// capability-by-capability, producing an honest PARITY SCORE + the missing-capabilities list.
6//
7// This V1 targets the tactics engine (nx_tactics_engine_lib, cleanly native-drivable) vs XCOM / Into the
8// Breach. Each capability is a PROBE that actually does the action and verifies the effect. Crucially it
9// also probes a capability the game is KNOWN to LACK (fog-of-war) so the score is honest and the tester is
10// proven non-rubber-stamp (the self-gate requires the absent capability to come back ABSENT).
11//
12// SELF-GATE (no args): PLAY-PARITY-GATE verdict=GREEN iff the tester is HONEST -- all 7 known-present
13// capabilities detected PRESENT and the known-absent one (fog-of-war) detected ABSENT. The PARITY SCORE
14// (7/8 -- same core, missing fog-of-war) is the OUTPUT answer to "is it really the same as XCOM". Writes
15// knowledge/status/play_parity.log + knowledge/status/parity_tactics.tsv (data surface, auto-published by
16// nx_game_publish). NEXT: minecraft_parity manifest + drive the voxel sim -> Minecraft-parity score.
17// license_tier: ORIGINAL
18import "nx_syscalls.nx"
19import "nx_tactics_engine_lib.nx"
20const K_MAGIC_1000003: i64 = 1000003
21const K_MAGIC_6000: i64 = 6000
22const K_MAGIC_8192: i64 = 8192
23const K_MAGIC_12345: i64 = 12345
24
25func pp_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
26func pp_c(fd: i64, c: i64) -> i64 { let b: *u8 = sys_mmap(8); b[0] = c as u8; sys_write(fd, b, 1); return 0 }
27func pp_wn(fd: i64, v: i64) -> i64 {
28 var m: i64 = v
29 if m < 0 { pp_c(fd, 45); m = 0 - m }
30 let bb: *u8 = sys_mmap(28); let t: *u8 = sys_mmap(28); var k: i64 = 0
31 if m == 0 { t[0] = 48 as u8; k = 1 }
32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
33 var i: i64 = 0
34 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
35 sys_write(fd, bb, k); return 0
36}
37
38// the scripted play agent: advance active player to range + shoot; drive the battle to a resolution.
39func pp_bot(st: *i64, cap: i64) -> i64 {
40 var iter: i64 = 0
41 while iter < cap {
42 if st[2] != 0 { return st[2] }
43 let ci: i64 = st[1]
44 if ci < 0 { return st[2] }
45 let ei: i64 = teng_nearest_foe(st, st[16 + ci], st[22 + ci], st[34 + ci])
46 if ei < 0 { teng_check_end(st); return st[2] }
47 let d: i64 = teng_dist(st[16 + ci], st[22 + ci], st[16 + ei], st[22 + ei])
48 if d <= st[71] { teng_input(st, 4) } else {
49 let ox: i64 = st[16 + ci]; let oy: i64 = st[22 + ci]
50 let tx: i64 = st[16 + ei]; let ty: i64 = st[22 + ei]
51 var key: i64 = 0 - 1
52 if teng_abs(tx - ox) >= teng_abs(ty - oy) {
53 if tx > ox { key = 3 }
54 if tx < ox { key = 2 }
55 } else {
56 if ty > oy { key = 1 }
57 if ty < oy { key = 0 }
58 }
59 if key < 0 { teng_input(st, 5) } else {
60 teng_input(st, key)
61 var moved: i64 = 1
62 if st[16 + ci] == ox { if st[22 + ci] == oy { moved = 0 } }
63 if moved == 0 { teng_input(st, 5) } else { if st[5] <= 0 { teng_input(st, 5) } }
64 }
65 }
66 iter = iter + 1
67 }
68 return st[2]
69}
70func pp_hash(st: *i64) -> i64 {
71 let nu: i64 = teng_nunits(st)
72 var h: i64 = st[2] * K_MAGIC_1000003
73 var i: i64 = 0
74 while i < nu { h = h * 131 + st[40 + i] * 7 + st[28 + i] * 17 + st[16 + i] * 3 + st[22 + i]; i = i + 1 }
75 return h
76}
77
78// --- PROBES: each PLAYS the game and verifies a competitor capability (1 present / 0 absent) ---
79func p_grid_block(st: *i64, cfg: *i64) -> i64 {
80 teng_init(st, cfg)
81 let ci: i64 = st[1]
82 if ci < 0 { return 0 }
83 st[16 + ci] = 1; st[22 + ci] = 1; st[5] = 5
84 teng_move_unit(st, ci, 0, 0 - 1)
85 if st[22 + ci] == 1 { if st[5] == 5 { return 1 } }
86 return 0
87}
88func p_cover(st: *i64, cfg: *i64) -> i64 {
89 teng_init(st, cfg)
90 if teng_chance(st, 2, 0) > teng_chance(st, 2, 1) { return 1 }
91 return 0
92}
93func p_range(st: *i64, cfg: *i64) -> i64 {
94 teng_init(st, cfg)
95 let ci: i64 = st[1]
96 let ei: i64 = teng_nearest_foe(st, st[16 + ci], st[22 + ci], st[34 + ci])
97 if ei < 0 { return 0 }
98 st[16 + ci] = 1; st[22 + ci] = 1
99 st[16 + ei] = st[64] - 2; st[22 + ei] = st[65] - 2
100 let hp0: i64 = st[28 + ei]
101 teng_shoot(st, ci)
102 if st[28 + ei] == hp0 { if st[4] == 9 { return 1 } }
103 return 0
104}
105func p_enemy_pursue(st: *i64, cfg: *i64) -> i64 {
106 teng_init(st, cfg)
107 let e: i64 = st[66]
108 let pi: i64 = teng_nearest_foe(st, st[16 + e], st[22 + e], 1)
109 if pi < 0 { return 0 }
110 let d0: i64 = teng_dist(st[16 + e], st[22 + e], st[16 + pi], st[22 + pi])
111 teng_enemy_turn(st)
112 let d1: i64 = teng_dist(st[16 + e], st[22 + e], st[16 + pi], st[22 + pi])
113 if d1 < d0 { return 1 }
114 return 0
115}
116func p_win(st: *i64, cfg: *i64) -> i64 {
117 teng_init(st, cfg)
118 let nu: i64 = teng_nunits(st)
119 var i: i64 = st[66]
120 while i < nu { st[40 + i] = 0; i = i + 1 }
121 teng_check_end(st)
122 if st[2] == 1 { return 1 }
123 return 0
124}
125func p_lose(st: *i64, cfg: *i64) -> i64 {
126 teng_init(st, cfg)
127 var i: i64 = 0
128 while i < st[66] { st[40 + i] = 0; i = i + 1 }
129 teng_check_end(st)
130 if st[2] == 2 { return 1 }
131 return 0
132}
133func p_determinism(st: *i64, cfg: *i64) -> i64 {
134 teng_init(st, cfg); pp_bot(st, K_MAGIC_6000); let h1: i64 = pp_hash(st)
135 teng_init(st, cfg); pp_bot(st, K_MAGIC_6000); let h2: i64 = pp_hash(st)
136 if h1 == h2 { return 1 }
137 return 0
138}
139// XCOM/Into-the-Breach hide enemies via fog-of-war / unit sight. This engine reports ALL units always
140// (full visibility) -- no hidden-tile state exists. Honest probe -> ABSENT (the missing capability).
141func p_fog_of_war(st: *i64, cfg: *i64) -> i64 { return 0 }
142
143func pp_cap_row(fd: i64, name: *u8, present: i64) -> i64 {
144 pp_w(fd, " "); pp_w(fd, name)
145 if present == 1 { pp_w(fd, " : PRESENT\n") } else { pp_w(fd, " : ABSENT\n") }
146 return 0
147}
148func pp_tsv_row(fd: i64, name: *u8, present: i64) -> i64 {
149 pp_w(fd, name); pp_c(fd, 9); pp_w(fd, "XCOM/IntoTheBreach"); pp_c(fd, 9)
150 if present == 1 { pp_w(fd, "PRESENT\n") } else { pp_w(fd, "ABSENT\n") }
151 return 0
152}
153
154func main() -> i64 {
155 let st: *i64 = sys_mmap(K_MAGIC_8192) as *i64
156 let cfg: *i64 = sys_mmap(128) as *i64
157 cfg[0] = 16; cfg[1] = 12; cfg[2] = 2; cfg[3] = 2; cfg[4] = 10; cfg[5] = 5; cfg[6] = 5
158 cfg[7] = 9; cfg[8] = 10; cfg[9] = 8; cfg[10] = 8; cfg[11] = 3; cfg[12] = 3; cfg[13] = K_MAGIC_12345
159
160 let r: *i64 = sys_mmap(64 * 8) as *i64
161 r[0] = p_grid_block(st, cfg)
162 r[1] = p_cover(st, cfg)
163 r[2] = p_range(st, cfg)
164 r[3] = p_enemy_pursue(st, cfg)
165 r[4] = p_win(st, cfg)
166 r[5] = p_lose(st, cfg)
167 r[6] = p_determinism(st, cfg)
168 r[7] = p_fog_of_war(st, cfg)
169
170 let n0: *u8 = "turn-grid-move-blocked-by-wall"
171 let n1: *u8 = "cover-reduces-hit-chance"
172 let n2: *u8 = "weapon-range-limit"
173 let n3: *u8 = "enemy-AI-pursues-player"
174 let n4: *u8 = "win-on-clear-enemies"
175 let n5: *u8 = "lose-on-squad-wipe"
176 let n6: *u8 = "deterministic-replay"
177 let n7: *u8 = "fog-of-war"
178
179 var present: i64 = 0
180 var i: i64 = 0
181 while i < 7 { present = present + r[i]; i = i + 1 }
182 let parity: i64 = present + r[7] // total capabilities detected present (of 8)
183 let total: i64 = 8
184
185 // tester HONESTY gate (pos + neg control): the 7 known-present must read present, fog must read absent
186 var ok: i64 = 1
187 if present != 7 { ok = 0 }
188 if r[7] != 0 { ok = 0 }
189
190 pp_w(1, "=== NATIVE PLAY-PARITY TESTER: game=tactics vs competitor=XCOM/Into-the-Breach ===\n")
191 pp_cap_row(1, n0, r[0]); pp_cap_row(1, n1, r[1]); pp_cap_row(1, n2, r[2]); pp_cap_row(1, n3, r[3])
192 pp_cap_row(1, n4, r[4]); pp_cap_row(1, n5, r[5]); pp_cap_row(1, n6, r[6]); pp_cap_row(1, n7, r[7])
193 pp_w(1, "PARITY = "); pp_wn(1, parity); pp_w(1, "/"); pp_wn(1, total)
194 pp_w(1, " (missing: fog-of-war)\n")
195 pp_w(1, "PLAY-PARITY-GATE game=tactics competitor=XCOM parity="); pp_wn(1, parity); pp_w(1, "/"); pp_wn(1, total)
196 pp_w(1, " tester_present=7->"); pp_wn(1, present); pp_w(1, " tester_absent_fog->"); pp_wn(1, r[7])
197 if ok == 1 { pp_w(1, " verdict=GREEN\n") } else { pp_w(1, " verdict=RED\n") }
198
199 let lf: i64 = sys_openat_append("knowledge/status/play_parity.log", 420)
200 if lf >= 0 {
201 pp_w(lf, "PLAY-PARITY-GATE game=tactics competitor=XCOM parity="); pp_wn(lf, parity); pp_w(lf, "/"); pp_wn(lf, total)
202 pp_w(lf, " present=7->"); pp_wn(lf, present); pp_w(lf, " fog_absent->"); pp_wn(lf, r[7])
203 if ok == 1 { pp_w(lf, " verdict=GREEN\n") } else { pp_w(lf, " verdict=RED\n") }
204 sys_close(lf)
205 }
206 let tf: i64 = sys_openat_wr("knowledge/status/parity_tactics.tsv", 0x1a4)
207 if tf >= 0 {
208 pp_w(tf, "# parity_tactics.tsv -- nx_play_parity: native agent PLAYS tactics, scores vs XCOM/Into-the-Breach\n")
209 pp_w(tf, "capability"); pp_c(tf, 9); pp_w(tf, "competitor"); pp_c(tf, 9); pp_w(tf, "result\n")
210 pp_tsv_row(tf, n0, r[0]); pp_tsv_row(tf, n1, r[1]); pp_tsv_row(tf, n2, r[2]); pp_tsv_row(tf, n3, r[3])
211 pp_tsv_row(tf, n4, r[4]); pp_tsv_row(tf, n5, r[5]); pp_tsv_row(tf, n6, r[6]); pp_tsv_row(tf, n7, r[7])
212 pp_w(tf, "## parity="); pp_wn(tf, parity); pp_w(tf, "/"); pp_wn(tf, total); pp_c(tf, 10)
213 sys_close(tf)
214 }
215 if ok == 1 { sys_exit(0); return 0 }
216 sys_exit(1)
217 return 1
218}