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.
- package/README.md +142 -54
- package/dist/attacks.d.ts +18 -7
- package/dist/attacks.d.ts.map +1 -1
- package/dist/attacks.js +197 -89
- package/dist/bishopSplit32Blob.d.ts +2 -0
- package/dist/bishopSplit32Blob.d.ts.map +1 -0
- package/dist/bishopSplit32Blob.js +2 -0
- package/dist/castling.d.ts +2 -0
- package/dist/castling.d.ts.map +1 -1
- package/dist/castling.js +27 -12
- package/dist/chess960.d.ts +2 -9
- package/dist/chess960.d.ts.map +1 -1
- package/dist/chess960.js +2 -18
- package/dist/chessjs.d.ts +1 -1
- package/dist/chessjs.d.ts.map +1 -1
- package/dist/chessjs.js +1 -1
- package/dist/chessops/board.d.ts +1 -1
- package/dist/chessops/board.d.ts.map +1 -1
- package/dist/chessops/board.js +1 -1
- package/dist/chessops/chess.d.ts +6 -10
- package/dist/chessops/chess.d.ts.map +1 -1
- package/dist/chessops/chess.js +73 -97
- package/dist/chessops/convert.d.ts +1 -1
- package/dist/chessops/convert.d.ts.map +1 -1
- package/dist/chessops/convert.js +1 -1
- package/dist/chessops/debug.d.ts.map +1 -1
- package/dist/chessops/debug.js +7 -0
- package/dist/chessops/fen.d.ts.map +1 -1
- package/dist/chessops/fen.js +13 -2
- package/dist/chessops/fenInternal.d.ts +1 -1
- package/dist/chessops/fenInternal.d.ts.map +1 -1
- package/dist/chessops/fenInternal.js +1 -1
- package/dist/chessops/nativeBridge.d.ts +14 -0
- package/dist/chessops/nativeBridge.d.ts.map +1 -0
- package/dist/chessops/nativeBridge.js +87 -0
- package/dist/chessops/san.d.ts.map +1 -1
- package/dist/chessops/san.js +12 -10
- package/dist/chesstree.d.ts.map +1 -1
- package/dist/chesstree.js +23 -62
- package/dist/core.d.ts +6 -8
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +5 -10
- package/dist/fast/bishopSplit32Blob-NOHWZEWR.js +1 -0
- package/dist/fast/index.js +1 -0
- package/dist/fast/rookSplit32Blob-C3ANUNTJ.js +1 -0
- package/dist/fast/zobristBlob-HIMMLZLJ.js +1 -0
- package/dist/fast.d.ts +2 -0
- package/dist/fast.d.ts.map +1 -0
- package/dist/fast.js +2 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -19
- package/dist/native96.d.ts +16 -0
- package/dist/native96.d.ts.map +1 -0
- package/dist/native96.js +6 -0
- package/dist/nativeBoard96.d.ts +118 -0
- package/dist/nativeBoard96.d.ts.map +1 -0
- package/dist/nativeBoard96.js +1077 -0
- package/dist/nativeChess.d.ts +97 -0
- package/dist/nativeChess.d.ts.map +1 -0
- package/dist/nativeChess.js +201 -0
- package/dist/nativeMovegen96.d.ts +2 -0
- package/dist/nativeMovegen96.d.ts.map +1 -0
- package/dist/nativeMovegen96.js +282 -0
- package/dist/nativePublicTypes.d.ts +3 -0
- package/dist/nativePublicTypes.d.ts.map +1 -0
- package/dist/nativePublicTypes.js +1 -0
- package/dist/perftCompact.d.ts +10 -0
- package/dist/perftCompact.d.ts.map +1 -0
- package/dist/perftCompact.js +420 -0
- package/dist/pgn.d.ts +2 -3
- package/dist/pgn.d.ts.map +1 -1
- package/dist/pgn.js +2 -5
- package/dist/rookSplit32Blob.d.ts +2 -0
- package/dist/rookSplit32Blob.d.ts.map +1 -0
- package/dist/rookSplit32Blob.js +2 -0
- package/dist/setupBoard.d.ts +54 -0
- package/dist/setupBoard.d.ts.map +1 -0
- package/dist/setupBoard.js +249 -0
- package/dist/{fen.d.ts → setupFen.d.ts} +1 -1
- package/dist/setupFen.d.ts.map +1 -0
- package/dist/{fen.js → setupFen.js} +140 -125
- package/dist/squareSet.d.ts +2 -0
- package/dist/squareSet.d.ts.map +1 -1
- package/dist/squareSet.js +6 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/zobrist.d.ts +2 -2
- package/dist/zobrist.d.ts.map +1 -1
- package/dist/zobrist.js +17 -15
- package/package.json +18 -6
- package/dist/bishopMagicBlob.d.ts +0 -2
- package/dist/bishopMagicBlob.d.ts.map +0 -1
- package/dist/bishopMagicBlob.js +0 -11
- package/dist/board.d.ts +0 -216
- package/dist/board.d.ts.map +0 -1
- package/dist/board.js +0 -1088
- package/dist/chess.d.ts +0 -252
- package/dist/chess.d.ts.map +0 -1
- package/dist/chess.js +0 -1930
- package/dist/fen.d.ts.map +0 -1
- package/dist/rookMagicBlob.d.ts +0 -2
- package/dist/rookMagicBlob.d.ts.map +0 -1
- package/dist/rookMagicBlob.js +0 -11
- package/dist/san.d.ts +0 -38
- package/dist/san.d.ts.map +0 -1
- 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>
|
|
9
|
-
|
|
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
|
-
##
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 =
|
|
96
|
+
const board = Board.fromFen();
|
|
54
97
|
|
|
55
|
-
// Parse SAN and execute
|
|
98
|
+
// Parse SAN and execute a legal move
|
|
56
99
|
const move = board.parseSan("e4");
|
|
57
|
-
|
|
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
|
-
##
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
|
76
|
-
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
|
|
|
114
|
+
## Performance comparisons (0.6.0)
|
|
115
|
+
|
|
116
|
+

|
|
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
|
-
|
|
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 =
|
|
168
|
+
const board = Board.fromFen();
|
|
115
169
|
|
|
116
|
-
//
|
|
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
|
|
175
|
+
// Or write into a reusable caller-owned buffer without list allocation:
|
|
122
176
|
const buffer = new Uint16Array(256);
|
|
123
|
-
const count = board.
|
|
177
|
+
const count = board.legalMovesInto(buffer);
|
|
124
178
|
```
|
|
125
179
|
|
|
126
180
|
### 2. Game State & Terminal Checks
|
|
127
181
|
```ts
|
|
128
|
-
const 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.
|
|
187
|
+
board.isSeventyFiveMoveDraw(); // false
|
|
134
188
|
board.isInsufficientMaterial();// false
|
|
135
|
-
board.turn; // 0 =
|
|
189
|
+
board.turn; // 0 = Black, 1 = White
|
|
136
190
|
```
|
|
137
191
|
|
|
138
192
|
### 3. Incremental Polyglot Zobrist Hashing
|
|
139
193
|
```ts
|
|
140
|
-
|
|
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
|
|
224
|
+
// Replay full games from compact 16-bit buffers:
|
|
161
225
|
const moves = new Uint16Array([ /* packed 16-bit moves */ ]);
|
|
162
|
-
const board = Board.
|
|
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
|
|
170
|
-
2. **
|
|
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. **
|
|
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
|
|
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
|
|
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 ⇒
|
|
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(
|
|
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("./
|
|
38
|
-
export declare function isAttacked(board: import("./
|
|
39
|
-
|
|
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 {};
|
package/dist/attacks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attacks.d.ts","sourceRoot":"","sources":["../src/attacks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attacks.d.ts","sourceRoot":"","sources":["../src/attacks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAiFnC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEtD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAEpD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAA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