chess-moments 0.10.0 → 0.11.0
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.
- package/functions/index.js +2 -0
- package/functions/prettify.js +2 -4
- package/functions/train.js +21 -0
- package/index.js +2 -1
- package/package.json +1 -1
package/functions/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const prepare = require('./prepare');
|
|
|
9
9
|
const prettify = require('./prettify');
|
|
10
10
|
const shape = require('./shape');
|
|
11
11
|
const split = require('./split');
|
|
12
|
+
const train = require('./train');
|
|
12
13
|
const tree = require('./tree');
|
|
13
14
|
|
|
14
15
|
module.exports = {
|
|
@@ -23,5 +24,6 @@ module.exports = {
|
|
|
23
24
|
prettify,
|
|
24
25
|
shape,
|
|
25
26
|
split,
|
|
27
|
+
train,
|
|
26
28
|
tree,
|
|
27
29
|
};
|
package/functions/prettify.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module.exports = (comment) => {
|
|
2
2
|
try {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.map((it) => it.trim())
|
|
6
|
-
.filter((it) => it.indexOf('[') !== 0)[0];
|
|
3
|
+
// Remove any shape comments like [%cal Ya7,Ya6] or [%csl Ya7,Ya6]
|
|
4
|
+
return comment.replace(/\s*\[%c(?:al|sl) [^\]]+\]/g, '').trim();
|
|
7
5
|
} catch (err) {
|
|
8
6
|
return undefined;
|
|
9
7
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const flat = require('./flat');
|
|
2
|
+
|
|
3
|
+
const train = (sloppyPgn, moveIndex) => {
|
|
4
|
+
const moments = flat(sloppyPgn);
|
|
5
|
+
|
|
6
|
+
// Remove sidelines (depth > 1) when no move index is specified
|
|
7
|
+
if (!moveIndex) {
|
|
8
|
+
return moments.filter((moment) => moment.depth === 1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Split the moments into two groups
|
|
12
|
+
const before = moments.slice(0, moveIndex);
|
|
13
|
+
const after = moments.slice(moveIndex);
|
|
14
|
+
|
|
15
|
+
// Remove sidelines after the specified move index with the move index depth
|
|
16
|
+
const filtered = after.filter((moment) => moment.depth <= moments[moveIndex].depth);
|
|
17
|
+
|
|
18
|
+
return before.concat(filtered);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = train;
|
package/index.js
CHANGED