gigachess 0.2.1

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -0
  3. package/dist/attacks.d.ts +40 -0
  4. package/dist/attacks.d.ts.map +1 -0
  5. package/dist/attacks.js +389 -0
  6. package/dist/bishopMagicBlob.d.ts +2 -0
  7. package/dist/bishopMagicBlob.d.ts.map +1 -0
  8. package/dist/bishopMagicBlob.js +11 -0
  9. package/dist/board.d.ts +73 -0
  10. package/dist/board.d.ts.map +1 -0
  11. package/dist/board.js +237 -0
  12. package/dist/chess.d.ts +215 -0
  13. package/dist/chess.d.ts.map +1 -0
  14. package/dist/chess.js +1453 -0
  15. package/dist/chess960.d.ts +10 -0
  16. package/dist/chess960.d.ts.map +1 -0
  17. package/dist/chess960.js +18 -0
  18. package/dist/chessops/board.d.ts +49 -0
  19. package/dist/chessops/board.d.ts.map +1 -0
  20. package/dist/chessops/board.js +138 -0
  21. package/dist/chessops/chess.d.ts +104 -0
  22. package/dist/chessops/chess.d.ts.map +1 -0
  23. package/dist/chessops/chess.js +435 -0
  24. package/dist/chessops/compat.d.ts +19 -0
  25. package/dist/chessops/compat.d.ts.map +1 -0
  26. package/dist/chessops/compat.js +25 -0
  27. package/dist/chessops/convert.d.ts +42 -0
  28. package/dist/chessops/convert.d.ts.map +1 -0
  29. package/dist/chessops/convert.js +114 -0
  30. package/dist/chessops/debug.d.ts +17 -0
  31. package/dist/chessops/debug.d.ts.map +1 -0
  32. package/dist/chessops/debug.js +67 -0
  33. package/dist/chessops/fen.d.ts +28 -0
  34. package/dist/chessops/fen.d.ts.map +1 -0
  35. package/dist/chessops/fen.js +74 -0
  36. package/dist/chessops/fenInternal.d.ts +15 -0
  37. package/dist/chessops/fenInternal.d.ts.map +1 -0
  38. package/dist/chessops/fenInternal.js +42 -0
  39. package/dist/chessops/index.d.ts +12 -0
  40. package/dist/chessops/index.d.ts.map +1 -0
  41. package/dist/chessops/index.js +17 -0
  42. package/dist/chessops/san.d.ts +7 -0
  43. package/dist/chessops/san.d.ts.map +1 -0
  44. package/dist/chessops/san.js +33 -0
  45. package/dist/chessops/setup.d.ts +64 -0
  46. package/dist/chessops/setup.d.ts.map +1 -0
  47. package/dist/chessops/setup.js +158 -0
  48. package/dist/chessops/squareSet.d.ts +48 -0
  49. package/dist/chessops/squareSet.d.ts.map +1 -0
  50. package/dist/chessops/squareSet.js +192 -0
  51. package/dist/chessops/transform.d.ts +12 -0
  52. package/dist/chessops/transform.d.ts.map +1 -0
  53. package/dist/chessops/transform.js +53 -0
  54. package/dist/chessops/types.d.ts +47 -0
  55. package/dist/chessops/types.d.ts.map +1 -0
  56. package/dist/chessops/types.js +12 -0
  57. package/dist/chessops/util.d.ts +19 -0
  58. package/dist/chessops/util.d.ts.map +1 -0
  59. package/dist/chessops/util.js +52 -0
  60. package/dist/chesstree.d.ts +143 -0
  61. package/dist/chesstree.d.ts.map +1 -0
  62. package/dist/chesstree.js +514 -0
  63. package/dist/core.d.ts +10 -0
  64. package/dist/core.d.ts.map +1 -0
  65. package/dist/core.js +11 -0
  66. package/dist/fen.d.ts +10 -0
  67. package/dist/fen.d.ts.map +1 -0
  68. package/dist/fen.js +600 -0
  69. package/dist/index.d.ts +17 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +22 -0
  72. package/dist/packedMove.d.ts +31 -0
  73. package/dist/packedMove.d.ts.map +1 -0
  74. package/dist/packedMove.js +88 -0
  75. package/dist/pgn.d.ts +24 -0
  76. package/dist/pgn.d.ts.map +1 -0
  77. package/dist/pgn.js +361 -0
  78. package/dist/rookMagicBlob.d.ts +2 -0
  79. package/dist/rookMagicBlob.d.ts.map +1 -0
  80. package/dist/rookMagicBlob.js +11 -0
  81. package/dist/san.d.ts +6 -0
  82. package/dist/san.d.ts.map +1 -0
  83. package/dist/san.js +484 -0
  84. package/dist/squareSet.d.ts +48 -0
  85. package/dist/squareSet.d.ts.map +1 -0
  86. package/dist/squareSet.js +154 -0
  87. package/dist/types.d.ts +147 -0
  88. package/dist/types.d.ts.map +1 -0
  89. package/dist/types.js +88 -0
  90. package/dist/util.d.ts +11 -0
  91. package/dist/util.d.ts.map +1 -0
  92. package/dist/util.js +59 -0
  93. package/dist/zobrist.d.ts +45 -0
  94. package/dist/zobrist.d.ts.map +1 -0
  95. package/dist/zobrist.js +271 -0
  96. package/dist/zobristBlob.d.ts +2 -0
  97. package/dist/zobristBlob.d.ts.map +1 -0
  98. package/dist/zobristBlob.js +11 -0
  99. package/package.json +135 -0
@@ -0,0 +1,67 @@
1
+ import { makeSquare, roleToChar } from "./util.js";
2
+ export const squareSet = (squares) => [...squares].map(makeSquare).join(", ");
3
+ export const piece = (p) => `${p.color} ${p.role}`;
4
+ export const board = (b) => {
5
+ const rows = [];
6
+ for (let rank = 7; rank >= 0; rank--) {
7
+ let row = `${rank + 1} `;
8
+ for (let file = 0; file < 8; file++) {
9
+ const p = b.get(rank * 8 + file);
10
+ row += p ? `${p.color === "white" ? roleToChar(p.role).toUpperCase() : roleToChar(p.role)} ` : ". ";
11
+ }
12
+ rows.push(row);
13
+ }
14
+ return rows.join("\n") + "\n a b c d e f g h";
15
+ };
16
+ export const square = (sq) => makeSquare(sq);
17
+ /**
18
+ * ASCII position dump (pure oracle): eight whitespace-separated piece rows,
19
+ * rank 8 first — byte-identical (modulo whitespace) to the baseline debug
20
+ * board dump on the same position.
21
+ */
22
+ export const debugBoard = (pos) => {
23
+ const rows = [];
24
+ for (let rank = 7; rank >= 0; rank--) {
25
+ const row = [];
26
+ for (let file = 0; file < 8; file++) {
27
+ const p = pos.board.get(rank * 8 + file);
28
+ row.push(p ? (p.color === "white" ? roleToChar(p.role).toUpperCase() : roleToChar(p.role)) : ".");
29
+ }
30
+ rows.push(row.join(" "));
31
+ }
32
+ return rows.join("\n");
33
+ };
34
+ export const dests = (d) => [...d.entries()].map(([from, set]) => `${makeSquare(from)}: ${[...set].map(makeSquare).join(" ")}`).join("\n");
35
+ export const perft = (pos, depth, log = false) => {
36
+ if (depth === 0)
37
+ return 1;
38
+ if (depth === 1) {
39
+ let n = 0;
40
+ for (const [from, set] of pos.allDests()) {
41
+ const piece = pos.board.get(from);
42
+ for (const to of set) {
43
+ // pawn moves to the backrank expand into 4 promotions
44
+ n += piece?.role === "pawn" && (to >= 56 || to < 8) ? 4 : 1;
45
+ }
46
+ }
47
+ return n;
48
+ }
49
+ let nodes = 0;
50
+ for (const [from, set] of pos.allDests()) {
51
+ const piece = pos.board.get(from);
52
+ for (const to of set) {
53
+ const moves = piece?.role === "pawn" && (to >= 56 || to < 8)
54
+ ? ["queen", "rook", "bishop", "knight"].map((promotion) => ({ from, to, promotion }))
55
+ : [{ from, to }];
56
+ for (const move of moves) {
57
+ const child = pos.clone();
58
+ child.play(move);
59
+ const count = perft(child, depth - 1);
60
+ nodes += count;
61
+ if (log)
62
+ console.log(makeSquare(from) + makeSquare(to) + ("promotion" in move ? move.promotion : "") + ": " + count);
63
+ }
64
+ }
65
+ }
66
+ return nodes;
67
+ };
@@ -0,0 +1,28 @@
1
+ import { Result } from "@badrap/result";
2
+ import { Board } from "./board.js";
3
+ import { SquareSet } from "./squareSet.js";
4
+ import type { Setup } from "./setup.js";
5
+ import { EMPTY_BOARD_FEN, EMPTY_EPD, EMPTY_FEN, INITIAL_BOARD_FEN, INITIAL_EPD, INITIAL_FEN } from "./fenInternal.js";
6
+ export { EMPTY_BOARD_FEN, EMPTY_EPD, EMPTY_FEN, INITIAL_BOARD_FEN, INITIAL_EPD, INITIAL_FEN, };
7
+ export declare enum InvalidFen {
8
+ Fen = "ERR_FEN",
9
+ Board = "ERR_BOARD",
10
+ Pockets = "ERR_POCKETS",
11
+ Turn = "ERR_TURN",
12
+ Castling = "ERR_CASTLING",
13
+ EpSquare = "ERR_EP_SQUARE",
14
+ RemainingChecks = "ERR_REMAINING_CHECKS",
15
+ Halfmoves = "ERR_HALFMOVES",
16
+ Fullmoves = "ERR_FULLMOVES"
17
+ }
18
+ export declare class FenError extends Error {
19
+ }
20
+ export declare const parseBoardFen: (boardPart: string) => Result<Board, FenError>;
21
+ export declare const parseCastlingFen: (board: Board, castlingPart: string) => Result<SquareSet, FenError>;
22
+ export declare const parseFen: (fen: string) => Result<Setup, FenError>;
23
+ export interface FenOpts {
24
+ epd?: boolean;
25
+ }
26
+ export declare const makeFen: (setup: Setup, opts?: FenOpts) => string;
27
+ export declare const makeBoardFen: (board: Board) => string;
28
+ //# sourceMappingURL=fen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fen.d.ts","sourceRoot":"","sources":["../../src/chessops/fen.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,WAAW,EAGZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,WAAW,GACZ,CAAC;AAEF,oBAAY,UAAU;IACpB,GAAG,YAAY;IACf,KAAK,cAAc;IACnB,OAAO,gBAAgB;IACvB,IAAI,aAAa;IACjB,QAAQ,iBAAiB;IACzB,QAAQ,kBAAkB;IAC1B,eAAe,yBAAyB;IACxC,SAAS,kBAAkB;IAC3B,SAAS,kBAAkB;CAC5B;AAED,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,KAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAMvE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,KAAK,EAAE,cAAc,MAAM,KAAG,MAAM,CAAC,SAAS,EAAE,QAAQ,CAoB/F,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,KAAG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAI5D,CAAC;AAEF,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,KAAK,EAAE,OAAO,OAAO,KAAG,MAGtD,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,KAAG,MAE3C,CAAC"}
@@ -0,0 +1,74 @@
1
+ // src/baseline/fen.ts — baseline-exact FEN API (ADR-014), backed by the
2
+ // immutable engine parser (which additionally accepts unreachable ep squares
3
+ // and 4-field FENs per the purechess-rules spec — baseline-compatible).
4
+ import { Result } from "@badrap/result";
5
+ import * as engineFen from "../fen.js";
6
+ import { SquareSet } from "./squareSet.js";
7
+ import { boardFromEngine, boardToEngine, setupFromEngine, setupToEngine } from "./convert.js";
8
+ import { EMPTY_BOARD_FEN, EMPTY_EPD, EMPTY_FEN, INITIAL_BOARD_FEN, INITIAL_EPD, INITIAL_FEN, engineBoardFromPlacement, engineMakePlacement, } from "./fenInternal.js";
9
+ // FEN constants are single-sourced in the shared engine bridge (task 3.2).
10
+ export { EMPTY_BOARD_FEN, EMPTY_EPD, EMPTY_FEN, INITIAL_BOARD_FEN, INITIAL_EPD, INITIAL_FEN, };
11
+ export var InvalidFen;
12
+ (function (InvalidFen) {
13
+ InvalidFen["Fen"] = "ERR_FEN";
14
+ InvalidFen["Board"] = "ERR_BOARD";
15
+ InvalidFen["Pockets"] = "ERR_POCKETS";
16
+ InvalidFen["Turn"] = "ERR_TURN";
17
+ InvalidFen["Castling"] = "ERR_CASTLING";
18
+ InvalidFen["EpSquare"] = "ERR_EP_SQUARE";
19
+ InvalidFen["RemainingChecks"] = "ERR_REMAINING_CHECKS";
20
+ InvalidFen["Halfmoves"] = "ERR_HALFMOVES";
21
+ InvalidFen["Fullmoves"] = "ERR_FULLMOVES";
22
+ })(InvalidFen || (InvalidFen = {}));
23
+ export class FenError extends Error {
24
+ }
25
+ export const parseBoardFen = (boardPart) => {
26
+ try {
27
+ return Result.ok(boardFromEngine(engineBoardFromPlacement(boardPart)));
28
+ }
29
+ catch (e) {
30
+ return Result.err(new FenError(e instanceof Error ? e.message : InvalidFen.Board));
31
+ }
32
+ };
33
+ export const parseCastlingFen = (board, castlingPart) => {
34
+ let rights = SquareSet.empty();
35
+ for (const ch of castlingPart) {
36
+ if (ch === "-")
37
+ continue;
38
+ let square;
39
+ if (ch === "K")
40
+ square = 7;
41
+ else if (ch === "Q")
42
+ square = 0;
43
+ else if (ch === "k")
44
+ square = 63;
45
+ else if (ch === "q")
46
+ square = 56;
47
+ else if (ch >= "A" && ch <= "H")
48
+ square = ch.charCodeAt(0) - 65; // white backrank file
49
+ else if (ch >= "a" && ch <= "h")
50
+ square = 56 + (ch.charCodeAt(0) - 97); // black backrank file
51
+ else
52
+ return Result.err(new FenError(InvalidFen.Castling));
53
+ const piece = board.get(square);
54
+ const expectedColor = ch === ch.toUpperCase() ? "white" : "black";
55
+ if (!piece || piece.role !== "rook" || piece.color !== expectedColor) {
56
+ return Result.err(new FenError(InvalidFen.Castling));
57
+ }
58
+ rights = rights.with(square);
59
+ }
60
+ return Result.ok(rights);
61
+ };
62
+ export const parseFen = (fen) => {
63
+ const r = engineFen.parseFen(fen);
64
+ if (!r.ok)
65
+ return Result.err(new FenError(r.error?.code ?? InvalidFen.Fen));
66
+ return Result.ok(setupFromEngine(r.value));
67
+ };
68
+ export const makeFen = (setup, opts) => {
69
+ const full = engineFen.makeFen(setupToEngine(setup));
70
+ return opts?.epd ? full.split(" ").slice(0, 4).join(" ") : full;
71
+ };
72
+ export const makeBoardFen = (board) => {
73
+ return engineMakePlacement(boardToEngine(board));
74
+ };
@@ -0,0 +1,15 @@
1
+ import type { Board as EngineBoard } from "../board.js";
2
+ export declare const INITIAL_BOARD_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
3
+ export declare const INITIAL_EPD = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -";
4
+ export declare const INITIAL_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
5
+ export declare const EMPTY_BOARD_FEN = "8/8/8/8/8/8/8/8";
6
+ export declare const EMPTY_EPD = "8/8/8/8/8/8/8/8 w - -";
7
+ export declare const EMPTY_FEN = "8/8/8/8/8/8/8/8 w - - 0 1";
8
+ /** Parses a board placement field into an engine Board (throws on garbage —
9
+ * callers wrap into Result). */
10
+ export declare function engineBoardFromPlacement(placement: string): EngineBoard;
11
+ /** Renders just the piece-placement field of an engine Board (no castling/ep
12
+ * counters — those need a real Setup, which callers with one should use
13
+ * engineMakeFen for directly). */
14
+ export declare function engineMakePlacement(board: EngineBoard): string;
15
+ //# sourceMappingURL=fenInternal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fenInternal.d.ts","sourceRoot":"","sources":["../../src/chessops/fenInternal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAIxD,eAAO,MAAM,iBAAiB,gDAAgD,CAAC;AAC/E,eAAO,MAAM,WAAW,yDAAyD,CAAC;AAClF,eAAO,MAAM,WAAW,6DAA6D,CAAC;AACtF,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,SAAS,0BAA0B,CAAC;AACjD,eAAO,MAAM,SAAS,8BAA8B,CAAC;AAErD;gCACgC;AAChC,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAIvE;AAWD;;kCAEkC;AAClC,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAU9D"}
@@ -0,0 +1,42 @@
1
+ // src/baseline/fenInternal.ts — engine bridge shared by the baseline-compatible
2
+ // facade modules (ADR-014). Not part of the public API. Single-sourced FEN
3
+ // constants + placement codecs (turbochess-adopt task 3.2; formerly
4
+ // `turbochess`, ADR-015).
5
+ import { parseFen as engineParseFen, makeFen as engineMakeFen } from "../fen.js";
6
+ import { Color } from "../types.js";
7
+ export const INITIAL_BOARD_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
8
+ export const INITIAL_EPD = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -";
9
+ export const INITIAL_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
10
+ export const EMPTY_BOARD_FEN = "8/8/8/8/8/8/8/8";
11
+ export const EMPTY_EPD = "8/8/8/8/8/8/8/8 w - -";
12
+ export const EMPTY_FEN = "8/8/8/8/8/8/8/8 w - - 0 1";
13
+ /** Parses a board placement field into an engine Board (throws on garbage —
14
+ * callers wrap into Result). */
15
+ export function engineBoardFromPlacement(placement) {
16
+ const parsed = engineParseFen(`${placement} w - - 0 1`);
17
+ if (!parsed.ok)
18
+ throw new Error(parsed.error?.code ?? "fen/invalidPiecePlacement");
19
+ return parsed.value.board;
20
+ }
21
+ const EMPTY_CASTLING = {
22
+ white: new Set(),
23
+ black: new Set(),
24
+ whiteKing: false,
25
+ whiteQueen: false,
26
+ blackKing: false,
27
+ blackQueen: false,
28
+ };
29
+ /** Renders just the piece-placement field of an engine Board (no castling/ep
30
+ * counters — those need a real Setup, which callers with one should use
31
+ * engineMakeFen for directly). */
32
+ export function engineMakePlacement(board) {
33
+ const setup = {
34
+ board,
35
+ turn: Color.White,
36
+ castling: EMPTY_CASTLING,
37
+ epSquare: null,
38
+ halfmoves: 0,
39
+ fullmoves: 1,
40
+ };
41
+ return engineMakeFen(setup).split(" ")[0];
42
+ }
@@ -0,0 +1,12 @@
1
+ export * from "./types.js";
2
+ export * from "./squareSet.js";
3
+ export * from "./board.js";
4
+ export * from "./setup.js";
5
+ export * from "./chess.js";
6
+ export * from "./fen.js";
7
+ export * from "./san.js";
8
+ export * from "./util.js";
9
+ export * from "./debug.js";
10
+ export { buildTree, pgnImport, pgnExport, build, TreeWrapperImpl, } from "../chesstree.js";
11
+ export type { TreeWrapper, TreeNode, Path, Comment, Glyph, Clock, Shape, Eval as TreeEval, Game, Player, AnalyseData, } from "../chesstree.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chessops/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAK3B,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,KAAK,EACL,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,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,iBAAiB,CAAC"}
@@ -0,0 +1,17 @@
1
+ // src/baseline/index.ts — baseline-compatible public API (ADR-014).
2
+ // Mirrors the baseline root module layout: `import { Chess, parseFen, ... }
3
+ // from "turbochess/chessops" (formerly turbochess/baseline, ADR-015)`. Backed by the immutable turbochess engine.
4
+ export * from "./types.js";
5
+ export * from "./squareSet.js";
6
+ export * from "./board.js";
7
+ export * from "./setup.js";
8
+ export * from "./chess.js";
9
+ export * from "./fen.js";
10
+ export * from "./san.js";
11
+ export * from "./util.js";
12
+ export * from "./debug.js";
13
+ // Integrated tree analysis (change turbochess-unified-api-and-perf, task 3.3):
14
+ // the workstation consumes chessops + chesstree from ONE package. Re-exports
15
+ // the clean-room chesstree layer (buildTree / pgnImport / pgnExport /
16
+ // TreeWrapper) alongside the chessops-shaped API.
17
+ export { buildTree, pgnImport, pgnExport, build, TreeWrapperImpl, } from "../chesstree.js";
@@ -0,0 +1,7 @@
1
+ import type { Position } from "./chess.js";
2
+ import type { Move } from "./types.js";
3
+ export declare const makeSan: (pos: Position, move: Move) => string;
4
+ export declare const makeSanAndPlay: (pos: Position, move: Move) => string;
5
+ export declare const makeSanVariation: (pos: Position, variation: Move[]) => string;
6
+ export declare const parseSan: (pos: Position, san: string) => Move | undefined;
7
+ //# sourceMappingURL=san.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"san.d.ts","sourceRoot":"","sources":["../../src/chessops/san.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,eAAO,MAAM,OAAO,GAAI,KAAK,QAAQ,EAAE,MAAM,IAAI,KAAG,MAInD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,QAAQ,EAAE,MAAM,IAAI,KAAG,MAI1D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,KAAK,QAAQ,EAAE,WAAW,IAAI,EAAE,KAAG,MASnE,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,QAAQ,EAAE,KAAK,MAAM,KAAG,IAAI,GAAG,SAI5D,CAAC"}
@@ -0,0 +1,33 @@
1
+ // src/baseline/san.ts — baseline-exact SAN API (ADR-014): position-first
2
+ // signatures, `parseSan` returns `Move | undefined`.
3
+ import * as engineSan from "../san.js";
4
+ import { isDrop } from "./types.js";
5
+ import { moveFromFacade, moveToFacade } from "./convert.js";
6
+ export const makeSan = (pos, move) => {
7
+ if (isDrop(move))
8
+ throw new Error("Drops are not supported in standard chess");
9
+ const epos = pos.eposInternal();
10
+ return engineSan.makeSan(moveFromFacade(epos, move), epos);
11
+ };
12
+ export const makeSanAndPlay = (pos, move) => {
13
+ const san = makeSan(pos, move);
14
+ pos.play(move);
15
+ return san;
16
+ };
17
+ export const makeSanVariation = (pos, variation) => {
18
+ const clone = pos.clone();
19
+ const parts = [];
20
+ for (const move of variation) {
21
+ if (isDrop(move))
22
+ throw new Error("Drops are not supported in standard chess");
23
+ parts.push(makeSan(clone, move));
24
+ clone.play(move);
25
+ }
26
+ return parts.join(" ");
27
+ };
28
+ export const parseSan = (pos, san) => {
29
+ const r = engineSan.parseSan(san, pos.eposInternal());
30
+ if (!r.ok)
31
+ return undefined;
32
+ return moveToFacade(r.value);
33
+ };
@@ -0,0 +1,64 @@
1
+ import { Board } from "./board.js";
2
+ import { SquareSet } from "./squareSet.js";
3
+ import type { ByColor, ByRole, Color, Role, Square } from "./types.js";
4
+ export declare class MaterialSide implements ByRole<number> {
5
+ pawn: number;
6
+ knight: number;
7
+ bishop: number;
8
+ rook: number;
9
+ queen: number;
10
+ king: number;
11
+ private constructor();
12
+ static empty(): MaterialSide;
13
+ static fromBoard(board: Board, color: Color): MaterialSide;
14
+ clone(): MaterialSide;
15
+ equals(other: MaterialSide): boolean;
16
+ add(other: MaterialSide): MaterialSide;
17
+ subtract(other: MaterialSide): MaterialSide;
18
+ nonEmpty(): boolean;
19
+ isEmpty(): boolean;
20
+ hasPawns(): boolean;
21
+ hasNonPawns(): boolean;
22
+ size(): number;
23
+ }
24
+ export declare class Material implements ByColor<MaterialSide> {
25
+ white: MaterialSide;
26
+ black: MaterialSide;
27
+ constructor(white: MaterialSide, black: MaterialSide);
28
+ static empty(): Material;
29
+ static fromBoard(board: Board): Material;
30
+ clone(): Material;
31
+ equals(other: Material): boolean;
32
+ add(other: Material): Material;
33
+ subtract(other: Material): Material;
34
+ count(role: Role): number;
35
+ size(): number;
36
+ isEmpty(): boolean;
37
+ nonEmpty(): boolean;
38
+ hasPawns(): boolean;
39
+ hasNonPawns(): boolean;
40
+ }
41
+ export declare class RemainingChecks implements ByColor<number> {
42
+ white: number;
43
+ black: number;
44
+ constructor(white: number, black: number);
45
+ static default(): RemainingChecks;
46
+ clone(): RemainingChecks;
47
+ equals(other: RemainingChecks): boolean;
48
+ }
49
+ /** A not necessarily legal standard-chess position (baseline-exact shape). */
50
+ export interface Setup {
51
+ board: Board;
52
+ pockets: Material | undefined;
53
+ turn: Color;
54
+ castlingRights: SquareSet;
55
+ epSquare: Square | undefined;
56
+ remainingChecks: RemainingChecks | undefined;
57
+ halfmoves: number;
58
+ fullmoves: number;
59
+ }
60
+ export declare const defaultSetup: () => Setup;
61
+ export declare const emptySetup: () => Setup;
62
+ export declare const setupClone: (setup: Setup) => Setup;
63
+ export declare const setupEquals: (left: Setup, right: Setup) => boolean;
64
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/chessops/setup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEvE,qBAAa,YAAa,YAAW,MAAM,CAAC,MAAM,CAAC;IACjD,IAAI,SAAK;IACT,MAAM,SAAK;IACX,MAAM,SAAK;IACX,IAAI,SAAK;IACT,KAAK,SAAK;IACV,IAAI,SAAK;IACT,OAAO;IACP,MAAM,CAAC,KAAK,IAAI,YAAY;IAG5B,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,YAAY;IAO1D,KAAK,IAAI,YAAY;IAKrB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAGpC,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY;IAKtC,QAA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,SAAS,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,eAAe,EAAE,eAAe,GAAG,SAAS,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,QAAO,KAS9B,CAAC;AAEH,eAAO,MAAM,UAAU,QAAO,KAS5B,CAAC;AAEH,eAAO,MAAM,UAAU,GAAI,OAAO,KAAK,KAAG,KASxC,CAAC;AAEH,eAAO,MAAM,WAAW,GAAI,MAAM,KAAK,EAAE,OAAO,KAAK,KAAG,OAMpB,CAAC"}
@@ -0,0 +1,158 @@
1
+ // src/baseline/setup.ts — baseline-exact Setup interface and helpers (ADR-014).
2
+ // Pockets/remainingChecks are always undefined: turbochess implements standard
3
+ // chess only (no Crazyhouse/3check — variants are out of project scope).
4
+ import { Board } from "./board.js";
5
+ import { SquareSet } from "./squareSet.js";
6
+ export class MaterialSide {
7
+ constructor() {
8
+ this.pawn = 0;
9
+ this.knight = 0;
10
+ this.bishop = 0;
11
+ this.rook = 0;
12
+ this.queen = 0;
13
+ this.king = 0;
14
+ }
15
+ static empty() {
16
+ return new MaterialSide();
17
+ }
18
+ static fromBoard(board, color) {
19
+ const m = MaterialSide.empty();
20
+ for (const role of ["pawn", "knight", "bishop", "rook", "queen", "king"]) {
21
+ m[role] = board.pieces(color, role).size();
22
+ }
23
+ return m;
24
+ }
25
+ clone() {
26
+ const m = MaterialSide.empty();
27
+ for (const role of ["pawn", "knight", "bishop", "rook", "queen", "king"])
28
+ m[role] = this[role];
29
+ return m;
30
+ }
31
+ equals(other) {
32
+ return ["pawn", "knight", "bishop", "rook", "queen", "king"].every((r) => this[r] === other[r]);
33
+ }
34
+ add(other) {
35
+ const m = this.clone();
36
+ for (const role of ["pawn", "knight", "bishop", "rook", "queen", "king"])
37
+ m[role] += other[role];
38
+ return m;
39
+ }
40
+ subtract(other) {
41
+ const m = this.clone();
42
+ for (const role of ["pawn", "knight", "bishop", "rook", "queen", "king"])
43
+ m[role] -= other[role];
44
+ return m;
45
+ }
46
+ nonEmpty() {
47
+ return !this.isEmpty();
48
+ }
49
+ isEmpty() {
50
+ return this.size() === 0;
51
+ }
52
+ hasPawns() {
53
+ return this.pawn > 0;
54
+ }
55
+ hasNonPawns() {
56
+ return this.knight + this.bishop + this.rook + this.queen + this.king > 0;
57
+ }
58
+ size() {
59
+ return this.pawn + this.knight + this.bishop + this.rook + this.queen + this.king;
60
+ }
61
+ }
62
+ export class Material {
63
+ constructor(white, black) {
64
+ this.white = white;
65
+ this.black = black;
66
+ }
67
+ static empty() {
68
+ return new Material(MaterialSide.empty(), MaterialSide.empty());
69
+ }
70
+ static fromBoard(board) {
71
+ return new Material(MaterialSide.fromBoard(board, "white"), MaterialSide.fromBoard(board, "black"));
72
+ }
73
+ clone() {
74
+ return new Material(this.white.clone(), this.black.clone());
75
+ }
76
+ equals(other) {
77
+ return this.white.equals(other.white) && this.black.equals(other.black);
78
+ }
79
+ add(other) {
80
+ return new Material(this.white.add(other.white), this.black.add(other.black));
81
+ }
82
+ subtract(other) {
83
+ return new Material(this.white.subtract(other.white), this.black.subtract(other.black));
84
+ }
85
+ count(role) {
86
+ return this.white[role] + this.black[role];
87
+ }
88
+ size() {
89
+ return this.white.size() + this.black.size();
90
+ }
91
+ isEmpty() {
92
+ return this.size() === 0;
93
+ }
94
+ nonEmpty() {
95
+ return !this.isEmpty();
96
+ }
97
+ hasPawns() {
98
+ return this.white.hasPawns() || this.black.hasPawns();
99
+ }
100
+ hasNonPawns() {
101
+ return this.white.hasNonPawns() || this.black.hasNonPawns();
102
+ }
103
+ }
104
+ export class RemainingChecks {
105
+ constructor(white, black) {
106
+ this.white = white;
107
+ this.black = black;
108
+ }
109
+ static default() {
110
+ return new RemainingChecks(0, 0);
111
+ }
112
+ clone() {
113
+ return new RemainingChecks(this.white, this.black);
114
+ }
115
+ equals(other) {
116
+ return this.white === other.white && this.black === other.black;
117
+ }
118
+ }
119
+ export const defaultSetup = () => ({
120
+ board: Board.default(),
121
+ pockets: undefined,
122
+ turn: "white",
123
+ castlingRights: new SquareSet(0x81, 0x81000000), // a1, h1, a8, h8
124
+ epSquare: undefined,
125
+ remainingChecks: undefined,
126
+ halfmoves: 0,
127
+ fullmoves: 1,
128
+ });
129
+ export const emptySetup = () => ({
130
+ board: Board.empty(),
131
+ pockets: undefined,
132
+ turn: "white",
133
+ castlingRights: SquareSet.empty(),
134
+ epSquare: undefined,
135
+ remainingChecks: undefined,
136
+ halfmoves: 0,
137
+ fullmoves: 1,
138
+ });
139
+ export const setupClone = (setup) => ({
140
+ board: setup.board.clone(),
141
+ pockets: setup.pockets?.clone(),
142
+ turn: setup.turn,
143
+ castlingRights: setup.castlingRights,
144
+ epSquare: setup.epSquare,
145
+ remainingChecks: setup.remainingChecks?.clone(),
146
+ halfmoves: setup.halfmoves,
147
+ fullmoves: setup.fullmoves,
148
+ });
149
+ export const setupEquals = (left, right) => boardEqualsShallow(left.board, right.board) &&
150
+ left.turn === right.turn &&
151
+ left.castlingRights.equals(right.castlingRights) &&
152
+ left.epSquare === right.epSquare &&
153
+ left.halfmoves === right.halfmoves &&
154
+ left.fullmoves === right.fullmoves;
155
+ function boardEqualsShallow(a, b) {
156
+ const fields = ["occupied", "promoted", "white", "black", "pawn", "knight", "bishop", "rook", "queen", "king"];
157
+ return fields.every((f) => a[f].equals(b[f]));
158
+ }
@@ -0,0 +1,48 @@
1
+ import type { Color, Square } from "./types.js";
2
+ export declare class SquareSet implements Iterable<Square> {
3
+ readonly lo: number;
4
+ readonly hi: number;
5
+ constructor(lo: number, hi: number);
6
+ static fromSquare(square: Square): SquareSet;
7
+ static fromRank(rank: number): SquareSet;
8
+ static fromFile(file: number): SquareSet;
9
+ static empty(): SquareSet;
10
+ static full(): SquareSet;
11
+ static corners(): SquareSet;
12
+ static center(): SquareSet;
13
+ static backranks(): SquareSet;
14
+ static backrank(color: Color): SquareSet;
15
+ static lightSquares(): SquareSet;
16
+ static darkSquares(): SquareSet;
17
+ complement(): SquareSet;
18
+ xor(other: SquareSet): SquareSet;
19
+ union(other: SquareSet): SquareSet;
20
+ intersect(other: SquareSet): SquareSet;
21
+ diff(other: SquareSet): SquareSet;
22
+ intersects(other: SquareSet): boolean;
23
+ isDisjoint(other: SquareSet): boolean;
24
+ supersetOf(other: SquareSet): boolean;
25
+ subsetOf(other: SquareSet): boolean;
26
+ shr64(shift: number): SquareSet;
27
+ shl64(shift: number): SquareSet;
28
+ bswap64(): SquareSet;
29
+ rbit64(): SquareSet;
30
+ minus64(other: SquareSet): SquareSet;
31
+ equals(other: SquareSet): boolean;
32
+ size(): number;
33
+ isEmpty(): boolean;
34
+ nonEmpty(): boolean;
35
+ has(square: Square): boolean;
36
+ set(square: Square, on: boolean): SquareSet;
37
+ with(square: Square): SquareSet;
38
+ without(square: Square): SquareSet;
39
+ toggle(square: Square): SquareSet;
40
+ last(): Square | undefined;
41
+ first(): Square | undefined;
42
+ withoutFirst(): SquareSet;
43
+ moreThanOne(): boolean;
44
+ singleSquare(): Square | undefined;
45
+ [Symbol.iterator](): Iterator<Square>;
46
+ reversed(): Iterable<Square>;
47
+ }
48
+ //# sourceMappingURL=squareSet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"squareSet.d.ts","sourceRoot":"","sources":["../../src/chessops/squareSet.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEhD,qBAAa,SAAU,YAAW,QAAQ,CAAC,MAAM,CAAC;IAChD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAER,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAOlC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAG5C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;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