gigachess 0.4.1 → 0.4.3

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/dist/chesstree.js CHANGED
@@ -6,11 +6,11 @@
6
6
  // Not part of the third-party baseline; MIT like the rest of gigachess.
7
7
  import { parsePgn } from "./pgn.js";
8
8
  import { parseFen, makeFen } from "./fen.js";
9
- import { makeMove, isCheck } from "./chess.js";
10
- import { parseSan, makeUci } from "./san.js";
9
+ import { makeMove, isCheck, isNullMoveLegal } from "./chess.js";
10
+ import { parseSan, makeUci, isNullMoveSan } from "./san.js";
11
+ import { NULL_MOVE_SAN, NULL_MOVE_UCI, nullMove } from "./packedMove.js";
11
12
  import { Color } from "./types.js";
12
13
  const START_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
13
- const NULL_MOVE_SANS = new Set(["--", "Z0", "null"]);
14
14
  const ID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
15
15
  /** Deterministic unique 2-char node id (same alphabet/contract the
16
16
  * workstation's `createUniqueMoveNodeId` relies on). */
@@ -29,7 +29,7 @@ function commentId(fullPath, index) {
29
29
  // Same scheme the baseline emits: pgn-comment-comment-<path-to-node>-<i>
30
30
  return `pgn-comment-comment-${fullPath}-${index}`;
31
31
  }
32
- const isNullMoveSan = (san) => NULL_MOVE_SANS.has(san);
32
+ const isNullMoveNode = (node) => node.san !== undefined && isNullMoveSan(node.san);
33
33
  /** Baseline import semantics: a move repeated as a sibling (same SAN — e.g.
34
34
  * the same line reached via several variations) merges into one node;
35
35
  * subtrees and comments fold together recursively. */
@@ -69,19 +69,29 @@ function replaySection(moves, ctx, out) {
69
69
  };
70
70
  let advance = null;
71
71
  if (isNullMoveSan(m.san)) {
72
- // baseline normalizes Z0/null placeholders to san "--", uci "0000"
73
- node.san = "--";
74
- node.uci = "0000";
72
+ // A pass is a first-class ply, not a skipped token: it advances the
73
+ // position (turn flips, ep clears, halfmove and fullmove both bump), so
74
+ // node.fen must be the RESULT position and ctx must advance exactly as
75
+ // for any other move — otherwise every later node on this line stays one
76
+ // ply out of step and carries the parent's FEN. A pass is illegal while
77
+ // the side to move is in check: skip it, never throw.
78
+ if (!isNullMoveLegal(ctx.pos))
79
+ continue;
80
+ // the baseline normalizes the Z0 pass token to san "--", uci "0000"
81
+ node.san = NULL_MOVE_SAN;
82
+ node.uci = NULL_MOVE_UCI;
83
+ advance = { pos: makeMove(ctx.pos, nullMove()) };
84
+ node.fen = fenWithEpPolicy(advance.pos);
75
85
  }
76
86
  else {
77
87
  const parsed = parseSan(m.san, ctx.pos);
78
88
  if (!parsed.ok)
79
89
  continue; // never throw on garbage — skip the move
80
90
  const move = parsed.value;
81
- advance = { move };
82
91
  node.san = m.san;
83
92
  node.uci = makeUci(move);
84
- node.fen = fenWithEpPolicy(makeMove(ctx.pos, move));
93
+ advance = { pos: makeMove(ctx.pos, move) };
94
+ node.fen = fenWithEpPolicy(advance.pos);
85
95
  }
86
96
  if (m.comments.length > 0) {
87
97
  node.comments = m.comments.map((text, i) => ({
@@ -93,7 +103,7 @@ function replaySection(moves, ctx, out) {
93
103
  // node, recursively merging their subtrees
94
104
  const existing = target.find((c) => c.san !== undefined && c.san === node.san);
95
105
  let mergedInto;
96
- if (existing !== undefined && !isNullMoveSan(node.san ?? "")) {
106
+ if (existing !== undefined && !isNullMoveNode(node)) {
97
107
  mergeTree(existing, node);
98
108
  mergedInto = existing;
99
109
  }
@@ -101,7 +111,7 @@ function replaySection(moves, ctx, out) {
101
111
  target.push(node);
102
112
  }
103
113
  if (advance) {
104
- ctx.pos = makeMove(ctx.pos, advance.move);
114
+ ctx.pos = advance.pos;
105
115
  ctx.ply += 1;
106
116
  ctx.path += id;
107
117
  }
@@ -408,14 +418,20 @@ function renderHeaders(game, rootFen) {
408
418
  }
409
419
  return lines;
410
420
  }
411
- function advanceState(state) {
412
- if (state.turn === "b") {
421
+ function advanceState(state, isPass) {
422
+ // A pass is a FULL move: the number advances whoever passed, exactly as the
423
+ // null-move FEN transition does (fullmove+1 regardless of side). A normal
424
+ // move only advances the number when Black just moved.
425
+ if (isPass || state.turn === "b") {
413
426
  state.moveNo += 1;
414
427
  state.turn = "w";
415
428
  }
416
429
  else {
417
430
  state.turn = "b";
418
431
  }
432
+ // A pass always completes a move, so the next token must carry its number.
433
+ if (isPass)
434
+ state.needNumber = true;
419
435
  }
420
436
  /** Emits the tree from `list[idx]`: the node, then the paren groups for its
421
437
  * sibling alternatives (list[idx+1..], which replace it — baseline places
@@ -427,7 +443,9 @@ function emitFrom(list, idx, state, tokens) {
427
443
  const node = list[idx];
428
444
  const san = node.san;
429
445
  const isNull = san !== undefined && isNullMoveSan(san);
430
- if (san !== undefined && !isNull) {
446
+ // A pass is emitted as `--` — it is a real ply, so dropping it (the old
447
+ // behavior) desynchronized the numbering of every following token.
448
+ if (san !== undefined) {
431
449
  if (state.turn === "w")
432
450
  tokens.push(state.moveNo + ".");
433
451
  else if (state.needNumber)
@@ -442,8 +460,8 @@ function emitFrom(list, idx, state, tokens) {
442
460
  }
443
461
  for (const c of node.comments ?? [])
444
462
  tokens.push("{" + c.text + "}");
445
- if (san !== undefined && !isNull)
446
- advanceState(state);
463
+ if (san !== undefined)
464
+ advanceState(state, isNull);
447
465
  for (let j = idx + 1; j < list.length; j++) {
448
466
  const inner = { ...stateBefore, needNumber: true };
449
467
  const sub = [];
@@ -495,15 +513,14 @@ export const pgnExport = {
495
513
  if (san === undefined)
496
514
  continue;
497
515
  const isNull = isNullMoveSan(san);
498
- if (!isNull) {
499
- if (state.turn === "w")
500
- tokens.push(`${state.moveNo}.`);
501
- else if (state.needNumber)
502
- tokens.push(`${state.moveNo}...`);
503
- tokens.push(san);
504
- state.needNumber = false;
505
- advanceState(state);
506
- }
516
+ // A pass is emitted as `--` and advances the numbering as a full move.
517
+ if (state.turn === "w")
518
+ tokens.push(`${state.moveNo}.`);
519
+ else if (state.needNumber)
520
+ tokens.push(`${state.moveNo}...`);
521
+ tokens.push(san);
522
+ state.needNumber = false;
523
+ advanceState(state, isNull);
507
524
  for (const c of node.comments ?? [])
508
525
  tokens.push(`{${c.text}}`);
509
526
  }
package/dist/core.d.ts CHANGED
@@ -5,6 +5,6 @@ export * from "./util.js";
5
5
  export * from "./fen.js";
6
6
  export * from "./san.js";
7
7
  export { knightAttacks, kingAttacks, pawnAttacks, bishopAttacks, rookAttacks, queenAttacks, ensureMagicTablesLoaded, magicTablesLoaded, ray, between, isAttacked, kingAttackers, } from "./attacks.js";
8
- export { dests, allDests, detectCastling, isCheck, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isThreefoldRepetition, perft, makeMove, play, } from "./chess.js";
9
- export type { CastlingPlan } from "./chess.js";
8
+ export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, makeMove, makeNullMove, play, } from "./chess.js";
9
+ export type { CastlingPlan, NullUndo } from "./chess.js";
10
10
  //# sourceMappingURL=core.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,KAAK,EACL,QAAQ,EACR,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,OAAO,EACP,eAAe,EACf,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
package/dist/core.js CHANGED
@@ -8,4 +8,4 @@ export * from "./util.js";
8
8
  export * from "./fen.js";
9
9
  export * from "./san.js";
10
10
  export { knightAttacks, kingAttacks, pawnAttacks, bishopAttacks, rookAttacks, queenAttacks, ensureMagicTablesLoaded, magicTablesLoaded, ray, between, isAttacked, kingAttackers, } from "./attacks.js";
11
- export { dests, allDests, detectCastling, isCheck, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isThreefoldRepetition, perft, makeMove, play, } from "./chess.js";
11
+ export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, makeMove, makeNullMove, play, } from "./chess.js";
package/dist/index.d.ts CHANGED
@@ -11,8 +11,8 @@ export * from "./packedMove.js";
11
11
  export { knightAttacks, kingAttacks, pawnAttacks, bishopAttacks, rookAttacks, queenAttacks, ensureMagicTablesLoaded, magicTablesLoaded, ray, between, lineRay, LINE_RAY_LO, LINE_RAY_HI, isAttacked, } from "./attacks.js";
12
12
  export { kingAttackers } from "./attacks.js";
13
13
  export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js";
14
- export { dests, allDests, detectCastling, isCheck, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, play, INITIAL_FEN, } from "./chess.js";
15
- export type { CastlingPlan } from "./chess.js";
14
+ export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, makeNullMove, play, INITIAL_FEN, } from "./chess.js";
15
+ export type { CastlingPlan, NullUndo } from "./chess.js";
16
16
  export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
17
17
  export type { TreeWrapper, TreeNode, Path, Comment, Glyph, Clock, Shape, Eval as TreeEval, Game, Player, AnalyseData, } from "./chesstree.js";
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,OAAO,EACP,KAAK,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,EACL,SAAS,EACT,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,IAAI,QAAQ,EAChB,IAAI,EACJ,MAAM,EACN,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,OAAO,EACP,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,EACL,QAAQ,EACR,cAAc,EACd,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,OAAO,EACP,eAAe,EACf,KAAK,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzD,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,EACL,SAAS,EACT,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,IAAI,QAAQ,EAChB,IAAI,EACJ,MAAM,EACN,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -16,6 +16,6 @@ export { knightAttacks, kingAttacks, pawnAttacks, bishopAttacks, rookAttacks, qu
16
16
  export { kingAttackers } from "./attacks.js";
17
17
  export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js";
18
18
  // chess core (avoid duplicate Position and kingAttackers)
19
- export { dests, allDests, detectCastling, isCheck, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, play, INITIAL_FEN, } from "./chess.js";
19
+ export { dests, allDests, detectCastling, isCheck, isCheckFresh, isCheckmate, isStalemate, isInsufficientMaterial, isFiftyMoveDraw, isSeventyFiveMoveDraw, isThreefoldRepetition, isLegal, isNullMoveLegal, perft, countLegalMoves, legalMovesInto, forEachLegalMove, MoveCounter, makeMove, makeNullMove, play, INITIAL_FEN, } from "./chess.js";
20
20
  // chesstree integration (tree shapes + analysis API, folded into the root)
21
21
  export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
@@ -14,7 +14,30 @@ export declare const PROMO_ROOK = 3;
14
14
  export declare const PROMO_QUEEN = 4;
15
15
  /** Packs from/to/promo into one 16-bit word. */
16
16
  export declare function packMove(from: number, to: number, promo?: number): number;
17
- /** Unpacks a 16-bit word into its from/to/promo fields. */
17
+ /** The null-move (pass) sentinel word. */
18
+ export declare const NULL_MOVE_WORD = 65535;
19
+ /** Canonical SAN rendering of a pass — never suffixed with `+` or `#`. */
20
+ export declare const NULL_MOVE_SAN = "--";
21
+ /** Canonical UCI rendering of a pass. */
22
+ export declare const NULL_MOVE_UCI = "0000";
23
+ /** True when `word` is the null-move sentinel (a pass, not a board move). */
24
+ export declare function isNull(word: number): boolean;
25
+ /**
26
+ * A fresh null-move value (never share one instance across callers).
27
+ *
28
+ * `from`/`to` mirror the sentinel's own field decode (both 63) so the value
29
+ * round-trips through the wire format unchanged; `isNull` is what identifies
30
+ * it as a pass, never the squares.
31
+ */
32
+ export declare function nullMove(): Move;
33
+ /** True when `move` is the null move (pass). */
34
+ export declare function isNullMove(move: Move): boolean;
35
+ /**
36
+ * Unpacks a 16-bit word into its from/to/promo fields.
37
+ *
38
+ * The null-move sentinel `0xffff` is a pass, not a from/to/promo triple; the
39
+ * caller must test `isNull(word)` first (see `unpackToMove`, which does).
40
+ */
18
41
  export declare function unpackMove(word: number): PackedMove;
19
42
  /** Role enum → moves2 promotion code. */
20
43
  export declare function roleToPromoCode(role: Role): number;
@@ -22,7 +45,12 @@ export declare function roleToPromoCode(role: Role): number;
22
45
  export declare function promoCodeToRole(code: number): Role | undefined;
23
46
  /** Packs a Move into its 16-bit word (promotion flags are honored). */
24
47
  export declare function packOf(move: Move): number;
25
- /** Expands a 16-bit word into an engine Move (no legality interpretation). */
48
+ /**
49
+ * Expands a 16-bit word into an engine Move (no legality interpretation).
50
+ *
51
+ * The null-move sentinel decodes to a first-class pass — it must NOT be masked
52
+ * through as the bogus normal word `from=63, to=63, promo=15`.
53
+ */
26
54
  export declare function unpackToMove(word: number): Move;
27
55
  /** Packs a move list into a flat Uint16Array (moves2 stream). */
28
56
  export declare function movesToPacked(moves: readonly Move[]): Uint16Array;
@@ -1 +1 @@
1
- {"version":3,"file":"packedMove.d.ts","sourceRoot":"","sources":["../src/packedMove.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,IA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C,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,GAAE,MAAmB,GAAG,MAAM,CAErF;AAUD,0CAA0C;AAC1C,eAAO,MAAM,cAAc,QAAS,CAAC;AAErC,0EAA0E;AAC1E,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,yCAAyC;AACzC,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,6EAA6E;AAC7E,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAU/B;AAED,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAOnD;AAED,yCAAyC;AACzC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAQlD;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAQ9D;AAED,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAKzC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAY/C;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,WAAW,CAIjE;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAatE"}
@@ -18,7 +18,51 @@ export const PROMO_QUEEN = 4;
18
18
  export function packMove(from, to, promo = PROMO_NONE) {
19
19
  return ((from & 0x3f) | ((to & 0x3f) << 6) | ((promo & 0x0f) << 12)) & 0xffff;
20
20
  }
21
- /** Unpacks a 16-bit word into its from/to/promo fields. */
21
+ // ---------- null move (pass) — the first-class `0xffff` sentinel ----------
22
+ //
23
+ // The null move is NOT a from/to/promo triple: it is the single u16 sentinel
24
+ // `0xffff`, matching gigachess-rs `Move(0xffff)` (board.rs make_null_move).
25
+ // The sentinel is reserved — no legal move packs to it (the widest legal word
26
+ // is 0x4fff: from=63, to=63, promo=4), so the value is unambiguous in a
27
+ // moves2 stream.
28
+ /** The null-move (pass) sentinel word. */
29
+ export const NULL_MOVE_WORD = 0xffff;
30
+ /** Canonical SAN rendering of a pass — never suffixed with `+` or `#`. */
31
+ export const NULL_MOVE_SAN = "--";
32
+ /** Canonical UCI rendering of a pass. */
33
+ export const NULL_MOVE_UCI = "0000";
34
+ /** True when `word` is the null-move sentinel (a pass, not a board move). */
35
+ export function isNull(word) {
36
+ return (word & 0xffff) === NULL_MOVE_WORD;
37
+ }
38
+ /**
39
+ * A fresh null-move value (never share one instance across callers).
40
+ *
41
+ * `from`/`to` mirror the sentinel's own field decode (both 63) so the value
42
+ * round-trips through the wire format unchanged; `isNull` is what identifies
43
+ * it as a pass, never the squares.
44
+ */
45
+ export function nullMove() {
46
+ return {
47
+ from: 63,
48
+ to: 63,
49
+ promotion: null,
50
+ isPromotion: false,
51
+ isEnPassant: false,
52
+ isCastling: false,
53
+ isNull: true,
54
+ };
55
+ }
56
+ /** True when `move` is the null move (pass). */
57
+ export function isNullMove(move) {
58
+ return move.isNull === true;
59
+ }
60
+ /**
61
+ * Unpacks a 16-bit word into its from/to/promo fields.
62
+ *
63
+ * The null-move sentinel `0xffff` is a pass, not a from/to/promo triple; the
64
+ * caller must test `isNull(word)` first (see `unpackToMove`, which does).
65
+ */
22
66
  export function unpackMove(word) {
23
67
  const w = word & 0xffff;
24
68
  return {
@@ -49,11 +93,21 @@ export function promoCodeToRole(code) {
49
93
  }
50
94
  /** Packs a Move into its 16-bit word (promotion flags are honored). */
51
95
  export function packOf(move) {
96
+ // A pass is the reserved sentinel, not a from/to/promo triple.
97
+ if (isNullMove(move))
98
+ return NULL_MOVE_WORD;
52
99
  const promo = move.promotion !== null && move.promotion !== undefined ? roleToPromoCode(move.promotion) : PROMO_NONE;
53
100
  return packMove(move.from, move.to, promo);
54
101
  }
55
- /** Expands a 16-bit word into an engine Move (no legality interpretation). */
102
+ /**
103
+ * Expands a 16-bit word into an engine Move (no legality interpretation).
104
+ *
105
+ * The null-move sentinel decodes to a first-class pass — it must NOT be masked
106
+ * through as the bogus normal word `from=63, to=63, promo=15`.
107
+ */
56
108
  export function unpackToMove(word) {
109
+ if (isNull(word))
110
+ return nullMove();
57
111
  const { from, to, promo } = unpackMove(word);
58
112
  const role = promoCodeToRole(promo);
59
113
  return {
package/dist/san.d.ts CHANGED
@@ -1,6 +1,38 @@
1
1
  import type { Position, Move, Result, SanError, UciError } from "./types.js";
2
+ /**
3
+ * The null move is a first-class pass, not a placeholder alias: the only SAN
4
+ * tokens that denote one are `--` (the canonical rendering) and `Z0` (the
5
+ * moves2/FEN pass token). `null`, `pass` and every other spelling are rejected
6
+ * by `parseSan`.
7
+ */
8
+ export declare const NULL_MOVE_SANS: readonly string[];
9
+ /** True when `san` is one of the two accepted null-move tokens. */
10
+ export declare function isNullMoveSan(san: string): boolean;
2
11
  export declare function makeSan(move: Move, pos: Position): string;
3
12
  export declare function parseSan(san: string, pos: Position): Result<Move, SanError>;
13
+ /**
14
+ * `parseSan` with the matching moves retained.
15
+ *
16
+ * A multi-match parse ends in `san/ambiguous` and `parseSan` throws the matches
17
+ * away, so a caller can report *that* the input was ambiguous but never *what*
18
+ * it could have meant. `candidates` carries that list so a UI can name the
19
+ * disambiguated spellings instead of guessing (BlindBase ADR-042, report #11).
20
+ *
21
+ * `result` is exactly what `parseSan` returns for the same input; this exists so
22
+ * the two cannot drift, not as a second parse path.
23
+ */
24
+ export declare function parseSanDetailed(san: string, pos: Position): {
25
+ result: Result<Move, SanError>;
26
+ candidates: Move[] | null;
27
+ };
28
+ /**
29
+ * Every legal move `san` could denote, or the error when it names none.
30
+ *
31
+ * The counterpart to `parseSan` for callers that must react to ambiguity rather
32
+ * than accept it: `length === 1` means resolved, `length > 1` means the caller
33
+ * should ask which of these it meant.
34
+ */
35
+ export declare function parseSanCandidates(san: string, pos: Position): Result<Move[], SanError>;
4
36
  export declare function parseUci(uci: string): Result<Move, UciError>;
5
37
  export declare function makeUci(move: Move): string;
6
38
  //# sourceMappingURL=san.d.ts.map
package/dist/san.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"san.d.ts","sourceRoot":"","sources":["../src/san.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB7E,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAsJzD;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CA6L3E;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAuB5D;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAgB1C"}
1
+ {"version":3,"file":"san.d.ts","sourceRoot":"","sources":["../src/san.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQ7E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAA0B,CAAC;AAGvE,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAYD,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CA0JzD;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAE3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,QAAQ,GACZ;IAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAAC,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;CAAE,CAc/D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAMvF;AAuND,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CA2B5D;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAmB1C"}
package/dist/san.js CHANGED
@@ -7,8 +7,21 @@ import * as attacks from "./attacks.js";
7
7
  import { Color, Role } from "./types.js";
8
8
  import { Err, Ok } from "./types.js";
9
9
  import { squareFile, squareRank, parseSquare, squareName } from "./util.js";
10
+ import { isNullMove, nullMove, NULL_MOVE_SAN, NULL_MOVE_UCI } from "./packedMove.js";
10
11
  const ROLE_SAN = ["", "N", "B", "R", "Q", "K"];
11
12
  const roleToSanChar = (role) => ROLE_SAN[role] ?? "";
13
+ /**
14
+ * The null move is a first-class pass, not a placeholder alias: the only SAN
15
+ * tokens that denote one are `--` (the canonical rendering) and `Z0` (the
16
+ * moves2/FEN pass token). `null`, `pass` and every other spelling are rejected
17
+ * by `parseSan`.
18
+ */
19
+ export const NULL_MOVE_SANS = [NULL_MOVE_SAN, "Z0"];
20
+ const NULL_MOVE_SAN_SET = new Set(NULL_MOVE_SANS);
21
+ /** True when `san` is one of the two accepted null-move tokens. */
22
+ export function isNullMoveSan(san) {
23
+ return NULL_MOVE_SAN_SET.has(san);
24
+ }
12
25
  const SAN_ROLES = { K: Role.King, Q: Role.Queen, R: Role.Rook, B: Role.Bishop, N: Role.Knight };
13
26
  const sanCharToRole = (ch) => SAN_ROLES[ch];
14
27
  const promoCharToRole = (ch) => SAN_ROLES[ch.toUpperCase()];
@@ -18,6 +31,11 @@ function normalizeCastlingSan(s) {
18
31
  }
19
32
  // ---------- makeSan ----------
20
33
  export function makeSan(move, pos) {
34
+ // A pass renders as exactly `--` and returns here: it is never suffixed with
35
+ // `+` or `#` (a pass can neither give nor answer check), and it has no
36
+ // origin square for the castling/disambiguation paths below.
37
+ if (isNullMove(move))
38
+ return NULL_MOVE_SAN;
21
39
  // Castling — detected via the shared detectCastling path (design D2) so a
22
40
  // canonical castling move given in the representation's encoding renders
23
41
  // O-O/O-O-O, never "Kg1"/"Kxh1" (measured defect: makeSan({4,6}, kiwipete)
@@ -188,8 +206,71 @@ export function makeSan(move, pos) {
188
206
  }
189
207
  // ---------- parseSan ----------
190
208
  export function parseSan(san, pos) {
209
+ return parseSanDetailed(san, pos).result;
210
+ }
211
+ /**
212
+ * `parseSan` with the matching moves retained.
213
+ *
214
+ * A multi-match parse ends in `san/ambiguous` and `parseSan` throws the matches
215
+ * away, so a caller can report *that* the input was ambiguous but never *what*
216
+ * it could have meant. `candidates` carries that list so a UI can name the
217
+ * disambiguated spellings instead of guessing (BlindBase ADR-042, report #11).
218
+ *
219
+ * `result` is exactly what `parseSan` returns for the same input; this exists so
220
+ * the two cannot drift, not as a second parse path.
221
+ */
222
+ export function parseSanDetailed(san, pos) {
223
+ const traced = parseSanTraced(san, pos);
224
+ const candidates = traced.candidates;
225
+ if (candidates === null) {
226
+ // Rejected before any move could match — nothing to disambiguate.
227
+ return { result: traced.result, candidates: null };
228
+ }
229
+ if (candidates.length === 0) {
230
+ return { result: Err({ code: "san/noLegalMove" }), candidates };
231
+ }
232
+ if (candidates.length > 1) {
233
+ return { result: Err({ code: "san/ambiguous" }), candidates };
234
+ }
235
+ return { result: Ok(candidates[0]), candidates };
236
+ }
237
+ /**
238
+ * Every legal move `san` could denote, or the error when it names none.
239
+ *
240
+ * The counterpart to `parseSan` for callers that must react to ambiguity rather
241
+ * than accept it: `length === 1` means resolved, `length > 1` means the caller
242
+ * should ask which of these it meant.
243
+ */
244
+ export function parseSanCandidates(san, pos) {
245
+ const { result, candidates } = parseSanDetailed(san, pos);
246
+ if (candidates === null || candidates.length === 0) {
247
+ return result.ok ? Ok([result.value]) : Err(result.error);
248
+ }
249
+ return Ok(candidates);
250
+ }
251
+ /**
252
+ * The parse body, keeping the collected candidates.
253
+ *
254
+ * Every early refusal before candidate collection returns `candidates: null`,
255
+ * which is what distinguishes "this string is not a SAN at all" from "this SAN
256
+ * is ambiguous" — a distinction `parseSan`'s single error channel previously
257
+ * lost.
258
+ */
259
+ function parseSanTraced(san, pos) {
260
+ // A refusal raised before any move could match: nothing to disambiguate, which
261
+ // is what separates "not a SAN at all" from "an ambiguous SAN".
262
+ const fail = (code) => ({ result: Err({ code }), candidates: null });
191
263
  const orig = san;
192
264
  let s = normalizeCastlingSan(san.trim());
265
+ // Null move (pass) — exactly `--` or `Z0`, matched BEFORE any check-suffix
266
+ // handling so a suffixed spelling (`--+`) is not silently accepted. A pass is
267
+ // legal iff the side to move is not in check; the test is computed fresh from
268
+ // the attack tables, never from the cached `checkers` bitboard.
269
+ if (isNullMoveSan(s)) {
270
+ if (!chess.isNullMoveLegal(pos))
271
+ return fail("san/illegal");
272
+ return { result: Ok(nullMove()), candidates: [nullMove()] };
273
+ }
193
274
  // Handle check suffix for later, but keep for validation
194
275
  let checkSuffix = "";
195
276
  if (s.endsWith("+") || s.endsWith("#")) {
@@ -201,7 +282,7 @@ export function parseSan(san, pos) {
201
282
  const isKingSide = s === "O-O";
202
283
  const kingSq = board.kingSquare(pos.board, pos.turn);
203
284
  if (kingSq === undefined)
204
- return Err({ code: "san/noKing" });
285
+ return fail("san/noKing");
205
286
  // Find if castling is legal via dests. The generated dest is the
206
287
  // representation's castling square: normalized landing (6/2/62/58) or the
207
288
  // right's rook square (baseline/960 form). Both are accepted.
@@ -222,12 +303,12 @@ export function parseSan(san, pos) {
222
303
  }
223
304
  }
224
305
  if (dest === undefined)
225
- return Err({ code: "san/illegal" });
306
+ return fail("san/illegal");
226
307
  const move = { from: kingSq, to: dest, isCastling: true, isEnPassant: false, isPromotion: false, promotion: null };
227
308
  // Optionally validate check suffix matches actual
228
309
  // We ignore mismatch for parsing tolerance, but we could validate
229
310
  // If checkSuffix present, we could verify after play, but not required to error
230
- return Ok(move);
311
+ return { result: Ok(move), candidates: [move] };
231
312
  }
232
313
  // Promotion handling
233
314
  let promotion = undefined;
@@ -235,20 +316,20 @@ export function parseSan(san, pos) {
235
316
  if (eqIdx !== -1) {
236
317
  const promoChar = s[eqIdx + 1];
237
318
  if (!promoChar)
238
- return Err({ code: "san/invalidPromotion" });
319
+ return fail("san/invalidPromotion");
239
320
  const role = promoCharToRole(promoChar);
240
321
  if (role === undefined)
241
- return Err({ code: "san/invalidPromotion" });
322
+ return fail("san/invalidPromotion");
242
323
  promotion = role;
243
324
  s = s.slice(0, eqIdx);
244
325
  }
245
326
  // Destination
246
327
  if (s.length < 2)
247
- return Err({ code: "san/invalidSan" });
328
+ return fail("san/invalidSan");
248
329
  const toStr = s.slice(-2);
249
330
  const to = parseSquare(toStr);
250
331
  if (to === undefined)
251
- return Err({ code: "san/invalidSquare" });
332
+ return fail("san/invalidSquare");
252
333
  let rest = s.slice(0, -2);
253
334
  // Capture
254
335
  let isCapture = false;
@@ -276,7 +357,7 @@ export function parseSan(san, pos) {
276
357
  else if (ch >= "1" && ch <= "8")
277
358
  disambRank = ch;
278
359
  else
279
- return Err({ code: "san/invalidSan" });
360
+ return fail("san/invalidSan");
280
361
  }
281
362
  else if (rest.length === 2) {
282
363
  if (rest[0] >= "a" && rest[0] <= "h" && rest[1] >= "1" && rest[1] <= "8") {
@@ -284,10 +365,10 @@ export function parseSan(san, pos) {
284
365
  disambRank = rest[1];
285
366
  }
286
367
  else
287
- return Err({ code: "san/invalidSan" });
368
+ return fail("san/invalidSan");
288
369
  }
289
370
  else if (rest.length > 2) {
290
- return Err({ code: "san/invalidSan" });
371
+ return fail("san/invalidSan");
291
372
  }
292
373
  // For pawn, pieceRole is pawn, but rest may be file for capture (like "e" in exd5)
293
374
  // Our disamb handling already captured that: for "exd5", rest after removing piece (none) and capture, rest = "e" => disambFile = 'e' . Good.
@@ -364,7 +445,7 @@ export function parseSan(san, pos) {
364
445
  filteredFroms = filteredFroms.filter(f => squareRank(f) === reqRank);
365
446
  }
366
447
  if (filteredFroms.length === 0)
367
- return Err({ code: "san/noLegalMove" });
448
+ return fail("san/noLegalMove");
368
449
  // Legality filtering with single shared check context
369
450
  const ctx = chess.analyzeCheckContext(pos);
370
451
  const candidates = [];
@@ -398,15 +479,19 @@ export function parseSan(san, pos) {
398
479
  });
399
480
  }
400
481
  if (candidates.length === 0)
401
- return Err({ code: "san/noLegalMove" });
482
+ return { result: Err({ code: "san/noLegalMove" }), candidates };
402
483
  if (candidates.length > 1)
403
- return Err({ code: "san/ambiguous" });
404
- const chosen = candidates[0];
405
- return Ok(chosen);
484
+ return { result: Err({ code: "san/ambiguous" }), candidates };
485
+ return { result: Ok(candidates[0]), candidates };
406
486
  }
407
487
  // ---------- UCI ----------
408
488
  export function parseUci(uci) {
409
489
  const s = uci.trim();
490
+ // The null move is the `0000` token (its own 4-char spelling, not a square
491
+ // pair). Parsing is position-free; the legality of a pass is judged by the
492
+ // validating entry points (isLegal / parseSan / makeMove).
493
+ if (s === NULL_MOVE_UCI)
494
+ return Ok(nullMove());
410
495
  if (s.length < 4 || s.length > 5)
411
496
  return Err({ code: "uci/invalidUci" });
412
497
  const fromStr = s.slice(0, 2);
@@ -433,6 +518,10 @@ export function parseUci(uci) {
433
518
  return Ok(move);
434
519
  }
435
520
  export function makeUci(move) {
521
+ // A pass renders as `0000` (the 16-bit sentinel's 4-char spelling) and
522
+ // returns here — it has no origin/destination square.
523
+ if (isNullMove(move))
524
+ return NULL_MOVE_UCI;
436
525
  const from = squareName(move.from);
437
526
  const to = squareName(move.to);
438
527
  let promo = "";
package/dist/types.d.ts CHANGED
@@ -118,6 +118,7 @@ export type Move = NormalMove & {
118
118
  isEnPassant?: boolean;
119
119
  isCastling?: boolean;
120
120
  isPromotion?: boolean;
121
+ isNull?: boolean;
121
122
  };
122
123
  export type Outcome = "white" | "black" | "draw" | "*";
123
124
  export type Result<T, E> = {
@@ -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;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IACpE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IACtE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IAAE,EAAE,KAAK;IACtE,EAAE,KAAK;IAAE,EAAE,KAAK;I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AAE,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
@@ -64,4 +64,17 @@ export declare function zobristAfterMove(pos: Position, move: {
64
64
  } | undefined, newPos: Position): ZobristKey;
65
65
  /** 16-hex-digit rendering of a {lo,hi} key (hi first, zero-padded). */
66
66
  export declare function zobristHex(key: ZobristKey): string;
67
+ /**
68
+ * Incremental $O(1)$ Zobrist update for a null move (pass) — the delta-free
69
+ * counterpart of {@link zobristAfterMove}. A pass touches no piece, so the only
70
+ * contributions that change are the ones the transition clears/flips:
71
+ *
72
+ * - the OLD en-passant square leaves (relevance is tested against the mover's
73
+ * pawns, which a pass does not move) — a pass always clears the ep square,
74
+ * - no NEW en-passant square is ever set by a pass,
75
+ * - the side-to-move key flips.
76
+ *
77
+ * Mirrors gigachess-rs `Board::make_null_move` (board.rs).
78
+ */
79
+ export declare function zobristAfterNullMove(pos: Position): ZobristKey;
67
80
  //# sourceMappingURL=zobrist.d.ts.map