@bongos/core 1.19.334 → 1.19.336

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,133 +0,0 @@
1
- // tests/autotile_xverify.mjs
2
- //
3
- // Cross-verify the JS autotile picker (public/game/world/autotile.js)
4
- // against the Python lookup tables (art/pipeline/autotile_mapping.py).
5
- //
6
- // Both implementations build a 256-entry blob47 table and a 16-entry
7
- // path16 table. They MUST agree byte-for-byte; if they drift, the in-
8
- // game renderer would pick a different tile than the autotile compositor
9
- // produced, breaking edge matching.
10
- //
11
- // Strategy: Python emits its tables to art/pipeline/_autotile_tables.json
12
- // (run autotile_xverify.py first). This script imports the JS picker,
13
- // rebuilds the same tables by enumerating all input bytes, and asserts
14
- // pairwise equality with the Python output.
15
- //
16
- // Usage:
17
- // python3 art/pipeline/autotile_xverify.py
18
- // node tests/autotile_xverify.mjs
19
-
20
- import { selectBlob47, selectPath16 } from '../public/game/world/autotile.js';
21
- import { readFileSync } from 'node:fs';
22
- import { fileURLToPath } from 'node:url';
23
- import { dirname, resolve } from 'node:path';
24
-
25
- const HERE = dirname(fileURLToPath(import.meta.url));
26
- const TABLES_PATH = resolve(HERE, '..', 'art', 'pipeline', '_autotile_tables.json');
27
-
28
- function loadPythonTables() {
29
- let raw;
30
- try {
31
- raw = readFileSync(TABLES_PATH, 'utf8');
32
- } catch (e) {
33
- console.error(
34
- `\n[xverify] cannot read ${TABLES_PATH}\n` +
35
- `Run \`python3 art/pipeline/autotile_xverify.py\` first to emit it.\n`
36
- );
37
- process.exit(2);
38
- }
39
- return JSON.parse(raw);
40
- }
41
-
42
- // Reconstruct the JS blob47 table by feeding all 256 input bytes through
43
- // selectBlob47. We use 'X' for "same as my terrain" and 'Y' for "different"
44
- // so the picker's identity check resolves to the right bit pattern.
45
- function buildJsBlobTable() {
46
- const table = new Array(256);
47
- for (let byte = 0; byte < 256; byte++) {
48
- const b = (pos) => ((byte >> pos) & 1) ? 'X' : 'Y';
49
- table[byte] = selectBlob47('X', {
50
- NW: b(7), N: b(6), NE: b(5),
51
- W: b(4), E: b(3),
52
- SW: b(2), S: b(1), SE: b(0),
53
- });
54
- }
55
- return table;
56
- }
57
-
58
- function buildJsPathTable() {
59
- const table = new Array(16);
60
- for (let byte = 0; byte < 16; byte++) {
61
- table[byte] = selectPath16({
62
- N: (byte >> 3) & 1,
63
- W: (byte >> 2) & 1,
64
- E: (byte >> 1) & 1,
65
- S: (byte >> 0) & 1,
66
- });
67
- }
68
- return table;
69
- }
70
-
71
- function diff(a, b) {
72
- const out = [];
73
- for (let i = 0; i < a.length; i++) {
74
- if (a[i] !== b[i]) out.push({ i, py: a[i], js: b[i] });
75
- }
76
- return out;
77
- }
78
-
79
- function main() {
80
- const py = loadPythonTables();
81
-
82
- const jsBlob = buildJsBlobTable();
83
- const blobDiff = diff(py.blob47.table, jsBlob);
84
- const blobUnique = new Set(jsBlob).size;
85
-
86
- const jsPath = buildJsPathTable();
87
- const pathDiff = diff(py.path16.table, jsPath);
88
- const pathUnique = new Set(jsPath).size;
89
-
90
- let ok = true;
91
-
92
- if (py.blob47.size !== 47) {
93
- console.error(`[xverify] python blob47 size != 47 (got ${py.blob47.size})`);
94
- ok = false;
95
- }
96
- if (blobUnique !== 47) {
97
- console.error(`[xverify] js blob47 produced ${blobUnique} unique tile indices, expected 47`);
98
- ok = false;
99
- }
100
- if (blobDiff.length > 0) {
101
- console.error(`[xverify] blob47 mismatch (${blobDiff.length} bytes):`);
102
- for (const d of blobDiff.slice(0, 10)) {
103
- console.error(` byte 0x${d.i.toString(16).padStart(2, '0')}: python=${d.py} js=${d.js}`);
104
- }
105
- if (blobDiff.length > 10) console.error(` ... and ${blobDiff.length - 10} more`);
106
- ok = false;
107
- }
108
-
109
- if (py.path16.size !== 16) {
110
- console.error(`[xverify] python path16 size != 16 (got ${py.path16.size})`);
111
- ok = false;
112
- }
113
- if (pathUnique !== 16) {
114
- console.error(`[xverify] js path16 produced ${pathUnique} unique tile indices, expected 16`);
115
- ok = false;
116
- }
117
- if (pathDiff.length > 0) {
118
- console.error(`[xverify] path16 mismatch (${pathDiff.length} bytes):`);
119
- for (const d of pathDiff) {
120
- console.error(` byte 0x${d.i.toString(16).padStart(2, '0')}: python=${d.py} js=${d.js}`);
121
- }
122
- ok = false;
123
- }
124
-
125
- if (!ok) {
126
- console.error(`\n[xverify] FAIL — Python and JS autotile tables disagree.\n`);
127
- process.exit(1);
128
- }
129
-
130
- console.log(`[xverify] OK — Python and JS agree across all 256 blob47 inputs and all 16 path16 inputs.`);
131
- }
132
-
133
- main();