cm-chess 2.3.0 → 2.3.4
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 +1 -1
- package/src/cm-chess/Fen.js +8 -11
- package/test/TestFen.js +5 -3
package/package.json
CHANGED
package/src/cm-chess/Fen.js
CHANGED
|
@@ -7,29 +7,26 @@
|
|
|
7
7
|
export class Fen {
|
|
8
8
|
|
|
9
9
|
constructor(fen) {
|
|
10
|
-
this.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
|
-
|
|
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
|
@@ -3,13 +3,15 @@ import {Fen} from "../src/cm-chess/Fen.js"
|
|
|
3
3
|
|
|
4
4
|
describe("Fen", function () {
|
|
5
5
|
|
|
6
|
-
it("should parse a
|
|
7
|
-
const
|
|
6
|
+
it("should parse and generate a FEN", () => {
|
|
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,
|
|
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
|
})
|