chess-moments 0.11.1 → 0.11.2
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,10 +1,10 @@
|
|
|
1
|
-
function splitByMoveIndex(inputData,
|
|
1
|
+
function splitByMoveIndex(inputData, current) {
|
|
2
2
|
const before = [];
|
|
3
3
|
const after = [];
|
|
4
4
|
|
|
5
5
|
inputData.forEach((innerArray) => {
|
|
6
6
|
// Check if every element in the inner array has an index less than moveIndex
|
|
7
|
-
if (innerArray.every((item) => item.index <
|
|
7
|
+
if (innerArray.every((item) => item.index < current.index)) {
|
|
8
8
|
if (innerArray.length) {
|
|
9
9
|
before.push(innerArray);
|
|
10
10
|
}
|
package/functions/train.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { flatten } = require('lodash');
|
|
2
|
-
const splitByMoveIndex = require('./split-by-move
|
|
2
|
+
const splitByMoveIndex = require('./split-by-move');
|
|
3
3
|
const tree = require('./tree');
|
|
4
4
|
|
|
5
|
-
const train = (sloppyPgn,
|
|
5
|
+
const train = (sloppyPgn, fen) => {
|
|
6
6
|
// Tree is an array of array depths
|
|
7
7
|
const moments = tree(sloppyPgn);
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ const train = (sloppyPgn, moveIndex) => {
|
|
|
10
10
|
const training = [];
|
|
11
11
|
|
|
12
12
|
// Remove sidelines (depth > 1) when no move index is specified
|
|
13
|
-
if (!
|
|
13
|
+
if (!fen) {
|
|
14
14
|
for (const innerArray of moments) {
|
|
15
15
|
const hasDepth = innerArray.filter((moment) => moment.depth === 1);
|
|
16
16
|
if (hasDepth.length) {
|
|
@@ -20,15 +20,15 @@ const train = (sloppyPgn, moveIndex) => {
|
|
|
20
20
|
return training;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// Get the current move from the move index
|
|
24
|
+
const current = flatten(moments).find((moment) => moment.fen === fen);
|
|
25
|
+
|
|
23
26
|
// Split the moments into two groups
|
|
24
|
-
const { before, after } = splitByMoveIndex(moments,
|
|
27
|
+
const { before, after } = splitByMoveIndex(moments, current);
|
|
25
28
|
for (const innerArray of before) {
|
|
26
29
|
training.push(innerArray);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
// Get the current move from the move index
|
|
30
|
-
const current = flatten(moments).find((moment) => moment.index === moveIndex);
|
|
31
|
-
|
|
32
32
|
// Only future moves remaining
|
|
33
33
|
for (const innerArray of after) {
|
|
34
34
|
// Remove every inner array with a depth not equal than the depth of the move index
|