gigachess 0.5.0 → 0.7.0

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.
Files changed (107) hide show
  1. package/README.md +142 -54
  2. package/dist/attacks.d.ts +18 -7
  3. package/dist/attacks.d.ts.map +1 -1
  4. package/dist/attacks.js +197 -89
  5. package/dist/bishopSplit32Blob.d.ts +2 -0
  6. package/dist/bishopSplit32Blob.d.ts.map +1 -0
  7. package/dist/bishopSplit32Blob.js +2 -0
  8. package/dist/castling.d.ts +2 -0
  9. package/dist/castling.d.ts.map +1 -1
  10. package/dist/castling.js +27 -12
  11. package/dist/chess960.d.ts +2 -9
  12. package/dist/chess960.d.ts.map +1 -1
  13. package/dist/chess960.js +2 -18
  14. package/dist/chessjs.d.ts +1 -1
  15. package/dist/chessjs.d.ts.map +1 -1
  16. package/dist/chessjs.js +1 -1
  17. package/dist/chessops/board.d.ts +1 -1
  18. package/dist/chessops/board.d.ts.map +1 -1
  19. package/dist/chessops/board.js +1 -1
  20. package/dist/chessops/chess.d.ts +6 -10
  21. package/dist/chessops/chess.d.ts.map +1 -1
  22. package/dist/chessops/chess.js +73 -97
  23. package/dist/chessops/convert.d.ts +1 -1
  24. package/dist/chessops/convert.d.ts.map +1 -1
  25. package/dist/chessops/convert.js +1 -1
  26. package/dist/chessops/debug.d.ts.map +1 -1
  27. package/dist/chessops/debug.js +7 -0
  28. package/dist/chessops/fen.d.ts.map +1 -1
  29. package/dist/chessops/fen.js +13 -2
  30. package/dist/chessops/fenInternal.d.ts +1 -1
  31. package/dist/chessops/fenInternal.d.ts.map +1 -1
  32. package/dist/chessops/fenInternal.js +1 -1
  33. package/dist/chessops/nativeBridge.d.ts +14 -0
  34. package/dist/chessops/nativeBridge.d.ts.map +1 -0
  35. package/dist/chessops/nativeBridge.js +87 -0
  36. package/dist/chessops/san.d.ts.map +1 -1
  37. package/dist/chessops/san.js +12 -10
  38. package/dist/chesstree.d.ts.map +1 -1
  39. package/dist/chesstree.js +23 -62
  40. package/dist/core.d.ts +6 -8
  41. package/dist/core.d.ts.map +1 -1
  42. package/dist/core.js +5 -10
  43. package/dist/fast/bishopSplit32Blob-NOHWZEWR.js +1 -0
  44. package/dist/fast/index.js +1 -0
  45. package/dist/fast/rookSplit32Blob-C3ANUNTJ.js +1 -0
  46. package/dist/fast/zobristBlob-HIMMLZLJ.js +1 -0
  47. package/dist/fast.d.ts +2 -0
  48. package/dist/fast.d.ts.map +1 -0
  49. package/dist/fast.js +2 -0
  50. package/dist/index.d.ts +1 -14
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +2 -19
  53. package/dist/native96.d.ts +16 -0
  54. package/dist/native96.d.ts.map +1 -0
  55. package/dist/native96.js +6 -0
  56. package/dist/nativeBoard96.d.ts +118 -0
  57. package/dist/nativeBoard96.d.ts.map +1 -0
  58. package/dist/nativeBoard96.js +1077 -0
  59. package/dist/nativeChess.d.ts +97 -0
  60. package/dist/nativeChess.d.ts.map +1 -0
  61. package/dist/nativeChess.js +201 -0
  62. package/dist/nativeMovegen96.d.ts +2 -0
  63. package/dist/nativeMovegen96.d.ts.map +1 -0
  64. package/dist/nativeMovegen96.js +282 -0
  65. package/dist/nativePublicTypes.d.ts +3 -0
  66. package/dist/nativePublicTypes.d.ts.map +1 -0
  67. package/dist/nativePublicTypes.js +1 -0
  68. package/dist/perftCompact.d.ts +10 -0
  69. package/dist/perftCompact.d.ts.map +1 -0
  70. package/dist/perftCompact.js +420 -0
  71. package/dist/pgn.d.ts +2 -3
  72. package/dist/pgn.d.ts.map +1 -1
  73. package/dist/pgn.js +2 -5
  74. package/dist/rookSplit32Blob.d.ts +2 -0
  75. package/dist/rookSplit32Blob.d.ts.map +1 -0
  76. package/dist/rookSplit32Blob.js +2 -0
  77. package/dist/setupBoard.d.ts +54 -0
  78. package/dist/setupBoard.d.ts.map +1 -0
  79. package/dist/setupBoard.js +249 -0
  80. package/dist/{fen.d.ts → setupFen.d.ts} +1 -1
  81. package/dist/setupFen.d.ts.map +1 -0
  82. package/dist/{fen.js → setupFen.js} +140 -125
  83. package/dist/squareSet.d.ts +2 -0
  84. package/dist/squareSet.d.ts.map +1 -1
  85. package/dist/squareSet.js +6 -1
  86. package/dist/types.d.ts +1 -1
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/zobrist.d.ts +2 -2
  89. package/dist/zobrist.d.ts.map +1 -1
  90. package/dist/zobrist.js +17 -15
  91. package/package.json +18 -6
  92. package/dist/bishopMagicBlob.d.ts +0 -2
  93. package/dist/bishopMagicBlob.d.ts.map +0 -1
  94. package/dist/bishopMagicBlob.js +0 -11
  95. package/dist/board.d.ts +0 -216
  96. package/dist/board.d.ts.map +0 -1
  97. package/dist/board.js +0 -1088
  98. package/dist/chess.d.ts +0 -252
  99. package/dist/chess.d.ts.map +0 -1
  100. package/dist/chess.js +0 -1930
  101. package/dist/fen.d.ts.map +0 -1
  102. package/dist/rookMagicBlob.d.ts +0 -2
  103. package/dist/rookMagicBlob.d.ts.map +0 -1
  104. package/dist/rookMagicBlob.js +0 -11
  105. package/dist/san.d.ts +0 -38
  106. package/dist/san.d.ts.map +0 -1
  107. package/dist/san.js +0 -549
package/README.md CHANGED
@@ -5,8 +5,9 @@
5
5
  <h1 align="center">GigaChess</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>The fastest chess library and engine in TypeScript.</strong><br>
9
- Built for high-performance web applications, interactive chessboards, and analysis engines.
8
+ <strong>Benchmark-leading pure JavaScript/TypeScript chess library.</strong>
9
+ <br>Published 0.6.0: up to 164× the perft throughput of chess.js and 13× that of chessops.<br>
10
+ Full chess rules. Zero runtime dependencies. No WebAssembly.
10
11
  </p>
11
12
 
12
13
  <p align="center">
@@ -19,22 +20,64 @@
19
20
 
20
21
  ---
21
22
 
22
- ## ⚡ Highlights
23
-
24
- * 🚀 **45x Faster Move Execution**: In-place stateful `Board` executes moves at **5.98M moves/sec** (167 ns/op).
25
- * 🏎️ **18.7M nodes/s Perft**: Stockfish-grade bitboard throughput in pure TypeScript.
26
- * 🛡️ **100% Permissive MIT License**: Completely free for commercial and proprietary applications.
27
- * 🔄 **1-Line `chess.js` Upgrade**: Drop-in wrapper via `gigachess/chessjs` with zero code changes.
28
- * ♟️ **Full Chess & Chess960**: Complete support for standard chess, Fischer Random (960), FEN, SAN, and UCI.
29
- * 🌲 **Study Trees & Fast PGN**: Interactive variation trees, comments, glyphs, and 128k games/sec PGN streaming.
30
- * 🔑 **Instant Polyglot Zobrist Hashing**: Zero-allocation $O(1)$ 64-bit incremental hash matching Polyglot startpos.
31
- * 📦 **16-bit Packed Move Streams (`moves2`)**: Compact 2-byte binary serialization replaying at **4.8M plies/sec**.
32
-
33
- ---
34
-
35
- > 💡 **100% Pure TypeScript with Zero Dependencies**: GigaChess requires no native C++ binaries, node-gyp, or WebAssembly. It runs seamlessly in modern browsers, Node.js, Bun, Deno, and edge workers.
36
-
37
- ---
23
+ ## Built to be the fastest
24
+
25
+ The published GigaChess 0.6.0 leads every supported pure-JS workload in our independent
26
+ Linux and Windows benchmark matrix, including move generation, notation,
27
+ FEN, game replay and perft. It is built for chess applications, interactive
28
+ boards, analysis tools and high-throughput game databases.
29
+
30
+ | Benchmark | vs chess.js | vs chessops |
31
+ |---|---:|---:|
32
+ | Mixed-position perft | **132–164×** | **7.8–9.9×** |
33
+ | Starting-position perft (depth 5) | **80–104×** | **9.6–13.4×** |
34
+ | SAN move lists | **7.4–8.1×** | **2.7–3.1×** |
35
+ | FEN round trip | **4.3–6.3×** | **3.0–3.8×** |
36
+
37
+ Throughput ratios across five tested Node.js configurations; higher is better.
38
+ Perft measures legal move-tree traversal, not AI search strength.
39
+ [Full results, all competitors and methodology](#performance-comparisons-060).
40
+
41
+ - **Pure TypeScript, zero runtime dependencies:** no WASM, native binaries or compilation step to begin playing.
42
+ - **Complete chess rules:** standard chess, Chess960, SAN, UCI, FEN, PGN and annotated study trees.
43
+ - **Developer-friendly:** chess.js and chessops-style interfaces over the same engine, plus a high-throughput stateful Board API.
44
+ - **Compact and correct:** independent packed 16-bit moves, checked replay, incremental Polyglot hashes, FIDE repetition keys and reversible moves.
45
+ - **MIT licensed:** use in open-source or commercial projects.
46
+
47
+ ### GigaChess 0.7.0 — shared native Board96
48
+
49
+ Version 0.7.0 replaces the old native API with a single directly
50
+ operated **96-byte Board96** payload matching GigaChess Rust 0.3.0's
51
+ little-endian interchange format. JavaScript object overhead is additional.
52
+ There is no legacy playable fallback. The chess.js and chessops-style
53
+ interfaces also use Board96 for play.
54
+
55
+ Across ten independently tested Node 22/24 configurations (Linux and
56
+ Windows x64/ARM64, macOS ARM64), 0.7.0 improves median throughput
57
+ versus npm 0.6.0 by 1.84× for checked replay, 1.67× for trusted replay,
58
+ 2.08× for SAN and 1.29× for make/undo. FEN parsing and some clone/perft
59
+ lanes remain slower; see the full ranges, not just the wins.
60
+
61
+ [0.7.0 benchmark and correctness evidence](bench/results/native-board96-round4/REPORT.md) ·
62
+ [Migration guide](docs/MIGRATION-v0.7.0.md)
63
+
64
+ ### Optimized pure-JavaScript Board
65
+
66
+ The optional `gigachess/fast` entry delivers an independently minified ESM
67
+ Board with the same public rules and move encoding. Load the compact attack
68
+ and hash tables for peak throughput:
69
+
70
+ ~~~ts
71
+ import { Board, ensureMagicTablesLoaded, ensureZobristLoaded } from "gigachess/fast";
72
+ await Promise.all([ensureMagicTablesLoaded(), ensureZobristLoaded()]);
73
+ const board = Board.fromFen();
74
+ ~~~
75
+
76
+ Import the table-loading hooks from the SAME /fast entry: the ordinary
77
+ /core module has separate module-local caches. Specialized perft uses its
78
+ own reversible, clock-independent internal move path; makeMove/unmakeMove
79
+ still fully maintain Zobrist, castling, clocks, and move validation.
80
+ Both entry points work without awaiting attack tables; the synchronous fallback is exact. Await hash readiness before using Polyglot keys.
38
81
 
39
82
  ## 📦 Installation
40
83
 
@@ -50,11 +93,13 @@ npm install gigachess
50
93
  import { Board } from "gigachess";
51
94
 
52
95
  // Initialize starting position
53
- const board = new Board();
96
+ const board = Board.fromFen();
54
97
 
55
- // Parse SAN and execute move in 167 ns
98
+ // Parse SAN and execute a legal move
56
99
  const move = board.parseSan("e4");
57
- const undo = board.makeMove(move);
100
+ if (move === null) throw new Error("Illegal move");
101
+ const undo = board.clone();
102
+ board.makeMove(move, undo);
58
103
 
59
104
  console.log(board.toFen()); // 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1'
60
105
  console.log(board.inCheck()); // false
@@ -66,30 +111,39 @@ console.log(board.toFen()); // startpos restored
66
111
 
67
112
  ---
68
113
 
69
- ## 📊 GigaChess vs `chess.js`
70
-
71
- Measured under Node.js v24 on Apple Silicon:
72
-
73
- | Feature / Benchmark | 🚀 **GigaChess** | 📦 **`chess.js`** (1.4.0) | Advantage |
74
- |---|---|---|---|
75
- | **Move Execution (`make` + `unmake`)** | **5,986,400 ops/s** (167 ns) | 134,500 ops/s (7,434 ns) | **44.5x faster (+4,350%)** |
76
- | **Legal Move Generation** | **541,200 pos/s** (1,848 ns) | 49,200 pos/s (20,341 ns) | **11.0x faster (+1,001%)** |
77
- | **Perft Movegen (Depth Search)** | **18,678,516 nodes/s** | ~500,000 nodes/s | **37x faster** |
78
- | **Game Stream Replay** | **4,803,000 plies/s** | 649,000 plies/s | **7.4x faster (+640%)** |
79
- | **Check & Status Query (`inCheck`)** | **4.9 ns** (203M ops/s) | 26.3 ns (38M ops/s) | **5.3x faster (+434%)** |
80
- | **PGN Parsing & Streaming** | **128,701 games/s** (89 MB/s) | 3,634 games/s (2.5 MB/s) | **35.4x faster (+3,440%)** |
81
- | **SAN Move Validation & Make** | **49,444 ops/s** | 6,992 ops/s | **7.07x faster (+607%)** |
82
- | **FEN Parsing & Setup** | **458,961 ops/s** | 91,214 ops/s | **5.03x faster (+403%)** |
83
- | **Memory per 80-Ply Game** | **160 Bytes** (`Uint16Array`) | ~4,200 Bytes (Heap Objects) | **26x less memory** |
84
- | **64-bit Polyglot Zobrist Hash** | ✅ **Built-in ($O(1)$ incremental)** | ❌ None | **Transposition & repetition** |
85
- | **Variation Trees & Analysis** | ✅ **Built-in (`chesstree`)** | ❌ None | **Branching, comments, glyphs** |
86
- | **Chess960 (Fischer Random)** | ✅ **Full 960 support** | ⚠️ Partial / legacy bugs | **Full standard & Chess960** |
114
+ ## Performance comparisons (0.6.0)
115
+
116
+ ![GigaChess benchmark comparison](./assets/benchmark-comparison.png)
117
+
118
+ Minimum GigaChess throughput advantage over each competitor across five Linux/Windows Node.js configurations. The strongest tested pure-JS competitor, drumevp, is also included: GigaChess is 2.33–3.73× faster in the separate direct move-generation comparison. See the [full benchmark report](docs/BENCHMARKS.md) for ranges, exact workloads, pinned versions and raw measurements.
119
+
120
+ | Workload | chess.js 1.4.0 | chessops 0.15.1 | drumevp 1.3.2 | drumevp source | GigaChess 0.5.0 |
121
+ |---|---:|---:|---:|---:|---:|
122
+ | Native move list | 1,706.09× | 5.09× | 2.83× | 2.79× | 3.45× |
123
+ | Normalized UCI list | 309.80× | 1.69× | 1.43× | 1.35× | 1.49× |
124
+ | SAN list | 7.44× | 2.72× | — | — | 1.28× |
125
+ | FEN round trip | 4.34× | 3.00× | 1.56× | — | 1.51× |
126
+ | Validated UCI replay | 358.57× | 3.70× | 5.22× | — | 4.71× |
127
+ | Start perft d5 | 79.75× | 9.57× | 1.80× | 1.81× | 4.26× |
128
+ | Kiwipete perft d4 | 103.78× | 9.11× | 1.76× | 1.75× | 4.75× |
129
+ | Endgame perft d5 | 45.86× | 7.60× | 1.35× | 1.37× | 4.79× |
130
+ | Promotion perft d4 | 90.96× | 8.71× | 1.64× | 1.65× | 4.39× |
131
+ | Mixed perft d3 | 132.10× | 7.83× | 1.66× | 1.63× | 3.57× |
132
+
133
+ The native list workload uses each library's public return type (chess.js produces verbose move objects); normalized UCI and SAN are separate. — means unsupported/not measured. 20,000 positions, 300 validated games, exact move-set and SAN parity. Final Apple Silicon/browser performance remains unverified.
134
+
135
+ ### WebAssembly comparison
136
+
137
+ UltraChess (Rust/WASM) is a separate runtime category, not part of the
138
+ pure-JS ranking. Its warm perft throughput is higher, while GigaChess leads
139
+ validated replay and offers synchronous first-use without WASM initialization.
140
+ See the [separate warm and cold-start comparisons](docs/BENCHMARKS.md#ultrachess-rustwebassembly-separate-category).
87
141
 
88
142
  ---
89
143
 
90
144
  ## 🔄 Drop-in `chess.js` Compatibility
91
145
 
92
- Existing `chess.js` code can be upgraded in 1 line with zero refactoring:
146
+ For supported `chess.js` APIs, switch the import:
93
147
 
94
148
  ```ts
95
149
  // Simply replace your import:
@@ -111,37 +165,47 @@ console.log(chess.history()); // ['e4', 'e5']
111
165
  ```ts
112
166
  import { Board } from "gigachess";
113
167
 
114
- const board = new Board();
168
+ const board = Board.fromFen();
115
169
 
116
- // Iterate without array allocation:
170
+ // Visit an independently owned list (callbacks may reenter):
117
171
  board.forEachLegalMove((move) => {
118
172
  console.log(board.toSan(move));
119
173
  });
120
174
 
121
- // Or write into a reusable buffer (541k pos/s):
175
+ // Or write into a reusable caller-owned buffer without list allocation:
122
176
  const buffer = new Uint16Array(256);
123
- const count = board.legalMoves(buffer);
177
+ const count = board.legalMovesInto(buffer);
124
178
  ```
125
179
 
126
180
  ### 2. Game State & Terminal Checks
127
181
  ```ts
128
- const board = new Board();
182
+ const board = Board.fromFen();
129
183
 
130
184
  board.inCheck(); // false
131
185
  board.isCheckmate(); // false
132
186
  board.isStalemate(); // false
133
- board.isDraw(); // false
187
+ board.isSeventyFiveMoveDraw(); // false
134
188
  board.isInsufficientMaterial();// false
135
- board.turn; // 0 = White, 1 = Black
189
+ board.turn; // 0 = Black, 1 = White
136
190
  ```
137
191
 
138
192
  ### 3. Incremental Polyglot Zobrist Hashing
139
193
  ```ts
140
- const board = new Board();
194
+ import { Board, ensureZobristLoaded } from "gigachess";
195
+
196
+ // The compact Zobrist data is loaded on demand; no wait is needed for normal
197
+ // movegen, but await readiness before asking for a meaningful position key.
198
+ await ensureZobristLoaded();
199
+ const board = Board.fromFen();
141
200
 
142
201
  // Fast 64-bit Polyglot key updated in O(1) during moves:
143
202
  const hash = board.zobrist(); // { lo: number, hi: number }
144
203
  console.log(board.zobristHex()); // "463b96181691fc9c"
204
+
205
+ // FIDE repetition equivalence ignores en-passant when the capture is illegal.
206
+ // Polyglot hashing intentionally retains its pseudo-legal EP rule; don't
207
+ // substitute the repetition key in opening-book or interoperable database keys.
208
+ const fideKey = board.repetitionKeyHex();
145
209
  ```
146
210
 
147
211
  ### 4. Chess960 (Fischer Random)
@@ -149,7 +213,7 @@ console.log(board.zobristHex()); // "463b96181691fc9c"
149
213
  import { Board } from "gigachess";
150
214
 
151
215
  // Load any of the 960 starting positions:
152
- const board = Board.fromFen("rnqbbknr/pppppppp/8/8/8/8/PPPPPPPP/RNQBBKNR w KQkq - 0 1");
216
+ const board = Board.fromFen("rnqbbknr/pppppppp/8/8/8/8/PPPPPPPP/RNQBBKNR w KQkq - 0 1", true);
153
217
  console.log(board.toFen());
154
218
  ```
155
219
 
@@ -157,22 +221,46 @@ console.log(board.toFen());
157
221
  ```ts
158
222
  import { Board } from "gigachess";
159
223
 
160
- // Replay full games at 4.8M plies/s from compact 16-bit buffers:
224
+ // Replay full games from compact 16-bit buffers:
161
225
  const moves = new Uint16Array([ /* packed 16-bit moves */ ]);
162
- const board = Board.fromMoves2(moves);
226
+ const board = Board.fromMoves2Trusted(moves); // trusted, already-validated data
227
+
228
+ // Files, network input and imported bytes should use the checked API:
229
+ const safeBoard = Board.fromMoves2Checked(moves);
230
+ // It rejects illegal moves (and truncated byte words) rather than mutating
231
+ // the board into an invalid position. Little-endian Uint8Array views with an
232
+ // odd byte offset are supported, too.
163
233
  ```
164
234
 
165
235
  ---
166
236
 
167
237
  ## 🔬 Under the Hood: Why GigaChess is Fast
168
238
 
169
- 1. **In-Place Bitboard Mutation**: Unlike engines that clone full state on every move, `Board` mutates bitboards in-place and returns a compact `Undo` for instant $O(1)$ rollback.
170
- 2. **Zero-BigInt 32-bit Integer Pairs**: 64-bit `BigInt` forces object allocation on the heap. GigaChess executes all bitboards as 32-bit unsigned integer pairs (`lo >>> 0`, `hi >>> 0`), running directly in CPU registers.
239
+ 1. **In-Place Bitboard Mutation**: Unlike engines that clone full state on every move, `Board` mutates bitboards in-place and uses a caller-owned Board96 snapshot for instant $O(1)$ rollback.
240
+ 2. **32-bit integer pairs**: Bitboards use unsigned low/high words and typed lookup tables, avoiding BigInt arithmetic in hot move-generation loops.
171
241
  3. **Stockfish Single-Pass Pin Analysis (`CheckContext`)**: Checkers and pin lines are computed once per position, turning legal move validation into fast bitwise intersections.
172
- 4. **16-bit Unboxed Small Integers (Smis)**: Packed moves are stored as 16-bit integers, bypassing garbage collection pauses.
242
+ 4. **Compact packed moves**: Independent Uint16Array results and caller-owned buffer APIs reduce allocation; no internal move-list cache.
243
+ 5. **Compact sliding tables and perft state**: Split-half occupancy lookups, exact cold ray fallback, and independent compact perft state.
244
+ 6. **Reusable canonical initial position**: Independent mutable state per board, plus less allocation in FEN and SAN hot paths.
173
245
 
174
246
  ---
175
247
 
176
248
  ## 📜 License
177
249
 
178
250
  MIT © [Itshak](https://github.com/itshak) & [GigaChess Contributors](https://github.com/itshak/gigachess/graphs/contributors).
251
+
252
+ ---
253
+
254
+ ## Cross-language correctness and maintenance
255
+
256
+ The pure-TypeScript engine and [gigachess-rs](https://github.com/itshak/gigachess-rs)
257
+ are separate implementations. JavaScript has **no WebAssembly startup or
258
+ runtime dependency**. Both share the canonical 96-byte Board96 v1 binary format and 16-bit moves2, king-to-rook
259
+ castling, null sentinel `0xffff`, Polyglot vectors and Chess960 rook-file hash
260
+ seed. See the [mirrored core contract](openspec/changes/compact-core-rust-parity-v0.7.0/specs/mirrored-core-contract/spec.md)
261
+ and the shared `tests/position-keys-v1.tsv` / `tests/moves2-v1.tsv` fixtures.
262
+
263
+ Benchmark numbers above describe specific workloads on specific hardware; they
264
+ are not a universal ranking across every JavaScript/WASM chess engine. For an
265
+ apples-to-apples pure TypeScript comparison and planned performance experiments,
266
+ see the [maintenance research](docs/research/superseded-openspec/dual-engine-hardening-20261123/research.md).
package/dist/attacks.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as sq from "./squareSet.js";
1
2
  import type { SquareSet } from "./squareSet.js";
2
3
  import { Color } from "./types.js";
3
4
  export declare function knightAttacks(sqIdx: number): SquareSet;
@@ -6,17 +7,17 @@ export declare function pawnAttacks(color: Color, sqIdx: number): SquareSet;
6
7
  /**
7
8
  * Lazy-load hook (task 3.3): dynamically imports the generated blob modules,
8
9
  * decodes them into Uint32Array views, and swaps the sliding-attack path from
9
- * the naive fallback to the magic tables. Idempotent and concurrency-safe:
10
+ * the synchronous ray fallback to the perfect-hash tables. Idempotent and concurrency-safe:
10
11
  * concurrent callers share one in-flight load. Callers may `await` it or
11
12
  * fire-and-forget (pre-warm at app startup, non-blocking); until it resolves,
12
- * the naive ray-walk fallback serves and stays ≥1.5× baseline.
13
+ * the synchronous nearest-blocker fallback serves.
13
14
  */
14
15
  export declare function ensureMagicTablesLoaded(): Promise<void>;
15
- /** Whether the magic tables are loaded (false ⇒ naive fallback in use). */
16
+ /** Whether the magic tables are loaded (false ⇒ synchronous fallback in use). */
16
17
  export declare function magicTablesLoaded(): boolean;
17
18
  export declare function bishopAttacks(sqIdx: number, occupied: SquareSet): SquareSet;
18
19
  export declare function rookAttacks(sqIdx: number, occupied: SquareSet): SquareSet;
19
- export declare function queenAttacks(sqIdx: number, occupied: SquareSet): SquareSet;
20
+ export declare function queenAttacks(s: number, occ: SquareSet): SquareSet;
20
21
  declare function bishopAttacksNaive(sqIdx: number, occ: SquareSet): SquareSet;
21
22
  declare function rookAttacksNaive(sqIdx: number, occ: SquareSet): SquareSet;
22
23
  export declare const _naive: {
@@ -28,15 +29,25 @@ export declare function between(from: number, to: number): SquareSet;
28
29
  export declare const LINE_RAY_LO: Uint32Array<ArrayBuffer>;
29
30
  export declare const LINE_RAY_HI: Uint32Array<ArrayBuffer>;
30
31
  export declare function lineRay(from: number, to: number): SquareSet;
32
+ export declare const emptyRookRays: sq.SquareSet[];
33
+ export declare const emptyBishopRays: sq.SquareSet[];
31
34
  /**
32
35
  * All pieces of `attacker` color attacking `square`. `occ` overrides the
33
36
  * occupancy used for slider rays (hot-loop variant: king-safety masks
34
37
  * evaluate attackedness with the moving king removed from the occupancy so
35
38
  * that sliders x-raying the king stay "attacking" through its old square).
36
39
  */
37
- export declare function attackersTo(board: import("./board.js").BoardLike, square: number, attacker: Color, occ?: SquareSet): SquareSet;
38
- export declare function isAttacked(board: import("./board.js").BoardLike, square: number, attacker: Color): boolean;
39
- export declare function kingAttackers(board: import("./board.js").BoardLike, kingColor: Color): SquareSet;
40
+ export declare function attackersTo(board: import("./setupBoard.js").BoardLike, square: number, attacker: Color, occ?: SquareSet): SquareSet;
41
+ export declare function isAttacked(board: import("./setupBoard.js").BoardLike, square: number, attacker: Color): boolean;
42
+ /**
43
+ * Union of enemy attacks with a supplied occupancy. Most callers need to
44
+ * ask only about the eight king destinations. Unlike eight independent
45
+ * attackersTo lookups, one pass through actual enemy pieces reuses each
46
+ * sliding attack once. Includes pinned enemy attacks per FIDE king safety.
47
+ * This function only reads board state; all accumulators are local.
48
+ */
49
+ export declare function attackedSquares(board: import("./setupBoard.js").BoardLike, attacker: Color, occ?: SquareSet): SquareSet;
50
+ export declare function kingAttackers(board: import("./setupBoard.js").BoardLike, kingColor: Color): SquareSet;
40
51
  export declare function rookAttacksForTest(sqIdx: number, occ: SquareSet): SquareSet;
41
52
  export declare function bishopAttacksForTest(sqIdx: number, occ: SquareSet): SquareSet;
42
53
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"attacks.d.ts","sourceRoot":"","sources":["../src/attacks.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAiInC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEtD;AACD,wBAAgB,WAAW,CAAC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