chess-moments 0.13.0 → 0.14.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.
@@ -1,8 +1,5 @@
1
- const brush = require('./brush');
2
1
  const fen = require('./fen');
3
2
  const flat = require('./flat');
4
- const getNextMoments = require('./get-next-moments');
5
- const getPrevMoment = require('./get-prev-moment');
6
3
  const lines = require('./lines');
7
4
  const moment = require('./moment');
8
5
  const parser = require('./parser');
@@ -15,11 +12,8 @@ const train = require('./train');
15
12
  const tree = require('./tree');
16
13
 
17
14
  module.exports = {
18
- brush,
19
15
  fen,
20
16
  flat,
21
- getNextMoments,
22
- getPrevMoment,
23
17
  lines,
24
18
  moment,
25
19
  parser,
@@ -1,4 +1,4 @@
1
- const brush = require('./brush');
1
+ const { getBrushColor } = require('./helpers');
2
2
 
3
3
  module.exports = (comment) => {
4
4
  try {
@@ -16,7 +16,7 @@ module.exports = (comment) => {
16
16
 
17
17
  for (const target of shapes.join('').split(',')) {
18
18
  draw.push({
19
- brush: brush(target.substr(0, 1)),
19
+ brush: getBrushColor(target.substr(0, 1)),
20
20
  orig: target.substr(1, 2),
21
21
  dest: target.substr(3, 2),
22
22
  });
package/index.js CHANGED
@@ -1,12 +1,9 @@
1
+ const { fen, pgn, flat, train, tree } = require('./functions');
1
2
  const {
2
- fen,
3
- pgn,
4
- flat,
5
- train,
6
- tree,
7
3
  getNextMoments,
8
4
  getPrevMoment,
9
- } = require('./functions');
5
+ momentsToPgn,
6
+ } = require('./functions/extras');
10
7
 
11
8
  module.exports = {
12
9
  fen,
@@ -16,4 +13,5 @@ module.exports = {
16
13
  tree,
17
14
  getNextMoments,
18
15
  getPrevMoment,
16
+ momentsToPgn,
19
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -1,9 +0,0 @@
1
- module.exports = (letter) => {
2
- const brushes = {
3
- R: 'red',
4
- Y: 'yellow',
5
- G: 'green',
6
- };
7
-
8
- return brushes[letter] || 'green';
9
- };
@@ -1,65 +0,0 @@
1
- /**
2
- * Always returns an array because there can be more than one next moment
3
- */
4
- const getNextMoments = (moments, current) => {
5
- try {
6
- const next = [];
7
- const sameDepth = moments[moments.indexOf(current) + 1];
8
- if (sameDepth.move && sameDepth.depth === current.depth) {
9
- next.push(sameDepth);
10
- }
11
-
12
- // If it's the first moment without move, add the next moment
13
- if (current.index === 0 && !current.move) {
14
- next.push(moments[1]);
15
- }
16
-
17
- // Split moments after the current index
18
- const currentIndex = moments.indexOf(current);
19
- const moves = moments.slice(currentIndex + 1).filter((m) => m.move);
20
-
21
- // Add fullmove number to the current moment
22
- current.fullmove = Number(current.fen.split(' ')[5]);
23
-
24
- // Active color is white
25
- if (current.fen.split(' ')[1] === 'w') {
26
- for (const moment of moves) {
27
- const activeColor = moment.fen.split(' ')[1];
28
- const fullmove = Number(moment.fen.split(' ')[5]);
29
-
30
- // Check if the next moment is a valid move for white
31
- if (
32
- moment.depth === current.depth + 1 &&
33
- activeColor === 'b' &&
34
- fullmove === current.fullmove
35
- ) {
36
- next.push(moment);
37
- }
38
- }
39
- }
40
-
41
- // Active color is black
42
- if (current.fen.split(' ')[1] === 'b') {
43
- for (const moment of moves) {
44
- const activeColor = moment.fen.split(' ')[1];
45
- const fullmove = Number(moment.fen.split(' ')[5]);
46
-
47
- // Check if the next moment is a valid move for black
48
- if (
49
- moment.depth === current.depth + 1 &&
50
- activeColor === 'w' &&
51
- fullmove === current.fullmove + 1
52
- ) {
53
- next.push(moment);
54
- }
55
- }
56
- }
57
-
58
- // If no next moment is found, return an empty array
59
- return next;
60
- } catch {
61
- return [];
62
- }
63
- };
64
-
65
- module.exports = getNextMoments;
@@ -1,66 +0,0 @@
1
- /**
2
- * Always returns an object because there can be only one previous moment
3
- */
4
- const getPrevMoment = (moments, current) => {
5
- try {
6
- const sameDepth = moments[moments.indexOf(current) - 1];
7
- if (sameDepth.move && sameDepth.depth === current.depth) {
8
- return sameDepth;
9
- }
10
-
11
- // If it's the first moment with move, return the previous moment (starting position)
12
- if (current.index === 1 && current.move) {
13
- return moments[0];
14
- }
15
-
16
- // Split moments until the current index
17
- const currentIndex = moments.indexOf(current);
18
- const moves = moments.slice(0, currentIndex).filter((m) => m.move);
19
-
20
- // Add fullmove number to the current moment
21
- current.fullmove = Number(current.fen.split(' ')[5]);
22
-
23
- // Active color is white
24
- if (current.fen.split(' ')[1] === 'w') {
25
- // Traverse moves in reverse order to optimize search
26
- for (let i = moves.length - 1; i >= 0; i--) {
27
- const moment = moves[i];
28
- const activeColor = moment.fen.split(' ')[1];
29
- const fullmove = Number(moment.fen.split(' ')[5]);
30
-
31
- if (
32
- moment.depth === current.depth - 1 &&
33
- activeColor === 'b' &&
34
- fullmove === current.fullmove - 1
35
- ) {
36
- return moment;
37
- }
38
- }
39
- }
40
-
41
- // Active color is black
42
- if (current.fen.split(' ')[1] === 'b') {
43
- // Traverse moves in reverse order to optimize search
44
- for (let i = moves.length - 1; i >= 0; i--) {
45
- const moment = moves[i];
46
- const activeColor = moment.fen.split(' ')[1];
47
- const fullmove = Number(moment.fen.split(' ')[5]);
48
-
49
- if (
50
- moment.depth === current.depth - 1 &&
51
- activeColor === 'w' &&
52
- fullmove === current.fullmove
53
- ) {
54
- return moment;
55
- }
56
- }
57
- }
58
-
59
- // If no previous moment is found, return an empty object
60
- return {};
61
- } catch {
62
- return {};
63
- }
64
- };
65
-
66
- module.exports = getPrevMoment;