js-chess-engine 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +586 -205
  2. package/dist/adapters/APIAdapter.d.ts +88 -0
  3. package/dist/adapters/APIAdapter.d.ts.map +1 -0
  4. package/dist/adapters/APIAdapter.js +225 -0
  5. package/dist/adapters/APIAdapter.js.map +1 -0
  6. package/dist/ai/AIEngine.d.ts +42 -0
  7. package/dist/ai/AIEngine.d.ts.map +1 -0
  8. package/dist/ai/AIEngine.js +62 -0
  9. package/dist/ai/AIEngine.js.map +1 -0
  10. package/dist/ai/Evaluator.d.ts +48 -0
  11. package/dist/ai/Evaluator.d.ts.map +1 -0
  12. package/dist/ai/Evaluator.js +248 -0
  13. package/dist/ai/Evaluator.js.map +1 -0
  14. package/dist/ai/MoveOrdering.d.ts +60 -0
  15. package/dist/ai/MoveOrdering.d.ts.map +1 -0
  16. package/dist/ai/MoveOrdering.js +173 -0
  17. package/dist/ai/MoveOrdering.js.map +1 -0
  18. package/dist/ai/Search.d.ts +62 -0
  19. package/dist/ai/Search.d.ts.map +1 -0
  20. package/dist/ai/Search.js +340 -0
  21. package/dist/ai/Search.js.map +1 -0
  22. package/dist/ai/TranspositionTable.d.ts +100 -0
  23. package/dist/ai/TranspositionTable.d.ts.map +1 -0
  24. package/dist/ai/TranspositionTable.js +176 -0
  25. package/dist/ai/TranspositionTable.js.map +1 -0
  26. package/dist/core/AttackDetector.d.ts +52 -0
  27. package/dist/core/AttackDetector.d.ts.map +1 -0
  28. package/dist/core/AttackDetector.js +397 -0
  29. package/dist/core/AttackDetector.js.map +1 -0
  30. package/dist/core/Board.d.ts +109 -0
  31. package/dist/core/Board.d.ts.map +1 -0
  32. package/dist/core/Board.js +410 -0
  33. package/dist/core/Board.js.map +1 -0
  34. package/dist/core/MoveGenerator.d.ts +48 -0
  35. package/dist/core/MoveGenerator.d.ts.map +1 -0
  36. package/dist/core/MoveGenerator.js +678 -0
  37. package/dist/core/MoveGenerator.js.map +1 -0
  38. package/dist/core/Position.d.ts +135 -0
  39. package/dist/core/Position.d.ts.map +1 -0
  40. package/dist/core/Position.js +351 -0
  41. package/dist/core/Position.js.map +1 -0
  42. package/dist/core/index.d.ts +9 -0
  43. package/dist/core/index.d.ts.map +1 -0
  44. package/dist/core/index.js +25 -0
  45. package/dist/core/index.js.map +1 -0
  46. package/dist/core/zobrist.d.ts +93 -0
  47. package/dist/core/zobrist.d.ts.map +1 -0
  48. package/dist/core/zobrist.js +273 -0
  49. package/dist/core/zobrist.js.map +1 -0
  50. package/dist/index.d.ts +154 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +353 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/types/ai.types.d.ts +97 -0
  55. package/dist/types/ai.types.d.ts.map +1 -0
  56. package/dist/types/ai.types.js +17 -0
  57. package/dist/types/ai.types.js.map +1 -0
  58. package/dist/types/board.types.d.ts +140 -0
  59. package/dist/types/board.types.d.ts.map +1 -0
  60. package/dist/types/board.types.js +34 -0
  61. package/dist/types/board.types.js.map +1 -0
  62. package/dist/types/index.d.ts +7 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +26 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/types/move.types.d.ts +70 -0
  67. package/dist/types/move.types.d.ts.map +1 -0
  68. package/dist/types/move.types.js +53 -0
  69. package/dist/types/move.types.js.map +1 -0
  70. package/dist/utils/constants.d.ts +123 -0
  71. package/dist/utils/constants.d.ts.map +1 -0
  72. package/dist/utils/constants.js +259 -0
  73. package/dist/utils/constants.js.map +1 -0
  74. package/dist/utils/conversion.d.ts +152 -0
  75. package/dist/utils/conversion.d.ts.map +1 -0
  76. package/dist/utils/conversion.js +288 -0
  77. package/dist/utils/conversion.js.map +1 -0
  78. package/dist/utils/environment.d.ts +33 -0
  79. package/dist/utils/environment.d.ts.map +1 -0
  80. package/dist/utils/environment.js +71 -0
  81. package/dist/utils/environment.js.map +1 -0
  82. package/dist/utils/fen.d.ts +28 -0
  83. package/dist/utils/fen.d.ts.map +1 -0
  84. package/dist/utils/fen.js +203 -0
  85. package/dist/utils/fen.js.map +1 -0
  86. package/package.json +29 -30
  87. package/.eslintrc.json +0 -16
  88. package/.github/workflows/main.yml +0 -20
  89. package/.nvmrc +0 -1
  90. package/CHANGELOG.md +0 -597
  91. package/dist/js-chess-engine.js +0 -1
  92. package/example/aiMatch.mjs +0 -21
  93. package/example/console.mjs +0 -37
  94. package/example/server.mjs +0 -27
  95. package/lib/Board.mjs +0 -946
  96. package/lib/const/board.mjs +0 -838
  97. package/lib/js-chess-engine.mjs +0 -99
  98. package/lib/utils.mjs +0 -154
  99. package/test/.eslintrc.json +0 -11
  100. package/test/ai.test.mjs +0 -132
  101. package/test/badge.svg +0 -1
  102. package/test/importExport.mjs +0 -108
  103. package/test/moves.test.mjs +0 -798
  104. package/webpack.config.js +0 -12
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Conversion utilities between square notation and internal indices
3
+ */
4
+ import { Square, SquareIndex, FileIndex, RankIndex } from '../types';
5
+ /**
6
+ * Convert square notation (e.g., "A1", "E4") to square index (0-63)
7
+ *
8
+ * Board layout:
9
+ * 56 57 58 59 60 61 62 63 (Rank 8) - A8 to H8
10
+ * 48 49 50 51 52 53 54 55 (Rank 7)
11
+ * ...
12
+ * 8 9 10 11 12 13 14 15 (Rank 2)
13
+ * 0 1 2 3 4 5 6 7 (Rank 1) - A1 to H1
14
+ *
15
+ * @param square - Square notation (case-insensitive)
16
+ * @returns Square index (0-63)
17
+ * @throws Error if square notation is invalid
18
+ */
19
+ export declare function squareToIndex(square: Square): SquareIndex;
20
+ /**
21
+ * Convert square index (0-63) to square notation (e.g., "A1", "E4")
22
+ *
23
+ * @param index - Square index (0-63)
24
+ * @returns Square notation in uppercase
25
+ * @throws Error if index is out of range
26
+ */
27
+ export declare function indexToSquare(index: SquareIndex): Square;
28
+ /**
29
+ * Get file index (0-7) from square index
30
+ *
31
+ * @param index - Square index (0-63)
32
+ * @returns File index (0=A, 1=B, ..., 7=H)
33
+ */
34
+ export declare function getFileIndex(index: SquareIndex): FileIndex;
35
+ /**
36
+ * Get rank index (0-7) from square index
37
+ *
38
+ * @param index - Square index (0-63)
39
+ * @returns Rank index (0=1, 1=2, ..., 7=8)
40
+ */
41
+ export declare function getRankIndex(index: SquareIndex): RankIndex;
42
+ /**
43
+ * Get file from square notation
44
+ *
45
+ * @param square - Square notation (case-insensitive)
46
+ * @returns File index (0-7)
47
+ */
48
+ export declare function getFile(square: Square): FileIndex;
49
+ /**
50
+ * Get rank from square notation
51
+ *
52
+ * @param square - Square notation (case-insensitive)
53
+ * @returns Rank index (0-7)
54
+ */
55
+ export declare function getRank(square: Square): RankIndex;
56
+ /**
57
+ * Create square index from file and rank indices
58
+ *
59
+ * @param file - File index (0-7)
60
+ * @param rank - Rank index (0-7)
61
+ * @returns Square index (0-63)
62
+ */
63
+ export declare function fileRankToIndex(file: FileIndex, rank: RankIndex): SquareIndex;
64
+ /**
65
+ * Check if square notation is valid
66
+ *
67
+ * @param square - Square notation
68
+ * @returns true if valid
69
+ */
70
+ export declare function isValidSquare(square: string): boolean;
71
+ /**
72
+ * Check if square index is valid
73
+ *
74
+ * @param index - Square index
75
+ * @returns true if valid (0-63)
76
+ */
77
+ export declare function isValidIndex(index: number): boolean;
78
+ /**
79
+ * Convert square index to bitboard (single bit set)
80
+ *
81
+ * @param index - Square index (0-63)
82
+ * @returns Bitboard with single bit set
83
+ */
84
+ export declare function indexToBitboard(index: SquareIndex): bigint;
85
+ /**
86
+ * Convert square notation to bitboard
87
+ *
88
+ * @param square - Square notation
89
+ * @returns Bitboard with single bit set
90
+ */
91
+ export declare function squareToBitboard(square: Square): bigint;
92
+ /**
93
+ * Get all set bits (square indices) from a bitboard
94
+ *
95
+ * @param bitboard - Bitboard to extract indices from
96
+ * @returns Array of square indices where bits are set
97
+ */
98
+ export declare function bitboardToIndices(bitboard: bigint): SquareIndex[];
99
+ /**
100
+ * Get the index of the lowest set bit in a bitboard
101
+ *
102
+ * @param bitboard - Bitboard
103
+ * @returns Index of lowest set bit, or -1 if no bits set
104
+ */
105
+ export declare function getLowestSetBit(bitboard: bigint): SquareIndex;
106
+ /**
107
+ * Count the number of set bits in a bitboard (population count)
108
+ *
109
+ * @param bitboard - Bitboard
110
+ * @returns Number of set bits
111
+ */
112
+ export declare function popCount(bitboard: bigint): number;
113
+ /**
114
+ * Calculate Manhattan distance between two squares
115
+ *
116
+ * @param from - Source square index
117
+ * @param to - Target square index
118
+ * @returns Manhattan distance
119
+ */
120
+ export declare function manhattanDistance(from: SquareIndex, to: SquareIndex): number;
121
+ /**
122
+ * Calculate Chebyshev distance between two squares (king moves)
123
+ *
124
+ * @param from - Source square index
125
+ * @param to - Target square index
126
+ * @returns Chebyshev distance
127
+ */
128
+ export declare function chebyshevDistance(from: SquareIndex, to: SquareIndex): number;
129
+ /**
130
+ * Check if a square is on the edge of the board
131
+ *
132
+ * @param index - Square index
133
+ * @returns true if on edge
134
+ */
135
+ export declare function isOnEdge(index: SquareIndex): boolean;
136
+ /**
137
+ * Check if square is on A-file
138
+ */
139
+ export declare function isAFile(index: SquareIndex): boolean;
140
+ /**
141
+ * Check if square is on H-file
142
+ */
143
+ export declare function isHFile(index: SquareIndex): boolean;
144
+ /**
145
+ * Check if square is on rank 1
146
+ */
147
+ export declare function isRank1(index: SquareIndex): boolean;
148
+ /**
149
+ * Check if square is on rank 8
150
+ */
151
+ export declare function isRank8(index: SquareIndex): boolean;
152
+ //# sourceMappingURL=conversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../src/utils/conversion.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAe,MAAM,UAAU,CAAC;AAKlF;;;;;;;;;;;;;GAaG;AACH,w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GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,GAAG,MAAM,CAO5E;AAID;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAIpD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEnD"}
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ /**
3
+ * Conversion utilities between square notation and internal indices
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.squareToIndex = squareToIndex;
7
+ exports.indexToSquare = indexToSquare;
8
+ exports.getFileIndex = getFileIndex;
9
+ exports.getRankIndex = getRankIndex;
10
+ exports.getFile = getFile;
11
+ exports.getRank = getRank;
12
+ exports.fileRankToIndex = fileRankToIndex;
13
+ exports.isValidSquare = isValidSquare;
14
+ exports.isValidIndex = isValidIndex;
15
+ exports.indexToBitboard = indexToBitboard;
16
+ exports.squareToBitboard = squareToBitboard;
17
+ exports.bitboardToIndices = bitboardToIndices;
18
+ exports.getLowestSetBit = getLowestSetBit;
19
+ exports.popCount = popCount;
20
+ exports.manhattanDistance = manhattanDistance;
21
+ exports.chebyshevDistance = chebyshevDistance;
22
+ exports.isOnEdge = isOnEdge;
23
+ exports.isAFile = isAFile;
24
+ exports.isHFile = isHFile;
25
+ exports.isRank1 = isRank1;
26
+ exports.isRank8 = isRank8;
27
+ const constants_1 = require("./constants");
28
+ // ==================== Square ↔ Index Conversion ====================
29
+ /**
30
+ * Convert square notation (e.g., "A1", "E4") to square index (0-63)
31
+ *
32
+ * Board layout:
33
+ * 56 57 58 59 60 61 62 63 (Rank 8) - A8 to H8
34
+ * 48 49 50 51 52 53 54 55 (Rank 7)
35
+ * ...
36
+ * 8 9 10 11 12 13 14 15 (Rank 2)
37
+ * 0 1 2 3 4 5 6 7 (Rank 1) - A1 to H1
38
+ *
39
+ * @param square - Square notation (case-insensitive)
40
+ * @returns Square index (0-63)
41
+ * @throws Error if square notation is invalid
42
+ */
43
+ function squareToIndex(square) {
44
+ const normalized = square.toUpperCase();
45
+ if (normalized.length !== 2) {
46
+ throw new Error(`Invalid square notation: ${square}`);
47
+ }
48
+ const file = normalized[0];
49
+ const rank = normalized[1];
50
+ const fileIndex = constants_1.COLUMNS.indexOf(file);
51
+ const rankIndex = constants_1.ROWS.indexOf(rank);
52
+ if (fileIndex === -1 || rankIndex === -1) {
53
+ throw new Error(`Invalid square notation: ${square}`);
54
+ }
55
+ return (rankIndex * 8 + fileIndex);
56
+ }
57
+ /**
58
+ * Convert square index (0-63) to square notation (e.g., "A1", "E4")
59
+ *
60
+ * @param index - Square index (0-63)
61
+ * @returns Square notation in uppercase
62
+ * @throws Error if index is out of range
63
+ */
64
+ function indexToSquare(index) {
65
+ if (index < 0 || index > 63) {
66
+ throw new Error(`Invalid square index: ${index}`);
67
+ }
68
+ const fileIndex = index % 8;
69
+ const rankIndex = Math.floor(index / 8);
70
+ return `${constants_1.COLUMNS[fileIndex]}${constants_1.ROWS[rankIndex]}`;
71
+ }
72
+ // ==================== File/Rank Conversion ====================
73
+ /**
74
+ * Get file index (0-7) from square index
75
+ *
76
+ * @param index - Square index (0-63)
77
+ * @returns File index (0=A, 1=B, ..., 7=H)
78
+ */
79
+ function getFileIndex(index) {
80
+ return (index % 8);
81
+ }
82
+ /**
83
+ * Get rank index (0-7) from square index
84
+ *
85
+ * @param index - Square index (0-63)
86
+ * @returns Rank index (0=1, 1=2, ..., 7=8)
87
+ */
88
+ function getRankIndex(index) {
89
+ return Math.floor(index / 8);
90
+ }
91
+ /**
92
+ * Get file from square notation
93
+ *
94
+ * @param square - Square notation (case-insensitive)
95
+ * @returns File index (0-7)
96
+ */
97
+ function getFile(square) {
98
+ const normalized = square.toUpperCase();
99
+ const fileIndex = constants_1.COLUMNS.indexOf(normalized[0]);
100
+ if (fileIndex === -1) {
101
+ throw new Error(`Invalid square notation: ${square}`);
102
+ }
103
+ return fileIndex;
104
+ }
105
+ /**
106
+ * Get rank from square notation
107
+ *
108
+ * @param square - Square notation (case-insensitive)
109
+ * @returns Rank index (0-7)
110
+ */
111
+ function getRank(square) {
112
+ const normalized = square.toUpperCase();
113
+ const rankIndex = constants_1.ROWS.indexOf(normalized[1]);
114
+ if (rankIndex === -1) {
115
+ throw new Error(`Invalid square notation: ${square}`);
116
+ }
117
+ return rankIndex;
118
+ }
119
+ /**
120
+ * Create square index from file and rank indices
121
+ *
122
+ * @param file - File index (0-7)
123
+ * @param rank - Rank index (0-7)
124
+ * @returns Square index (0-63)
125
+ */
126
+ function fileRankToIndex(file, rank) {
127
+ return (rank * 8 + file);
128
+ }
129
+ // ==================== Validation ====================
130
+ /**
131
+ * Check if square notation is valid
132
+ *
133
+ * @param square - Square notation
134
+ * @returns true if valid
135
+ */
136
+ function isValidSquare(square) {
137
+ if (typeof square !== 'string' || square.length !== 2) {
138
+ return false;
139
+ }
140
+ const normalized = square.toUpperCase();
141
+ const file = normalized[0];
142
+ const rank = normalized[1];
143
+ return constants_1.COLUMNS.includes(file) && constants_1.ROWS.includes(rank);
144
+ }
145
+ /**
146
+ * Check if square index is valid
147
+ *
148
+ * @param index - Square index
149
+ * @returns true if valid (0-63)
150
+ */
151
+ function isValidIndex(index) {
152
+ return Number.isInteger(index) && index >= 0 && index <= 63;
153
+ }
154
+ // ==================== Bitboard Helpers ====================
155
+ /**
156
+ * Convert square index to bitboard (single bit set)
157
+ *
158
+ * @param index - Square index (0-63)
159
+ * @returns Bitboard with single bit set
160
+ */
161
+ function indexToBitboard(index) {
162
+ return 1n << BigInt(index);
163
+ }
164
+ /**
165
+ * Convert square notation to bitboard
166
+ *
167
+ * @param square - Square notation
168
+ * @returns Bitboard with single bit set
169
+ */
170
+ function squareToBitboard(square) {
171
+ return indexToBitboard(squareToIndex(square));
172
+ }
173
+ /**
174
+ * Get all set bits (square indices) from a bitboard
175
+ *
176
+ * @param bitboard - Bitboard to extract indices from
177
+ * @returns Array of square indices where bits are set
178
+ */
179
+ function bitboardToIndices(bitboard) {
180
+ const indices = [];
181
+ let bb = bitboard;
182
+ while (bb !== 0n) {
183
+ const index = getLowestSetBit(bb);
184
+ indices.push(index);
185
+ bb &= bb - 1n; // Clear lowest set bit
186
+ }
187
+ return indices;
188
+ }
189
+ /**
190
+ * Get the index of the lowest set bit in a bitboard
191
+ *
192
+ * @param bitboard - Bitboard
193
+ * @returns Index of lowest set bit, or -1 if no bits set
194
+ */
195
+ function getLowestSetBit(bitboard) {
196
+ if (bitboard === 0n) {
197
+ return -1;
198
+ }
199
+ // Count trailing zeros
200
+ let index = 0;
201
+ let bb = bitboard;
202
+ while ((bb & 1n) === 0n) {
203
+ bb >>= 1n;
204
+ index++;
205
+ }
206
+ return index;
207
+ }
208
+ /**
209
+ * Count the number of set bits in a bitboard (population count)
210
+ *
211
+ * @param bitboard - Bitboard
212
+ * @returns Number of set bits
213
+ */
214
+ function popCount(bitboard) {
215
+ let count = 0;
216
+ let bb = bitboard;
217
+ while (bb !== 0n) {
218
+ bb &= bb - 1n; // Clear lowest set bit
219
+ count++;
220
+ }
221
+ return count;
222
+ }
223
+ // ==================== Distance Calculations ====================
224
+ /**
225
+ * Calculate Manhattan distance between two squares
226
+ *
227
+ * @param from - Source square index
228
+ * @param to - Target square index
229
+ * @returns Manhattan distance
230
+ */
231
+ function manhattanDistance(from, to) {
232
+ const fromFile = getFileIndex(from);
233
+ const fromRank = getRankIndex(from);
234
+ const toFile = getFileIndex(to);
235
+ const toRank = getRankIndex(to);
236
+ return Math.abs(fromFile - toFile) + Math.abs(fromRank - toRank);
237
+ }
238
+ /**
239
+ * Calculate Chebyshev distance between two squares (king moves)
240
+ *
241
+ * @param from - Source square index
242
+ * @param to - Target square index
243
+ * @returns Chebyshev distance
244
+ */
245
+ function chebyshevDistance(from, to) {
246
+ const fromFile = getFileIndex(from);
247
+ const fromRank = getRankIndex(from);
248
+ const toFile = getFileIndex(to);
249
+ const toRank = getRankIndex(to);
250
+ return Math.max(Math.abs(fromFile - toFile), Math.abs(fromRank - toRank));
251
+ }
252
+ // ==================== Board Boundaries ====================
253
+ /**
254
+ * Check if a square is on the edge of the board
255
+ *
256
+ * @param index - Square index
257
+ * @returns true if on edge
258
+ */
259
+ function isOnEdge(index) {
260
+ const file = getFileIndex(index);
261
+ const rank = getRankIndex(index);
262
+ return file === 0 || file === 7 || rank === 0 || rank === 7;
263
+ }
264
+ /**
265
+ * Check if square is on A-file
266
+ */
267
+ function isAFile(index) {
268
+ return getFileIndex(index) === 0;
269
+ }
270
+ /**
271
+ * Check if square is on H-file
272
+ */
273
+ function isHFile(index) {
274
+ return getFileIndex(index) === 7;
275
+ }
276
+ /**
277
+ * Check if square is on rank 1
278
+ */
279
+ function isRank1(index) {
280
+ return getRankIndex(index) === 0;
281
+ }
282
+ /**
283
+ * Check if square is on rank 8
284
+ */
285
+ function isRank8(index) {
286
+ return getRankIndex(index) === 7;
287
+ }
288
+ //# sourceMappingURL=conversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversion.js","sourceRoot":"","sources":["../../src/utils/conversion.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqBH,sCAkBC;AASD,sCASC;AAUD,oCAEC;AAQD,oCAEC;AAQD,0BAOC;AAQD,0BAOC;AASD,0CAEC;AAUD,sCAUC;AAQD,oCAEC;AAUD,0CAEC;AAQD,4CAEC;AAQD,8CAWC;AAQD,0CAeC;AAQD,4BAUC;AAWD,8CAOC;AASD,8CAOC;AAUD,4BAIC;AAKD,0BAEC;AAKD,0BAEC;AAKD,0BAEC;AAKD,0BAEC;AAjTD,2CAA4C;AAE5C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,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,6DAA6D;AAE7D;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAkB;IACvC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAkB;IACtC,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAkB;IACtC,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAkB;IACtC,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAC,KAAkB;IACtC,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Environment detection utilities
3
+ * Helps optimize memory usage based on runtime environment
4
+ */
5
+ /**
6
+ * Detect if code is running in Node.js environment
7
+ *
8
+ * @returns true if running in Node.js, false if in browser
9
+ */
10
+ export declare function isNodeEnvironment(): boolean;
11
+ /**
12
+ * Detect if code is running in browser environment
13
+ *
14
+ * @returns true if running in browser, false if in Node.js
15
+ */
16
+ export declare function isBrowserEnvironment(): boolean;
17
+ /**
18
+ * Get default transposition table size based on environment
19
+ *
20
+ * Node.js: 16 MB (ample memory available)
21
+ * Browser: 1 MB (more conservative for web/mobile)
22
+ *
23
+ * @returns Recommended TT size in MB
24
+ */
25
+ export declare function getDefaultTTSize(): number;
26
+ /**
27
+ * Get recommended TT size for a given AI level and environment
28
+ *
29
+ * @param level - AI difficulty level (1-5)
30
+ * @returns Recommended TT size in MB
31
+ */
32
+ export declare function getRecommendedTTSize(level: number): number;
33
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAO3C;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAsB1D"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Environment detection utilities
4
+ * Helps optimize memory usage based on runtime environment
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isNodeEnvironment = isNodeEnvironment;
8
+ exports.isBrowserEnvironment = isBrowserEnvironment;
9
+ exports.getDefaultTTSize = getDefaultTTSize;
10
+ exports.getRecommendedTTSize = getRecommendedTTSize;
11
+ /**
12
+ * Detect if code is running in Node.js environment
13
+ *
14
+ * @returns true if running in Node.js, false if in browser
15
+ */
16
+ function isNodeEnvironment() {
17
+ // Check for Node.js-specific globals
18
+ return (typeof process !== 'undefined' &&
19
+ process.versions != null &&
20
+ process.versions.node != null);
21
+ }
22
+ /**
23
+ * Detect if code is running in browser environment
24
+ *
25
+ * @returns true if running in browser, false if in Node.js
26
+ */
27
+ function isBrowserEnvironment() {
28
+ return !isNodeEnvironment();
29
+ }
30
+ /**
31
+ * Get default transposition table size based on environment
32
+ *
33
+ * Node.js: 16 MB (ample memory available)
34
+ * Browser: 1 MB (more conservative for web/mobile)
35
+ *
36
+ * @returns Recommended TT size in MB
37
+ */
38
+ function getDefaultTTSize() {
39
+ return isNodeEnvironment() ? 16 : 1;
40
+ }
41
+ /**
42
+ * Get recommended TT size for a given AI level and environment
43
+ *
44
+ * @param level - AI difficulty level (1-5)
45
+ * @returns Recommended TT size in MB
46
+ */
47
+ function getRecommendedTTSize(level) {
48
+ if (isNodeEnvironment()) {
49
+ // Node.js - more generous memory allocation
50
+ const nodeSizes = {
51
+ 1: 2, // Level 1: 2 MB
52
+ 2: 4, // Level 2: 4 MB
53
+ 3: 16, // Level 3: 16 MB (default)
54
+ 4: 32, // Level 4: 32 MB
55
+ 5: 64, // Level 5: 64 MB
56
+ };
57
+ return nodeSizes[level] ?? 16;
58
+ }
59
+ else {
60
+ // Browser - modern-device-friendly allocation (reasonable for 2024+ devices)
61
+ const browserSizes = {
62
+ 1: 1, // Level 1: 1 MB (lightweight, older devices)
63
+ 2: 2, // Level 2: 2 MB (mobile-friendly)
64
+ 3: 8, // Level 3: 8 MB (balanced default - appropriate for modern browsers)
65
+ 4: 16, // Level 4: 16 MB (strong performance)
66
+ 5: 32, // Level 5: 32 MB (maximum strength)
67
+ };
68
+ return browserSizes[level] ?? 8;
69
+ }
70
+ }
71
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,8CAOC;AAOD,oDAEC;AAUD,4CAEC;AAQD,oDAsBC;AA/DD;;;;GAIG;AACH,SAAgB,iBAAiB;IAC7B,qCAAqC;IACrC,OAAO,CACH,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAChC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB;IAChC,OAAO,CAAC,iBAAiB,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB;IAC5B,OAAO,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAC9C,IAAI,iBAAiB,EAAE,EAAE,CAAC;QACtB,4CAA4C;QAC5C,MAAM,SAAS,GAA2B;YACtC,CAAC,EAAE,CAAC,EAAI,gBAAgB;YACxB,CAAC,EAAE,CAAC,EAAI,gBAAgB;YACxB,CAAC,EAAE,EAAE,EAAG,2BAA2B;YACnC,CAAC,EAAE,EAAE,EAAG,iBAAiB;YACzB,CAAC,EAAE,EAAE,EAAG,iBAAiB;SAC5B,CAAC;QACF,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;SAAM,CAAC;QACJ,6EAA6E;QAC7E,MAAM,YAAY,GAA2B;YACzC,CAAC,EAAE,CAAC,EAAK,6CAA6C;YACtD,CAAC,EAAE,CAAC,EAAK,kCAAkC;YAC3C,CAAC,EAAE,CAAC,EAAK,qEAAqE;YAC9E,CAAC,EAAE,EAAE,EAAI,sCAAsC;YAC/C,CAAC,EAAE,EAAE,EAAI,oCAAoC;SAChD,CAAC;QACF,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;AACL,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * FEN (Forsyth-Edwards Notation) parser and formatter
3
+ *
4
+ * FEN format: pieces turn castling enPassant halfMove fullMove
5
+ * Example: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
6
+ */
7
+ import { InternalBoard } from '../types';
8
+ /**
9
+ * Parse a FEN string into an internal board
10
+ *
11
+ * @param fen - FEN string
12
+ * @returns Internal board representation
13
+ */
14
+ export declare function parseFEN(fen: string): InternalBoard;
15
+ /**
16
+ * Convert an internal board to a FEN string
17
+ *
18
+ * @param board - Internal board
19
+ * @returns FEN string
20
+ */
21
+ export declare function toFEN(board: InternalBoard): string;
22
+ /**
23
+ * Get FEN for starting position
24
+ *
25
+ * @returns FEN string for standard chess starting position
26
+ */
27
+ export declare function getStartingFEN(): string;
28
+ //# sourceMappingURL=fen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fen.d.ts","sourceRoot":"","sources":["../../src/utils/fen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAqC,MAAM,UAAU,CAAC;AAI5E;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CA+EnD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAyDlD;AAkDD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}