cm-chess 2.3.0 → 2.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chess",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "Like chess.js, but in ES6 and can handle variations (tree-structured move history)",
5
5
  "main": "./src/cm-chess/Chess.js",
6
6
  "scripts": {
@@ -7,29 +7,26 @@
7
7
  export class Fen {
8
8
 
9
9
  constructor(fen) {
10
- this.fen = fen
11
- }
12
-
13
- get fen() {
14
- return this._fen
10
+ this.parse(fen)
15
11
  }
16
12
 
17
13
  /**
18
14
  * https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
19
15
  * @param fen
20
16
  */
21
- set fen(fen) {
22
- this._fen = fen
17
+ parse(fen) {
23
18
  const fenParts = fen.split(" ")
24
19
  this.position = fenParts[0]
25
20
  this.colorToPlay = fenParts[1]
26
21
  this.castlings = fenParts[2].split("")
27
22
  this.enPassantTargetSquare = fenParts[3]
28
- if(this.enPassantTargetSquare === "-") {
29
- this.enPassantTargetSquare = undefined
30
- }
31
23
  this.plyClock = parseInt(fenParts[4], 10)
32
24
  this.moveNumber = parseInt(fenParts[5], 10)
33
25
  }
34
26
 
35
- }
27
+ toString() {
28
+ return this.position + " " + this.colorToPlay + " " + this.castlings.join("") + " " +
29
+ this.enPassantTargetSquare + " " + this.plyClock + " " + this.moveNumber
30
+ }
31
+
32
+ }
package/test/TestFen.js CHANGED
@@ -4,12 +4,14 @@ import {Fen} from "../src/cm-chess/Fen.js"
4
4
  describe("Fen", function () {
5
5
 
6
6
  it("should parse a fen", () => {
7
- const fen = new Fen("rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2")
7
+ const fenString = "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"
8
+ const fen = new Fen(fenString)
8
9
  assert.equal(fen.position, "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R")
9
10
  assert.equal(fen.colorToPlay, "b")
10
11
  assert.equal(fen.castlings.length, 4)
11
- assert.equal(fen.enPassantTargetSquare, undefined)
12
+ assert.equal(fen.enPassantTargetSquare, "-")
12
13
  assert.equal(fen.plyClock, 1)
13
14
  assert.equal(fen.moveNumber, 2)
15
+ assert.equal(fen.toString(), fenString)
14
16
  })
15
17
  })