cm-chess 3.3.2 → 3.3.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Fen.js +13 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chess",
3
- "version": "3.3.2",
3
+ "version": "3.3.3",
4
4
  "description": "It's like chess.js, but in ES6 and can handle variations (tree-structured move history)",
5
5
  "main": "./src/Chess.js",
6
6
  "type": "module",
package/src/Fen.js CHANGED
@@ -18,15 +18,25 @@ export class Fen {
18
18
  const fenParts = fen.split(" ")
19
19
  this.position = fenParts[0]
20
20
  this.colorToPlay = fenParts[1]
21
- this.castlings = fenParts[2].split("")
21
+ if(fenParts[2] !== "-") {
22
+ this.castlings = fenParts[2].split("")
23
+ } else {
24
+ this.castlings = []
25
+ }
22
26
  this.enPassantTargetSquare = fenParts[3]
23
27
  this.plyClock = parseInt(fenParts[4], 10)
24
28
  this.moveNumber = parseInt(fenParts[5], 10)
25
29
  }
26
30
 
27
31
  toString() {
28
- return this.position + " " + this.colorToPlay + " " + this.castlings.join("") + " " +
29
- this.enPassantTargetSquare + " " + this.plyClock + " " + this.moveNumber
32
+ let fen = this.position + " " + this.colorToPlay + " "
33
+ if (this.castlings.length > 0) {
34
+ fen += this.castlings.join("")
35
+ } else {
36
+ fen += "-"
37
+ }
38
+ fen += " " + this.enPassantTargetSquare + " " + this.plyClock + " " + this.moveNumber
39
+ return fen
30
40
  }
31
41
 
32
42
  }