gigachess 0.2.1 → 0.4.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 +103 -108
- package/dist/attacks.d.ts +6 -3
- package/dist/attacks.d.ts.map +1 -1
- package/dist/attacks.js +45 -1
- package/dist/board.d.ts +111 -45
- package/dist/board.d.ts.map +1 -1
- package/dist/board.js +747 -14
- package/dist/castling.d.ts +41 -0
- package/dist/castling.d.ts.map +1 -0
- package/dist/castling.js +267 -0
- package/dist/chess.d.ts +30 -28
- package/dist/chess.d.ts.map +1 -1
- package/dist/chess.js +835 -458
- package/dist/chess960.d.ts +1 -1
- package/dist/chess960.d.ts.map +1 -1
- package/dist/chess960.js +2 -2
- package/dist/chessjs.d.ts +13 -0
- package/dist/chessjs.d.ts.map +1 -0
- package/dist/chessjs.js +23 -0
- package/dist/chessops/board.d.ts +1 -1
- package/dist/chessops/board.d.ts.map +1 -1
- package/dist/chessops/chess.js +1 -1
- package/dist/chessops/convert.d.ts +1 -1
- package/dist/chessops/convert.d.ts.map +1 -1
- package/dist/chessops/convert.js +1 -6
- package/dist/chessops/fenInternal.d.ts +1 -1
- package/dist/chessops/fenInternal.d.ts.map +1 -1
- package/dist/chessops/fenInternal.js +2 -2
- package/dist/chessops/index.js +2 -2
- package/dist/chessops/setup.js +1 -1
- package/dist/chessops/types.js +1 -1
- package/dist/chesstree.d.ts +1 -1
- package/dist/chesstree.d.ts.map +1 -1
- package/dist/chesstree.js +5 -5
- package/dist/core.d.ts +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -2
- package/dist/fen.d.ts.map +1 -1
- package/dist/fen.js +84 -48
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/packedMove.js +2 -2
- package/dist/san.d.ts.map +1 -1
- package/dist/san.js +148 -172
- package/dist/squareSet.js +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/zobrist.d.ts +22 -0
- package/dist/zobrist.d.ts.map +1 -1
- package/dist/zobrist.js +107 -36
- package/dist/zobristBlob.js +1 -1
- package/package.json +8 -6
package/dist/san.js
CHANGED
|
@@ -3,45 +3,15 @@
|
|
|
3
3
|
import * as sq from "./squareSet.js";
|
|
4
4
|
import * as board from "./board.js";
|
|
5
5
|
import * as chess from "./chess.js";
|
|
6
|
+
import * as attacks from "./attacks.js";
|
|
6
7
|
import { Color, Role } from "./types.js";
|
|
7
8
|
import { Err, Ok } from "./types.js";
|
|
8
9
|
import { squareFile, squareRank, parseSquare, squareName } from "./util.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
case Role.Bishop: return "B";
|
|
15
|
-
case Role.Knight: return "N";
|
|
16
|
-
case Role.Pawn: return "";
|
|
17
|
-
default: return "";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function sanCharToRole(ch) {
|
|
21
|
-
if (ch === "K")
|
|
22
|
-
return Role.King;
|
|
23
|
-
if (ch === "Q")
|
|
24
|
-
return Role.Queen;
|
|
25
|
-
if (ch === "R")
|
|
26
|
-
return Role.Rook;
|
|
27
|
-
if (ch === "B")
|
|
28
|
-
return Role.Bishop;
|
|
29
|
-
if (ch === "N")
|
|
30
|
-
return Role.Knight;
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
function promoCharToRole(ch) {
|
|
34
|
-
const c = ch.toUpperCase();
|
|
35
|
-
if (c === "Q")
|
|
36
|
-
return Role.Queen;
|
|
37
|
-
if (c === "R")
|
|
38
|
-
return Role.Rook;
|
|
39
|
-
if (c === "B")
|
|
40
|
-
return Role.Bishop;
|
|
41
|
-
if (c === "N")
|
|
42
|
-
return Role.Knight;
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
10
|
+
const ROLE_SAN = ["", "N", "B", "R", "Q", "K"];
|
|
11
|
+
const roleToSanChar = (role) => ROLE_SAN[role] ?? "";
|
|
12
|
+
const SAN_ROLES = { K: Role.King, Q: Role.Queen, R: Role.Rook, B: Role.Bishop, N: Role.Knight };
|
|
13
|
+
const sanCharToRole = (ch) => SAN_ROLES[ch];
|
|
14
|
+
const promoCharToRole = (ch) => SAN_ROLES[ch.toUpperCase()];
|
|
45
15
|
function normalizeCastlingSan(s) {
|
|
46
16
|
// tolerant 0-0 -> O-O
|
|
47
17
|
return s.replace(/0-0-0/g, "O-O-O").replace(/0-0/g, "O-O");
|
|
@@ -64,10 +34,12 @@ export function makeSan(move, pos) {
|
|
|
64
34
|
let base = isKingSide ? "O-O" : "O-O-O";
|
|
65
35
|
// add check suffix
|
|
66
36
|
const next = chess.makeMove(pos, move);
|
|
67
|
-
if (chess.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
37
|
+
if (chess.isCheck(next)) {
|
|
38
|
+
if (chess.isCheckmate(next))
|
|
39
|
+
base += "#";
|
|
40
|
+
else
|
|
41
|
+
base += "+";
|
|
42
|
+
}
|
|
71
43
|
return base;
|
|
72
44
|
}
|
|
73
45
|
const piece = board.pieceAt(pos.board, move.from);
|
|
@@ -105,37 +77,41 @@ export function makeSan(move, pos) {
|
|
|
105
77
|
}
|
|
106
78
|
// Disambiguation for non-pawn (and pawn capture already handled)
|
|
107
79
|
if (piece.role !== Role.Pawn) {
|
|
108
|
-
// Find
|
|
80
|
+
// Find other pieces of same role/color that can legally move to same destination
|
|
109
81
|
const candidates = [];
|
|
110
82
|
const own = pos.turn === Color.White ? pos.board.white : pos.board.black;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
83
|
+
let attackers;
|
|
84
|
+
switch (piece.role) {
|
|
85
|
+
case Role.Knight:
|
|
86
|
+
attackers = sq.and(attacks.knightAttacks(move.to), sq.and(own, pos.board.knight));
|
|
87
|
+
break;
|
|
88
|
+
case Role.Bishop:
|
|
89
|
+
attackers = sq.and(attacks.bishopAttacks(move.to, pos.board.occupied), sq.and(own, pos.board.bishop));
|
|
90
|
+
break;
|
|
91
|
+
case Role.Rook:
|
|
92
|
+
attackers = sq.and(attacks.rookAttacks(move.to, pos.board.occupied), sq.and(own, pos.board.rook));
|
|
93
|
+
break;
|
|
94
|
+
case Role.Queen:
|
|
95
|
+
attackers = sq.and(attacks.queenAttacks(move.to, pos.board.occupied), sq.and(own, pos.board.queen));
|
|
96
|
+
break;
|
|
97
|
+
case Role.King:
|
|
98
|
+
attackers = sq.and(attacks.kingAttacks(move.to), sq.and(own, pos.board.king));
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
attackers = sq.EMPTY;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
const otherAttackers = sq.minus(attackers, sq.singleton(move.from));
|
|
105
|
+
if (!sq.isEmpty(otherAttackers)) {
|
|
106
|
+
const ctx = chess.analyzeCheckContext(pos);
|
|
107
|
+
for (const sqIdx of sq.iter(otherAttackers)) {
|
|
108
|
+
const cand = board.pieceAt(pos.board, sqIdx);
|
|
109
|
+
if (!cand)
|
|
110
|
+
continue;
|
|
111
|
+
const d = chess.destsFast(pos, sqIdx, cand, ctx);
|
|
112
|
+
if (sq.has(d, move.to))
|
|
113
|
+
candidates.push(sqIdx);
|
|
120
114
|
}
|
|
121
|
-
})();
|
|
122
|
-
const sameRole = sq.and(own, roleSet);
|
|
123
|
-
// CheckContext reuse (design D4): the position's check/pin masks are
|
|
124
|
-
// computed ONCE per makeSan call and shared across every candidate
|
|
125
|
-
// piece's dest evaluation, instead of re-running the full
|
|
126
|
-
// analyzeCheckContext inside chess.dests() per candidate — O(N x movegen)
|
|
127
|
-
// becomes O(N) with one shared context. Zero allocation beyond the
|
|
128
|
-
// context itself; SAN output is byte-identical (same destsFast semantics).
|
|
129
|
-
const ctx = chess.analyzeCheckContext(pos);
|
|
130
|
-
for (const sqIdx of sq.iter(sameRole)) {
|
|
131
|
-
if (sqIdx === move.from)
|
|
132
|
-
continue;
|
|
133
|
-
const cand = board.pieceAt(pos.board, sqIdx);
|
|
134
|
-
if (!cand)
|
|
135
|
-
continue;
|
|
136
|
-
const d = chess.destsFast(pos, sqIdx, cand, ctx);
|
|
137
|
-
if (sq.has(d, move.to))
|
|
138
|
-
candidates.push(sqIdx);
|
|
139
115
|
}
|
|
140
116
|
// Include moving piece itself, total candidates +1 = all that can reach dest
|
|
141
117
|
// If there is any other candidate, need disambiguation
|
|
@@ -202,10 +178,12 @@ export function makeSan(move, pos) {
|
|
|
202
178
|
}
|
|
203
179
|
// Check / mate suffix
|
|
204
180
|
const next = chess.makeMove(pos, move);
|
|
205
|
-
if (chess.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
181
|
+
if (chess.isCheck(next)) {
|
|
182
|
+
if (chess.isCheckmate(next))
|
|
183
|
+
san += "#";
|
|
184
|
+
else
|
|
185
|
+
san += "+";
|
|
186
|
+
}
|
|
209
187
|
return san;
|
|
210
188
|
}
|
|
211
189
|
// ---------- parseSan ----------
|
|
@@ -314,120 +292,118 @@ export function parseSan(san, pos) {
|
|
|
314
292
|
// For pawn, pieceRole is pawn, but rest may be file for capture (like "e" in exd5)
|
|
315
293
|
// Our disamb handling already captured that: for "exd5", rest after removing piece (none) and capture, rest = "e" => disambFile = 'e' . Good.
|
|
316
294
|
// For pawn push "e4", rest = "" => no disamb.
|
|
317
|
-
//
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
continue;
|
|
295
|
+
// Targeted reverse attacker lookup
|
|
296
|
+
const us = pos.turn;
|
|
297
|
+
const own = us === Color.White ? pos.board.white : pos.board.black;
|
|
298
|
+
const candidateFroms = [];
|
|
299
|
+
if (pieceRole === Role.Pawn) {
|
|
300
|
+
// 1. Pawn pushes
|
|
301
|
+
const pushFrom = us === Color.White ? to - 8 : to + 8;
|
|
302
|
+
if (pushFrom >= 0 && pushFrom < 64 && !board.pieceAt(pos.board, to)) {
|
|
303
|
+
const p = board.pieceAt(pos.board, pushFrom);
|
|
304
|
+
if (p && p.color === us && p.role === Role.Pawn)
|
|
305
|
+
candidateFroms.push(pushFrom);
|
|
329
306
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
307
|
+
if (us === Color.White && squareRank(to) === 3) {
|
|
308
|
+
const dblFrom = to - 16;
|
|
309
|
+
if (!board.pieceAt(pos.board, to) && !board.pieceAt(pos.board, to - 8)) {
|
|
310
|
+
const p = board.pieceAt(pos.board, dblFrom);
|
|
311
|
+
if (p && p.color === us && p.role === Role.Pawn)
|
|
312
|
+
candidateFroms.push(dblFrom);
|
|
313
|
+
}
|
|
333
314
|
}
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// promotion
|
|
342
|
-
if (promotion !== undefined) {
|
|
343
|
-
if (m.promotion !== promotion)
|
|
344
|
-
continue;
|
|
315
|
+
else if (us === Color.Black && squareRank(to) === 4) {
|
|
316
|
+
const dblFrom = to + 16;
|
|
317
|
+
if (!board.pieceAt(pos.board, to) && !board.pieceAt(pos.board, to + 8)) {
|
|
318
|
+
const p = board.pieceAt(pos.board, dblFrom);
|
|
319
|
+
if (p && p.color === us && p.role === Role.Pawn)
|
|
320
|
+
candidateFroms.push(dblFrom);
|
|
321
|
+
}
|
|
345
322
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
323
|
+
// 2. Pawn diagonal attacks (normal captures or en-passant)
|
|
324
|
+
const pAtt = attacks.pawnAttacks(us === Color.White ? Color.Black : Color.White, to);
|
|
325
|
+
const pawnCaps = sq.and(pAtt, sq.and(own, pos.board.pawn));
|
|
326
|
+
for (const sqIdx of sq.iter(pawnCaps)) {
|
|
327
|
+
candidateFroms.push(sqIdx);
|
|
349
328
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
let attackers;
|
|
332
|
+
switch (pieceRole) {
|
|
333
|
+
case Role.Knight:
|
|
334
|
+
attackers = sq.and(attacks.knightAttacks(to), sq.and(own, pos.board.knight));
|
|
335
|
+
break;
|
|
336
|
+
case Role.Bishop:
|
|
337
|
+
attackers = sq.and(attacks.bishopAttacks(to, pos.board.occupied), sq.and(own, pos.board.bishop));
|
|
338
|
+
break;
|
|
339
|
+
case Role.Rook:
|
|
340
|
+
attackers = sq.and(attacks.rookAttacks(to, pos.board.occupied), sq.and(own, pos.board.rook));
|
|
341
|
+
break;
|
|
342
|
+
case Role.Queen:
|
|
343
|
+
attackers = sq.and(attacks.queenAttacks(to, pos.board.occupied), sq.and(own, pos.board.queen));
|
|
344
|
+
break;
|
|
345
|
+
case Role.King:
|
|
346
|
+
attackers = sq.and(attacks.kingAttacks(to), sq.and(own, pos.board.king));
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
attackers = sq.EMPTY;
|
|
350
|
+
break;
|
|
355
351
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (r !== disambRank)
|
|
359
|
-
continue;
|
|
352
|
+
for (const sqIdx of sq.iter(attackers)) {
|
|
353
|
+
candidateFroms.push(sqIdx);
|
|
360
354
|
}
|
|
361
|
-
|
|
355
|
+
}
|
|
356
|
+
// Disambiguation filtering
|
|
357
|
+
let filteredFroms = candidateFroms;
|
|
358
|
+
if (disambFile !== null) {
|
|
359
|
+
const reqFile = disambFile.charCodeAt(0) - 97;
|
|
360
|
+
filteredFroms = filteredFroms.filter(f => squareFile(f) === reqFile);
|
|
361
|
+
}
|
|
362
|
+
if (disambRank !== null) {
|
|
363
|
+
const reqRank = disambRank.charCodeAt(0) - 49;
|
|
364
|
+
filteredFroms = filteredFroms.filter(f => squareRank(f) === reqRank);
|
|
365
|
+
}
|
|
366
|
+
if (filteredFroms.length === 0)
|
|
367
|
+
return Err({ code: "san/noLegalMove" });
|
|
368
|
+
// Legality filtering with single shared check context
|
|
369
|
+
const ctx = chess.analyzeCheckContext(pos);
|
|
370
|
+
const candidates = [];
|
|
371
|
+
const destRank = squareRank(to);
|
|
372
|
+
for (const from of filteredFroms) {
|
|
373
|
+
const fromPiece = board.pieceAt(pos.board, from);
|
|
374
|
+
if (!fromPiece)
|
|
375
|
+
continue;
|
|
376
|
+
const isPromo = fromPiece.role === Role.Pawn && (destRank === 0 || destRank === 7);
|
|
377
|
+
if (isPromo && promotion === undefined)
|
|
378
|
+
continue;
|
|
379
|
+
if (!isPromo && promotion !== undefined)
|
|
380
|
+
continue;
|
|
381
|
+
const d = chess.destsFast(pos, from, fromPiece, ctx);
|
|
382
|
+
if (!sq.has(d, to))
|
|
383
|
+
continue;
|
|
384
|
+
let isEnPassant = false;
|
|
385
|
+
if (fromPiece.role === Role.Pawn && pos.epSquare !== null && to === pos.epSquare) {
|
|
386
|
+
const fileDiff = Math.abs(squareFile(to) - squareFile(from));
|
|
387
|
+
const dir = fromPiece.color === Color.White ? 1 : -1;
|
|
388
|
+
if (fileDiff === 1 && destRank - squareRank(from) === dir)
|
|
389
|
+
isEnPassant = true;
|
|
390
|
+
}
|
|
391
|
+
candidates.push({
|
|
392
|
+
from,
|
|
393
|
+
to,
|
|
394
|
+
promotion: isPromo ? (promotion ?? Role.Queen) : null,
|
|
395
|
+
isPromotion: isPromo,
|
|
396
|
+
isEnPassant,
|
|
397
|
+
isCastling: false,
|
|
398
|
+
});
|
|
362
399
|
}
|
|
363
400
|
if (candidates.length === 0)
|
|
364
401
|
return Err({ code: "san/noLegalMove" });
|
|
365
402
|
if (candidates.length > 1)
|
|
366
403
|
return Err({ code: "san/ambiguous" });
|
|
367
404
|
const chosen = candidates[0];
|
|
368
|
-
// Optionally validate check suffix: if suffix present but after play check status mismatches, should we error? For now ignore, but we could validate
|
|
369
|
-
// If suffix is '+' but resulting pos not check, or '#' but not mate, should we error? Spec says SAN includes +/# based on resulting position, so we could validate but not required for parsing
|
|
370
|
-
// We'll optionally validate if suffix present
|
|
371
|
-
if (checkSuffix) {
|
|
372
|
-
const next = chess.makeMove(pos, chosen);
|
|
373
|
-
const isMate = chess.isCheckmate(next);
|
|
374
|
-
const isChk = chess.isCheck(next);
|
|
375
|
-
if (checkSuffix === "+" && !isChk) {
|
|
376
|
-
// SAN claims check but not check -> still treat as illegal? We could ignore
|
|
377
|
-
}
|
|
378
|
-
if (checkSuffix === "#" && !isMate) {
|
|
379
|
-
// mismatch
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
405
|
return Ok(chosen);
|
|
383
406
|
}
|
|
384
|
-
// helper to generate legal moves for SAN matching (includes all promotion variants)
|
|
385
|
-
function genLegalMovesForSan(pos) {
|
|
386
|
-
// Use chess genLegalMoves internal? We can call chess.perft helper? But chess.genLegalMoves is not exported (private). We need to replicate or expose.
|
|
387
|
-
// For now, we will generate via allDests and then expand promotions
|
|
388
|
-
// Simpler: use chess.allDests and then for each destination, create Move(s) and test isLegal via chess.isLegal? But we need Move objects with promotion etc.
|
|
389
|
-
// We'll generate via iterating allDests and handling promotion expansion
|
|
390
|
-
const moves = [];
|
|
391
|
-
const all = chess.allDests(pos);
|
|
392
|
-
for (const [from, set] of all) {
|
|
393
|
-
for (const to of sq.iter(set)) {
|
|
394
|
-
const piece = board.pieceAt(pos.board, from);
|
|
395
|
-
if (!piece)
|
|
396
|
-
continue;
|
|
397
|
-
const destRank = squareRank(to);
|
|
398
|
-
const isPromo = piece.role === Role.Pawn && (destRank === 0 || destRank === 7);
|
|
399
|
-
if (isPromo) {
|
|
400
|
-
for (const promo of [Role.Queen, Role.Rook, Role.Bishop, Role.Knight]) {
|
|
401
|
-
const isEnPassant = false;
|
|
402
|
-
// pawn promotion capture is also capture, but set already includes captures
|
|
403
|
-
const target = board.pieceAt(pos.board, to);
|
|
404
|
-
const isCap = !!target || (pos.epSquare === to);
|
|
405
|
-
// Actually en passant to back rank not possible
|
|
406
|
-
const mv = { from, to, promotion: promo, isPromotion: true, isEnPassant: false, isCastling: false };
|
|
407
|
-
// Need to set isEnPassant correctly for pawn promo capture en passant? Not needed
|
|
408
|
-
moves.push(mv);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
const target = board.pieceAt(pos.board, to);
|
|
413
|
-
let isEnPassant = false;
|
|
414
|
-
if (piece.role === Role.Pawn && pos.epSquare !== null && to === pos.epSquare) {
|
|
415
|
-
const fileDiff = Math.abs(squareFile(to) - squareFile(from));
|
|
416
|
-
const dir = piece.color === Color.White ? 1 : -1;
|
|
417
|
-
if (fileDiff === 1 && destRank - squareRank(from) === dir)
|
|
418
|
-
isEnPassant = true;
|
|
419
|
-
}
|
|
420
|
-
let isCastling = false;
|
|
421
|
-
if (piece.role === Role.King) {
|
|
422
|
-
// Shared detectCastling path (design D2) — no dest-heuristic here.
|
|
423
|
-
isCastling = chess.detectCastling(pos, from, to) !== null;
|
|
424
|
-
}
|
|
425
|
-
moves.push({ from, to, promotion: null, isPromotion: false, isEnPassant, isCastling });
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return moves;
|
|
430
|
-
}
|
|
431
407
|
// ---------- UCI ----------
|
|
432
408
|
export function parseUci(uci) {
|
|
433
409
|
const s = uci.trim();
|
package/dist/squareSet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/squareSet.ts — {lo,hi} pair, pure ops, target ES2020
|
|
2
2
|
// Language-neutral spec: lo bits 0..31 -> A1..H4, hi bits 0..31 -> A5..H8
|
|
3
|
-
// MIT
|
|
3
|
+
// MIT gigachess, clean-room from specs + FIDE notes + magic-bits/RecklessMagics JSON (no G P L)
|
|
4
4
|
// Constants — note >>>0 ensures unsigned 32
|
|
5
5
|
export const EMPTY = { lo: 0, hi: 0 };
|
|
6
6
|
export const FULL = { lo: 0xffffffff >>> 0, hi: 0xffffffff >>> 0 };
|
package/dist/types.d.ts
CHANGED
|
@@ -88,9 +88,10 @@ export type CastlingRights = {
|
|
|
88
88
|
readonly whiteQueen: boolean;
|
|
89
89
|
readonly blackKing: boolean;
|
|
90
90
|
readonly blackQueen: boolean;
|
|
91
|
+
readonly mask?: number;
|
|
91
92
|
};
|
|
92
93
|
export type Setup = {
|
|
93
|
-
readonly board: import("./board.js").
|
|
94
|
+
readonly board: import("./board.js").BoardLike;
|
|
94
95
|
readonly turn: Color;
|
|
95
96
|
readonly castling: CastlingRights;
|
|
96
97
|
readonly epSquare: number | null;
|
|
@@ -100,6 +101,10 @@ export type Setup = {
|
|
|
100
101
|
readonly fullmove?: number;
|
|
101
102
|
readonly zobristLo?: number;
|
|
102
103
|
readonly zobristHi?: number;
|
|
104
|
+
readonly castlingMask?: number;
|
|
105
|
+
readonly isChess960?: boolean;
|
|
106
|
+
readonly kingSq?: readonly [number, number];
|
|
107
|
+
readonly checkers?: import("./squareSet.js").SquareSet;
|
|
103
108
|
};
|
|
104
109
|
export type Position = Setup;
|
|
105
110
|
export type NormalMove = {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,0BAAkB,KAAK;IACrB,KAAK,IAAI;IACT,KAAK,IAAI;CACV;AAED,0BAAkB,IAAI;IACpB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,MAAM,IAAI;IACV,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;CACT;AAED,0BAAkB,MAAM;IACtB,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,IAAI;IAC9D,EAAE,IAAI;IAAE,EAAE,IAAI;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IA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E,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE5E,wBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAE/C;AACD,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAEhD;AAGD,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/zobrist.d.ts
CHANGED
|
@@ -4,6 +4,18 @@ export type ZobristKey = {
|
|
|
4
4
|
readonly lo: number;
|
|
5
5
|
readonly hi: number;
|
|
6
6
|
};
|
|
7
|
+
declare const IDX_EP = 772;
|
|
8
|
+
declare const IDX_SIDE = 780;
|
|
9
|
+
declare let keyLo: Uint32Array | null;
|
|
10
|
+
declare let keyHi: Uint32Array | null;
|
|
11
|
+
/**
|
|
12
|
+
* splitmix64 state seed for the 12 derived Chess960 castling keys (ADR-003).
|
|
13
|
+
* Published seed: 0x00C0_FFEE_DABA_D00D.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CASTLE_KEY_SEED = 54324596865421325n;
|
|
16
|
+
declare let castleKeyLo: Uint32Array | null;
|
|
17
|
+
declare let castleKeyHi: Uint32Array | null;
|
|
18
|
+
export { castleKeyLo, castleKeyHi, keyLo, keyHi, IDX_EP, IDX_SIDE };
|
|
7
19
|
/**
|
|
8
20
|
* Loads the Polyglot key blob (idempotent). Safe to call repeatedly; the
|
|
9
21
|
* returned promise resolves once the tables are available. Failures propagate
|
|
@@ -12,6 +24,16 @@ export type ZobristKey = {
|
|
|
12
24
|
export declare function ensureZobristLoaded(): Promise<void>;
|
|
13
25
|
/** Whether the Zobrist tables are loaded (false ⇒ hashing is skipped). */
|
|
14
26
|
export declare function zobristTablesLoaded(): boolean;
|
|
27
|
+
export declare function pieceKeyIdx(color: Color, role: Role, sqIdx: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Castling key index: `(color === White ? 1 : 0) * 8 + rookFile` (ADR-003).
|
|
30
|
+
*/
|
|
31
|
+
export declare function castlingKeyIdx(color: Color, rookSq: number, _kingSq?: number): number;
|
|
32
|
+
export declare function castleFileKey(color: Color, file: number): ZobristKey;
|
|
33
|
+
/** True when a pawn of `side` stands adjacent to the ep square (legal capture). */
|
|
34
|
+
export declare function epIsHashable(target: Position | import("./board.js").BoardLike | {
|
|
35
|
+
board: import("./board.js").BoardLike;
|
|
36
|
+
}, epSquare: number, side: Color): boolean;
|
|
15
37
|
/** Computes the Zobrist key from scratch (O(pieces)). Tables must be loaded. */
|
|
16
38
|
export declare function calculateZobrist(pos: Position): ZobristKey;
|
|
17
39
|
/**
|
package/dist/zobrist.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zobrist.d.ts","sourceRoot":"","sources":["../src/zobrist.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAA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