chess-moments 0.14.6 → 0.14.7

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.
@@ -10,32 +10,41 @@ const getNextMoments = (moments, current) => {
10
10
  return [moments[1]];
11
11
  }
12
12
 
13
- // Split moments after the current index
14
- const currentIndex = moments.indexOf(current);
15
- let moves = moments.slice(currentIndex + 1).filter((m) => m.move);
13
+ // If there is no next moment, return empty array
14
+ const nextIndex = moments.indexOf(current) + 1;
15
+ const nextMoment = moments[nextIndex];
16
+ if (!nextMoment) {
17
+ return [];
18
+ }
19
+
20
+ // Add the next moment if it has a move and is at the same depth
21
+ if (nextMoment.move && current.depth === nextMoment.depth) {
22
+ next.push(nextMoment);
23
+ }
16
24
 
17
- // If the immediate next moment has increased depth, filter out all moments until depth returns to current
18
- if (moves.length > 0 && moves[0].depth > current.depth) {
19
- let foundReturnToCurrentDepth = false;
20
- moves = moves.filter((moment) => {
21
- if (foundReturnToCurrentDepth) {
22
- return true; // Keep all moments after we return to current depth
23
- }
24
- if (moment.depth === current.depth) {
25
- foundReturnToCurrentDepth = true;
26
- return true; // Keep this moment and all following
27
- }
28
- return false; // Skip moments with increased depth
29
- });
25
+ // If the next next moment has a move, we don't have any other sidelines
26
+ const nextNextMoment = moments[nextIndex + 1];
27
+ if (nextMoment?.move && nextNextMoment?.move) {
28
+ return next;
30
29
  }
31
30
 
32
31
  // Add fullmove number to the current moment
33
32
  current.fullmove = Number(current.fen.split(' ')[5]);
34
33
 
34
+ // Keep only slim moments
35
+ const slim = moments.filter((moment) => {
36
+ const fullmove = Number(moment.fen.split(' ')[5]);
37
+ return (
38
+ moment.index > current.index + 1 &&
39
+ fullmove <= current.fullmove + 1 &&
40
+ moment.move // Also filter out moments without a move
41
+ );
42
+ });
43
+
35
44
  // Active color after current move (who moves next)
36
45
  const activeColorAfterCurrent = current.fen.split(' ')[1];
37
46
 
38
- for (const moment of moves) {
47
+ for (const moment of slim) {
39
48
  // Only process main line and immediate variations
40
49
  if (moment.depth > current.depth + 1) {
41
50
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.14.6",
3
+ "version": "0.14.7",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "dist/index.js",
6
6
  "files": [