chess-moments 0.14.5 → 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.
@@ -7,35 +7,44 @@ const getNextMoments = (moments, current) => {
7
7
 
8
8
  // If it's the first moment without move, add the next moment
9
9
  if (current.index === 0 && !current.move) {
10
- return moments[1];
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;
@@ -29,7 +29,8 @@ const getPrevMoment = (moments, current) => {
29
29
  const fullmove = Number(moment.fen.split(' ')[5]);
30
30
 
31
31
  if (
32
- moment.depth === current.depth - 1 &&
32
+ (moment.depth === current.depth - 1 ||
33
+ moment.depth === current.depth) &&
33
34
  activeColor === 'b' &&
34
35
  fullmove === current.fullmove - 1
35
36
  ) {
@@ -47,7 +48,8 @@ const getPrevMoment = (moments, current) => {
47
48
  const fullmove = Number(moment.fen.split(' ')[5]);
48
49
 
49
50
  if (
50
- moment.depth === current.depth - 1 &&
51
+ (moment.depth === current.depth - 1 ||
52
+ moment.depth === current.depth) &&
51
53
  activeColor === 'w' &&
52
54
  fullmove === current.fullmove
53
55
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.14.5",
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": [