chess-moments 0.14.7 → 0.14.8
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { getMoveNumber } = require('../helpers');
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Always returns an array because there can be more than one next moment
|
|
3
5
|
*/
|
|
@@ -16,6 +18,14 @@ const getNextMoments = (moments, current) => {
|
|
|
16
18
|
if (!nextMoment) {
|
|
17
19
|
return [];
|
|
18
20
|
}
|
|
21
|
+
// Last move of a sideline should not have any next moves
|
|
22
|
+
if (
|
|
23
|
+
!nextMoment?.move &&
|
|
24
|
+
current.depth >= nextMoment.depth &&
|
|
25
|
+
getMoveNumber(nextMoment.fen) <= getMoveNumber(current.fen)
|
|
26
|
+
) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
19
29
|
|
|
20
30
|
// Add the next moment if it has a move and is at the same depth
|
|
21
31
|
if (nextMoment.move && current.depth === nextMoment.depth) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const getMoveNumber = (fen) => {
|
|
2
|
+
// FEN format: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
|
|
3
|
+
// The fullmove number is the sixth part of the FEN string
|
|
4
|
+
const parts = fen.split(' ');
|
|
5
|
+
return Number(parts[5]);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
module.exports = getMoveNumber;
|