gigachess 0.4.2 → 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/board.d.ts +38 -0
- package/dist/board.d.ts.map +1 -1
- package/dist/board.js +37 -1
- package/dist/san.d.ts +23 -0
- package/dist/san.d.ts.map +1 -1
- package/dist/san.js +70 -17
- package/package.json +2 -2
package/dist/board.d.ts
CHANGED
|
@@ -135,7 +135,45 @@ export declare class Board implements BoardLike {
|
|
|
135
135
|
toUci(moveWord: number): string;
|
|
136
136
|
toFen(): string;
|
|
137
137
|
parseSan(san: string): number | null;
|
|
138
|
+
/**
|
|
139
|
+
* `parseSan` with the failure reason kept.
|
|
140
|
+
*
|
|
141
|
+
* `parseSan` maps every error — `san/ambiguous`, `san/noLegalMove`,
|
|
142
|
+
* `san/invalidSan` — onto the same `null`, so a caller cannot tell "no such
|
|
143
|
+
* move" from "several moves answer to this and you must disambiguate". Those
|
|
144
|
+
* are different answers for a UI: one is an error, the other needs the
|
|
145
|
+
* candidates named (BlindBase ADR-042, field report #11).
|
|
146
|
+
*
|
|
147
|
+
* The error code is returned rather than a richer object because the codes
|
|
148
|
+
* are the library's own error vocabulary (`SanError["code"]`), already
|
|
149
|
+
* documented and already i18n-keyed upstream.
|
|
150
|
+
*/
|
|
151
|
+
parseSanResult(san: string): {
|
|
152
|
+
ok: true;
|
|
153
|
+
moveWord: number;
|
|
154
|
+
} | {
|
|
155
|
+
ok: false;
|
|
156
|
+
code: string;
|
|
157
|
+
};
|
|
138
158
|
parseUci(uci: string): number | null;
|
|
159
|
+
/**
|
|
160
|
+
* Every packed move word `san` could denote here, or the reason it names none.
|
|
161
|
+
*
|
|
162
|
+
* `parseSan` reports `san/ambiguous` and discards the matches, so a caller
|
|
163
|
+
* can tell the user the input was ambiguous but not which moves it meant.
|
|
164
|
+
* This returns them, letting a caller present the disambiguated spellings
|
|
165
|
+
* rather than making the user guess (BlindBase ADR-042, field report #11).
|
|
166
|
+
*
|
|
167
|
+
* A resolved move comes back as a one-element array, so this can replace
|
|
168
|
+
* `parseSan` wherever the caller only needs "one move, or a reason".
|
|
169
|
+
*/
|
|
170
|
+
parseSanCandidates(san: string): {
|
|
171
|
+
ok: true;
|
|
172
|
+
moveWords: number[];
|
|
173
|
+
} | {
|
|
174
|
+
ok: false;
|
|
175
|
+
code: string;
|
|
176
|
+
};
|
|
139
177
|
perft(depth: number): number;
|
|
140
178
|
}
|
|
141
179
|
export type WritableBoard = {
|
package/dist/board.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../src/board.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAS,IAAI,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAkBxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAWlD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,Q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,OAAO,CAMrE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAa/D"}
|
package/dist/board.js
CHANGED
|
@@ -8,7 +8,7 @@ import { zobristTablesLoaded, calculateZobrist, zobristHex, pieceKeyIdx, castlin
|
|
|
8
8
|
import { CASTLE_CLEAR_STD, CASTLING_RIGHTS_TABLE, getCastlingMask, detectCastling, } from "./castling.js";
|
|
9
9
|
import { packOf, unpackToMove, promoCodeToRole, isNull, } from "./packedMove.js";
|
|
10
10
|
import { parseFen, makeFen } from "./fen.js";
|
|
11
|
-
import { parseSan, makeSan, parseUci, makeUci } from "./san.js";
|
|
11
|
+
import { parseSan, parseSanCandidates, makeSan, parseUci, makeUci } from "./san.js";
|
|
12
12
|
import { legalMovesInto, forEachLegalMove, countLegalMoves, isLegal, INITIAL_FEN } from "./chess.js";
|
|
13
13
|
export class Board {
|
|
14
14
|
constructor(input) {
|
|
@@ -785,10 +785,46 @@ export class Board {
|
|
|
785
785
|
const res = parseSan(san, this);
|
|
786
786
|
return res.ok ? packOf(res.value) : null;
|
|
787
787
|
}
|
|
788
|
+
/**
|
|
789
|
+
* `parseSan` with the failure reason kept.
|
|
790
|
+
*
|
|
791
|
+
* `parseSan` maps every error — `san/ambiguous`, `san/noLegalMove`,
|
|
792
|
+
* `san/invalidSan` — onto the same `null`, so a caller cannot tell "no such
|
|
793
|
+
* move" from "several moves answer to this and you must disambiguate". Those
|
|
794
|
+
* are different answers for a UI: one is an error, the other needs the
|
|
795
|
+
* candidates named (BlindBase ADR-042, field report #11).
|
|
796
|
+
*
|
|
797
|
+
* The error code is returned rather than a richer object because the codes
|
|
798
|
+
* are the library's own error vocabulary (`SanError["code"]`), already
|
|
799
|
+
* documented and already i18n-keyed upstream.
|
|
800
|
+
*/
|
|
801
|
+
parseSanResult(san) {
|
|
802
|
+
const res = parseSan(san, this);
|
|
803
|
+
return res.ok
|
|
804
|
+
? { ok: true, moveWord: packOf(res.value) }
|
|
805
|
+
: { ok: false, code: res.error.code };
|
|
806
|
+
}
|
|
788
807
|
parseUci(uci) {
|
|
789
808
|
const res = parseUci(uci);
|
|
790
809
|
return res.ok && isLegal(this, res.value) ? packOf(res.value) : null;
|
|
791
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Every packed move word `san` could denote here, or the reason it names none.
|
|
813
|
+
*
|
|
814
|
+
* `parseSan` reports `san/ambiguous` and discards the matches, so a caller
|
|
815
|
+
* can tell the user the input was ambiguous but not which moves it meant.
|
|
816
|
+
* This returns them, letting a caller present the disambiguated spellings
|
|
817
|
+
* rather than making the user guess (BlindBase ADR-042, field report #11).
|
|
818
|
+
*
|
|
819
|
+
* A resolved move comes back as a one-element array, so this can replace
|
|
820
|
+
* `parseSan` wherever the caller only needs "one move, or a reason".
|
|
821
|
+
*/
|
|
822
|
+
parseSanCandidates(san) {
|
|
823
|
+
const res = parseSanCandidates(san, this);
|
|
824
|
+
return res.ok
|
|
825
|
+
? { ok: true, moveWords: res.value.map(packOf) }
|
|
826
|
+
: { ok: false, code: res.error.code };
|
|
827
|
+
}
|
|
792
828
|
perft(depth) {
|
|
793
829
|
if (depth <= 0)
|
|
794
830
|
return 1;
|
package/dist/san.d.ts
CHANGED
|
@@ -10,6 +10,29 @@ export declare const NULL_MOVE_SANS: readonly string[];
|
|
|
10
10
|
export declare function isNullMoveSan(san: string): boolean;
|
|
11
11
|
export declare function makeSan(move: Move, pos: Position): string;
|
|
12
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>;
|
|
13
36
|
export declare function parseUci(uci: string): Result<Move, UciError>;
|
|
14
37
|
export declare function makeUci(move: Move): string;
|
|
15
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;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,
|
|
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
|
@@ -206,6 +206,60 @@ export function makeSan(move, pos) {
|
|
|
206
206
|
}
|
|
207
207
|
// ---------- parseSan ----------
|
|
208
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 });
|
|
209
263
|
const orig = san;
|
|
210
264
|
let s = normalizeCastlingSan(san.trim());
|
|
211
265
|
// Null move (pass) — exactly `--` or `Z0`, matched BEFORE any check-suffix
|
|
@@ -214,8 +268,8 @@ export function parseSan(san, pos) {
|
|
|
214
268
|
// the attack tables, never from the cached `checkers` bitboard.
|
|
215
269
|
if (isNullMoveSan(s)) {
|
|
216
270
|
if (!chess.isNullMoveLegal(pos))
|
|
217
|
-
return
|
|
218
|
-
return Ok(nullMove());
|
|
271
|
+
return fail("san/illegal");
|
|
272
|
+
return { result: Ok(nullMove()), candidates: [nullMove()] };
|
|
219
273
|
}
|
|
220
274
|
// Handle check suffix for later, but keep for validation
|
|
221
275
|
let checkSuffix = "";
|
|
@@ -228,7 +282,7 @@ export function parseSan(san, pos) {
|
|
|
228
282
|
const isKingSide = s === "O-O";
|
|
229
283
|
const kingSq = board.kingSquare(pos.board, pos.turn);
|
|
230
284
|
if (kingSq === undefined)
|
|
231
|
-
return
|
|
285
|
+
return fail("san/noKing");
|
|
232
286
|
// Find if castling is legal via dests. The generated dest is the
|
|
233
287
|
// representation's castling square: normalized landing (6/2/62/58) or the
|
|
234
288
|
// right's rook square (baseline/960 form). Both are accepted.
|
|
@@ -249,12 +303,12 @@ export function parseSan(san, pos) {
|
|
|
249
303
|
}
|
|
250
304
|
}
|
|
251
305
|
if (dest === undefined)
|
|
252
|
-
return
|
|
306
|
+
return fail("san/illegal");
|
|
253
307
|
const move = { from: kingSq, to: dest, isCastling: true, isEnPassant: false, isPromotion: false, promotion: null };
|
|
254
308
|
// Optionally validate check suffix matches actual
|
|
255
309
|
// We ignore mismatch for parsing tolerance, but we could validate
|
|
256
310
|
// If checkSuffix present, we could verify after play, but not required to error
|
|
257
|
-
return Ok(move);
|
|
311
|
+
return { result: Ok(move), candidates: [move] };
|
|
258
312
|
}
|
|
259
313
|
// Promotion handling
|
|
260
314
|
let promotion = undefined;
|
|
@@ -262,20 +316,20 @@ export function parseSan(san, pos) {
|
|
|
262
316
|
if (eqIdx !== -1) {
|
|
263
317
|
const promoChar = s[eqIdx + 1];
|
|
264
318
|
if (!promoChar)
|
|
265
|
-
return
|
|
319
|
+
return fail("san/invalidPromotion");
|
|
266
320
|
const role = promoCharToRole(promoChar);
|
|
267
321
|
if (role === undefined)
|
|
268
|
-
return
|
|
322
|
+
return fail("san/invalidPromotion");
|
|
269
323
|
promotion = role;
|
|
270
324
|
s = s.slice(0, eqIdx);
|
|
271
325
|
}
|
|
272
326
|
// Destination
|
|
273
327
|
if (s.length < 2)
|
|
274
|
-
return
|
|
328
|
+
return fail("san/invalidSan");
|
|
275
329
|
const toStr = s.slice(-2);
|
|
276
330
|
const to = parseSquare(toStr);
|
|
277
331
|
if (to === undefined)
|
|
278
|
-
return
|
|
332
|
+
return fail("san/invalidSquare");
|
|
279
333
|
let rest = s.slice(0, -2);
|
|
280
334
|
// Capture
|
|
281
335
|
let isCapture = false;
|
|
@@ -303,7 +357,7 @@ export function parseSan(san, pos) {
|
|
|
303
357
|
else if (ch >= "1" && ch <= "8")
|
|
304
358
|
disambRank = ch;
|
|
305
359
|
else
|
|
306
|
-
return
|
|
360
|
+
return fail("san/invalidSan");
|
|
307
361
|
}
|
|
308
362
|
else if (rest.length === 2) {
|
|
309
363
|
if (rest[0] >= "a" && rest[0] <= "h" && rest[1] >= "1" && rest[1] <= "8") {
|
|
@@ -311,10 +365,10 @@ export function parseSan(san, pos) {
|
|
|
311
365
|
disambRank = rest[1];
|
|
312
366
|
}
|
|
313
367
|
else
|
|
314
|
-
return
|
|
368
|
+
return fail("san/invalidSan");
|
|
315
369
|
}
|
|
316
370
|
else if (rest.length > 2) {
|
|
317
|
-
return
|
|
371
|
+
return fail("san/invalidSan");
|
|
318
372
|
}
|
|
319
373
|
// For pawn, pieceRole is pawn, but rest may be file for capture (like "e" in exd5)
|
|
320
374
|
// Our disamb handling already captured that: for "exd5", rest after removing piece (none) and capture, rest = "e" => disambFile = 'e' . Good.
|
|
@@ -391,7 +445,7 @@ export function parseSan(san, pos) {
|
|
|
391
445
|
filteredFroms = filteredFroms.filter(f => squareRank(f) === reqRank);
|
|
392
446
|
}
|
|
393
447
|
if (filteredFroms.length === 0)
|
|
394
|
-
return
|
|
448
|
+
return fail("san/noLegalMove");
|
|
395
449
|
// Legality filtering with single shared check context
|
|
396
450
|
const ctx = chess.analyzeCheckContext(pos);
|
|
397
451
|
const candidates = [];
|
|
@@ -425,11 +479,10 @@ export function parseSan(san, pos) {
|
|
|
425
479
|
});
|
|
426
480
|
}
|
|
427
481
|
if (candidates.length === 0)
|
|
428
|
-
return Err({ code: "san/noLegalMove" });
|
|
482
|
+
return { result: Err({ code: "san/noLegalMove" }), candidates };
|
|
429
483
|
if (candidates.length > 1)
|
|
430
|
-
return Err({ code: "san/ambiguous" });
|
|
431
|
-
|
|
432
|
-
return Ok(chosen);
|
|
484
|
+
return { result: Err({ code: "san/ambiguous" }), candidates };
|
|
485
|
+
return { result: Ok(candidates[0]), candidates };
|
|
433
486
|
}
|
|
434
487
|
// ---------- UCI ----------
|
|
435
488
|
export function parseUci(uci) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gigachess",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "The fastest chess library and engine in TypeScript. 45x faster than chess.js, 18.7M nodes/s perft, zero dependencies, 100% MIT.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"typecheck": "tsc --noEmit",
|
|
109
|
-
"test": "npm run typecheck && node tests/native-board.mjs && node tests/perft.mjs && node tests/castling.mjs && node tests/parity.mjs && node tests/purity.mjs && node tests/compat-chessops.mjs && node tests/chessjs-parity.mjs && node tests/chesstree-parity.mjs && node tests/zobrist-parity.mjs && node tests/packed-moves.mjs && node tests/zero-copy-moves.mjs && node tests/null-move.mjs && node tests/fuzz-differential.mjs",
|
|
109
|
+
"test": "npm run typecheck && npm run build && node tests/native-board.mjs && node tests/perft.mjs && node tests/castling.mjs && node tests/parity.mjs && node tests/purity.mjs && node tests/compat-chessops.mjs && node tests/chessjs-parity.mjs && node tests/chesstree-parity.mjs && node tests/zobrist-parity.mjs && node tests/packed-moves.mjs && node tests/zero-copy-moves.mjs && node tests/null-move.mjs && node tests/san-ambiguity.mjs && node tests/fuzz-differential.mjs",
|
|
110
110
|
"test:fuzz": "node tests/fuzz-differential.mjs",
|
|
111
111
|
"bench": "node bench/bench-sliding.mjs --iters 1000000 && node bench/bench-perft.mjs --depth 5 && node bench/bench-pgn.mjs --games 1000 && node bench/bench-fen-san.mjs --iters 1000 && node bench/bench-bundle.mjs --entry core",
|
|
112
112
|
"bench:sliding": "node bench/bench-sliding.mjs",
|