gigachess 0.4.3 → 0.5.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.
@@ -6,7 +6,16 @@ export interface Comment {
6
6
  export interface Glyph {
7
7
  symbol: string;
8
8
  name: string;
9
+ /** The PGN NAG number (`$14`), when the glyph has one. */
10
+ id?: number;
9
11
  }
12
+ /** The standard annotation glyphs, by NAG: move assessments (1–7) and
13
+ * position assessments (10–19 and the rest). Symbols and names follow the
14
+ * lichess tree, so a glyph reads the same in either tree. */
15
+ export declare const NAG_GLYPHS: Readonly<Record<number, Readonly<Glyph>>>;
16
+ /** The glyph for a NAG. A NAG without a standard glyph keeps its number as
17
+ * `$n`, so it survives import and export unchanged. */
18
+ export declare function glyphForNag(nag: number): Glyph;
10
19
  export interface Clock {
11
20
  white: number;
12
21
  black: number;
@@ -1 +1 @@
1
- {"version":3,"file":"chesstree.d.ts","sourceRoot":"","sources":["../src/chesstree.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,GAA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M,SAAS,cAAQ,CAAC"}
package/dist/chesstree.js CHANGED
@@ -12,6 +12,40 @@ import { NULL_MOVE_SAN, NULL_MOVE_UCI, nullMove } from "./packedMove.js";
12
12
  import { Color } from "./types.js";
13
13
  const START_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
14
14
  const ID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
15
+ /** The standard annotation glyphs, by NAG: move assessments (1–7) and
16
+ * position assessments (10–19 and the rest). Symbols and names follow the
17
+ * lichess tree, so a glyph reads the same in either tree. */
18
+ export const NAG_GLYPHS = Object.freeze({
19
+ 1: { id: 1, symbol: "!", name: "Good move" },
20
+ 2: { id: 2, symbol: "?", name: "Mistake" },
21
+ 3: { id: 3, symbol: "!!", name: "Brilliant move" },
22
+ 4: { id: 4, symbol: "??", name: "Blunder" },
23
+ 5: { id: 5, symbol: "!?", name: "Interesting move" },
24
+ 6: { id: 6, symbol: "?!", name: "Dubious move" },
25
+ 7: { id: 7, symbol: "□", name: "Only move" },
26
+ 10: { id: 10, symbol: "=", name: "Equal position" },
27
+ 13: { id: 13, symbol: "∞", name: "Unclear position" },
28
+ 14: { id: 14, symbol: "⩲", name: "White is slightly better" },
29
+ 15: { id: 15, symbol: "⩱", name: "Black is slightly better" },
30
+ 16: { id: 16, symbol: "±", name: "White is better" },
31
+ 17: { id: 17, symbol: "∓", name: "Black is better" },
32
+ 18: { id: 18, symbol: "+−", name: "White is winning" },
33
+ 19: { id: 19, symbol: "−+", name: "Black is winning" },
34
+ 22: { id: 22, symbol: "⨀", name: "Zugzwang" },
35
+ 32: { id: 32, symbol: "↑↑", name: "Development" },
36
+ 36: { id: 36, symbol: "↑", name: "Initiative" },
37
+ 40: { id: 40, symbol: "→", name: "Attack" },
38
+ 132: { id: 132, symbol: "⇆", name: "Counterplay" },
39
+ 138: { id: 138, symbol: "⊕", name: "Time trouble" },
40
+ 140: { id: 140, symbol: "∆", name: "With the idea" },
41
+ 146: { id: 146, symbol: "N", name: "Novelty" },
42
+ });
43
+ /** The glyph for a NAG. A NAG without a standard glyph keeps its number as
44
+ * `$n`, so it survives import and export unchanged. */
45
+ export function glyphForNag(nag) {
46
+ const known = NAG_GLYPHS[nag];
47
+ return known ? { ...known } : { id: nag, symbol: `$${nag}`, name: `NAG ${nag}` };
48
+ }
15
49
  /** Deterministic unique 2-char node id (same alphabet/contract the
16
50
  * workstation's `createUniqueMoveNodeId` relies on). */
17
51
  function nextNodeId(siblings) {
@@ -48,15 +82,26 @@ function mergeTree(existing, incoming) {
48
82
  ex.push(c);
49
83
  }
50
84
  }
85
+ if (incoming.startingComments !== undefined && incoming.startingComments.length > 0) {
86
+ const ex = existing.startingComments ?? (existing.startingComments = []);
87
+ for (const c of incoming.startingComments) {
88
+ if (!ex.some((e) => e.text === c.text))
89
+ ex.push(c);
90
+ }
91
+ }
51
92
  if (existing.glyphs === undefined && incoming.glyphs !== undefined)
52
93
  existing.glyphs = incoming.glyphs;
53
94
  }
54
- function replaySection(moves, ctx, out) {
95
+ /** `root` is set for the game's own section: comments before its first move
96
+ * belong to the root node (`{intro} 1. e4`), as in the baseline. In a
97
+ * variation they are the first move's `startingComments`. */
98
+ function replaySection(moves, ctx, out, root) {
55
99
  // Mainline nesting: the parser emits a flat mainline list, so each
56
100
  // successive move nests under the previous node's children. A PGN variation
57
101
  // replaces the move it follows — it starts from the position BEFORE that
58
102
  // move and its nodes are siblings of it (children[0] = mainline).
59
103
  let target = out;
104
+ let first = true;
60
105
  for (const m of moves) {
61
106
  const snapshot = { ...ctx };
62
107
  const id = nextNodeId(target);
@@ -93,12 +138,28 @@ function replaySection(moves, ctx, out) {
93
138
  advance = { pos: makeMove(ctx.pos, move) };
94
139
  node.fen = fenWithEpPolicy(advance.pos);
95
140
  }
96
- if (m.comments.length > 0) {
97
- node.comments = m.comments.map((text, i) => ({
141
+ const lead = m.startingComments ?? [];
142
+ const after = first ? m.comments : [...lead, ...m.comments];
143
+ if (first && lead.length > 0) {
144
+ if (root) {
145
+ root.comments = lead.map((text, i) => ({ id: `pgn-comment-comment-root-${i}`, text }));
146
+ }
147
+ else {
148
+ node.startingComments = lead.map((text, i) => ({
149
+ id: `pgn-starting-comment-${ctx.path}${id}-${i}`,
150
+ text,
151
+ }));
152
+ }
153
+ }
154
+ first = false;
155
+ if (after.length > 0) {
156
+ node.comments = after.map((text, i) => ({
98
157
  id: commentId(`${ctx.path}${id}`, i),
99
158
  text,
100
159
  }));
101
160
  }
161
+ if (m.nags.length > 0)
162
+ node.glyphs = m.nags.map(glyphForNag);
102
163
  // baseline pgnImport merges duplicate sibling moves (same SAN) into one
103
164
  // node, recursively merging their subtrees
104
165
  const existing = target.find((c) => c.san !== undefined && c.san === node.san);
@@ -234,7 +295,7 @@ export function pgnImport(pgn) {
234
295
  const start = startRes.ok ? startRes.value : parseFen(START_FEN).value;
235
296
  const root = { id: "", ply: 0, fen: rootFen, uci: "", children: [] };
236
297
  const ctx = { pos: start, ply: 0, path: "", moveNo: 1 };
237
- replaySection(parsed.value.moves, ctx, root.children);
298
+ replaySection(parsed.value.moves, ctx, root.children, root);
238
299
  const game = defaultGame(rootFen, headers);
239
300
  const white = headers.get("White");
240
301
  const black = headers.get("Black");
@@ -395,7 +456,20 @@ export function build(root) {
395
456
  }
396
457
  // ---------- PGN export ----------
397
458
  const STRO_KEYS = new Set(["Event", "Site", "Date", "Round", "White", "Black", "Result"]);
398
- const GLYPH_TO_NAG = { "!": 1, "?": 2, "!!": 3, "??": 4, "!?": 5, "?!": 6 };
459
+ const GLYPH_TO_NAG = Object.fromEntries(Object.values(NAG_GLYPHS).map((g) => [g.symbol, g.id]));
460
+ // ASCII spellings of the winning glyphs
461
+ GLYPH_TO_NAG["+-"] = 18;
462
+ GLYPH_TO_NAG["-+"] = 19;
463
+ /** The NAG for a glyph: its `id`, its standard symbol, or a `$n` symbol. */
464
+ function nagOfGlyph(g) {
465
+ if (typeof g.id === "number" && Number.isInteger(g.id) && g.id > 0)
466
+ return g.id;
467
+ const known = GLYPH_TO_NAG[g.symbol];
468
+ if (known !== undefined)
469
+ return known;
470
+ const m = /^\$(\d+)$/.exec(g.symbol);
471
+ return m ? parseInt(m[1], 10) : undefined;
472
+ }
399
473
  const Q = '"';
400
474
  const headerLine = (k, v) => "[" + k + " " + Q + (v ?? "?") + Q + "]";
401
475
  function renderHeaders(game, rootFen) {
@@ -445,6 +519,8 @@ function emitFrom(list, idx, state, tokens) {
445
519
  const isNull = san !== undefined && isNullMoveSan(san);
446
520
  // A pass is emitted as `--` — it is a real ply, so dropping it (the old
447
521
  // behavior) desynchronized the numbering of every following token.
522
+ for (const c of node.startingComments ?? [])
523
+ tokens.push("{" + c.text + "}");
448
524
  if (san !== undefined) {
449
525
  if (state.turn === "w")
450
526
  tokens.push(state.moveNo + ".");
@@ -453,7 +529,7 @@ function emitFrom(list, idx, state, tokens) {
453
529
  tokens.push(san);
454
530
  state.needNumber = false;
455
531
  for (const g of node.glyphs ?? []) {
456
- const nag = GLYPH_TO_NAG[g.symbol];
532
+ const nag = nagOfGlyph(g);
457
533
  if (nag !== undefined)
458
534
  tokens.push("$" + nag);
459
535
  }
@@ -485,7 +561,9 @@ function numberingFromFen(fen) {
485
561
  }
486
562
  function renderMovetext(root, game) {
487
563
  const state = numberingFromFen(root.fen);
488
- const moves = renderSection(root.children, state);
564
+ const intro = (root.comments ?? []).map((c) => "{" + c.text + "}");
565
+ const body = renderSection(root.children, state);
566
+ const moves = [...intro, body].filter(Boolean).join(" ");
489
567
  const result = game.result ?? "*";
490
568
  return moves.length > 0 ? moves + " " + result : result;
491
569
  }
package/dist/index.d.ts CHANGED
@@ -13,6 +13,6 @@ export { kingAttackers } from "./attacks.js";
13
13
  export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js";
14
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
15
  export type { CastlingPlan, NullUndo } from "./chess.js";
16
- export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
16
+ export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, NAG_GLYPHS, glyphForNag, } 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,YAAY,EACZ,WAAW,EACX,WAAW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O,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,EACf,UAAU,EACV,WAAW,GACZ,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
@@ -18,4 +18,4 @@ export { CASTLE_PATH_LO, CASTLE_PATH_HI, CASTLE_CLEAR_STD, } from "./castling.js
18
18
  // chess core (avoid duplicate Position and kingAttackers)
19
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
- export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, } from "./chesstree.js";
21
+ export { pgnImport, buildTree, build, pgnExport, TreeWrapperImpl, NAG_GLYPHS, glyphForNag, } from "./chesstree.js";
package/dist/pgn.d.ts CHANGED
@@ -3,6 +3,10 @@ export type PgnMove = {
3
3
  san: string;
4
4
  nags: number[];
5
5
  comments: string[];
6
+ /** Comments written before this move — only the first move of a section
7
+ * (the game or a variation) has them: `{intro} 1. e4`, `({lead} 2. f4)`.
8
+ * Absent when there are none. */
9
+ startingComments?: string[];
6
10
  variations: GameTree[];
7
11
  };
8
12
  export type GameTree = {
package/dist/pgn.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pgn.d.ts","sourceRoot":"","sources":["../src/pgn.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,QAAQ,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AA0DF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAmBhE;AAuMD,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAY9C;AAsCD,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,KAAK,CAAyB;IAEtC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMzB,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAOpC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAGtD;AAGD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,+BAAkB,CAAC"}
1
+ {"version":3,"file":"pgn.d.ts","sourceRoot":"","sources":["../src/pgn.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;qCAEiC;IACjC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,UAAU,EAAE,QAAQ,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB,CAAC;AA0DF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAmBhE;AAwMD,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAY9C;AAyCD,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,KAAK,CAAyB;IAEtC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMzB,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAOpC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAGtD;AAGD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,+BAAkB,CAAC"}
package/dist/pgn.js CHANGED
@@ -269,8 +269,9 @@ function parseMovetext(text) {
269
269
  // Create move node
270
270
  const moveNode = { san: token, nags: [], comments: [], variations: [] };
271
271
  if (pending.length > 0) {
272
- // comments that appeared before this move precede any after-move comments
273
- moveNode.comments = pending.slice();
272
+ // comments that appeared before this move stay before it, so
273
+ // makePgn(parsePgn(pgn)) keeps their place
274
+ moveNode.startingComments = pending.slice();
274
275
  pending = [];
275
276
  }
276
277
  currentMoves.push(moveNode);
@@ -306,6 +307,10 @@ function makeMovetext(moves, result) {
306
307
  // For mainline, white moves are even idx (0,2,4...), black odd
307
308
  // We'll emit numbers for white only, as "1. e4 e5 2. Nf3"
308
309
  // This is more standard and still tolerant when re-parsed
310
+ if (mv.startingComments && mv.startingComments.length > 0) {
311
+ for (const c of mv.startingComments)
312
+ s += `{${c}} `;
313
+ }
309
314
  if (idx % 2 === 0) {
310
315
  const num = Math.floor(idx / 2) + 1;
311
316
  s += `${num}. `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gigachess",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
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 && 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",
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/chesstree-glyphs.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",