chess-moments 0.14.8 → 0.14.9
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.
|
@@ -12,12 +12,16 @@ const getNextMoments = (moments, current) => {
|
|
|
12
12
|
return [moments[1]];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
//
|
|
15
|
+
// Get next moments for further processing
|
|
16
16
|
const nextIndex = moments.indexOf(current) + 1;
|
|
17
17
|
const nextMoment = moments[nextIndex];
|
|
18
|
+
const nextNextMoment = moments[nextIndex + 1];
|
|
19
|
+
|
|
20
|
+
// Early returns for edge cases
|
|
18
21
|
if (!nextMoment) {
|
|
19
22
|
return [];
|
|
20
23
|
}
|
|
24
|
+
|
|
21
25
|
// Last move of a sideline should not have any next moves
|
|
22
26
|
if (
|
|
23
27
|
!nextMoment?.move &&
|
|
@@ -32,9 +36,18 @@ const getNextMoments = (moments, current) => {
|
|
|
32
36
|
next.push(nextMoment);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
// Return early if we have consecutive moves or no next next moment
|
|
40
|
+
if (!nextNextMoment || (nextMoment?.move && nextNextMoment?.move)) {
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Second to last move of a sideline should not have any next moves
|
|
45
|
+
if (
|
|
46
|
+
nextMoment?.move &&
|
|
47
|
+
!nextNextMoment?.move &&
|
|
48
|
+
current.depth >= nextNextMoment.depth &&
|
|
49
|
+
getMoveNumber(nextNextMoment.fen) <= getMoveNumber(current.fen)
|
|
50
|
+
) {
|
|
38
51
|
return next;
|
|
39
52
|
}
|
|
40
53
|
|