cm-chess 2.4.4 → 2.5.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/README.md +1 -1
- package/package.json +3 -3
- package/src/cm-chess/Chess.js +6 -9
- package/test/TestChess.js +4 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cm-chess
|
|
2
2
|
|
|
3
|
-
It is like [chess.js](https://github.com/jhlywa/chess.js) (and
|
|
3
|
+
It is like [chess.js](https://github.com/jhlywa/chess.js) (and is based on an older version of chess.js),
|
|
4
4
|
but can handle history variations (tree-structured move history),
|
|
5
5
|
PGN header values, Nags and Comments.
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cm-chess",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "It's like chess.js, but in ES6 and can handle variations (tree-structured move history)",
|
|
5
5
|
"main": "./src/cm-chess/Chess.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"homepage": "https://github.com/shaack/cm-chess#readme",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"chess.mjs": "^1.3.1",
|
|
28
|
-
"cm-pgn": "
|
|
28
|
+
"cm-pgn": "2.3.2",
|
|
29
29
|
"modlib": "^1.2.12"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"teevi": "^2.2.
|
|
32
|
+
"teevi": "^2.2.4"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/cm-chess/Chess.js
CHANGED
|
@@ -250,17 +250,14 @@ export class Chess {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
-
*
|
|
253
|
+
* Render the game as PGN with header, comments and NAGs
|
|
254
|
+
* @param renderHeader optional, default true
|
|
255
|
+
* @param renderComments optional, default true
|
|
256
|
+
* @param renderNags optional, default true
|
|
254
257
|
* @returns {string} the PGN of the game.
|
|
255
258
|
*/
|
|
256
|
-
renderPgn() {
|
|
257
|
-
|
|
258
|
-
const chess = new ChessJs(this.setUpFen())
|
|
259
|
-
const moves = this.pgn.history.moves
|
|
260
|
-
for (const move of moves) {
|
|
261
|
-
chess.move(move)
|
|
262
|
-
}
|
|
263
|
-
return chess.pgn()
|
|
259
|
+
renderPgn(renderHeader = true, renderComments = true, renderNags = true) {
|
|
260
|
+
return this.pgn.render(renderHeader, renderComments, renderNags);
|
|
264
261
|
}
|
|
265
262
|
|
|
266
263
|
/**
|
package/test/TestChess.js
CHANGED
|
@@ -97,6 +97,7 @@ describe("Chess", function () {
|
|
|
97
97
|
const chess = new Chess()
|
|
98
98
|
const pgn = `[SetUp "1"]
|
|
99
99
|
[FEN "8/8/b2Bq3/7Q/3kp3/5pP1/8/3K4 w - - 0 1"]
|
|
100
|
+
[Result "1-0"]
|
|
100
101
|
|
|
101
102
|
1. Qc5+ Kd3 2. Qc2+ Kd4 3. Qd2+ Bd3 4. Qe3+ Kxe3 (4... Kc3 5. Qc1+ Kb3 6. Qa3+ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5#
|
|
102
103
|
1-0`
|
|
@@ -111,11 +112,12 @@ describe("Chess", function () {
|
|
|
111
112
|
assert.equal(chess.lastMove().inCheckmate, true)
|
|
112
113
|
assert.equal(chess.inCheckmate(), true)
|
|
113
114
|
assert.equal(chess.inDraw(), false)
|
|
114
|
-
// TODO result, 1-0 is missing
|
|
115
115
|
assert.equal(chess.renderPgn(), `[SetUp "1"]
|
|
116
116
|
[FEN "8/8/b2Bq3/7Q/3kp3/5pP1/8/3K4 w - - 0 1"]
|
|
117
|
+
[Result "1-0"]
|
|
117
118
|
|
|
118
|
-
1. Qc5+ Kd3 2. Qc2+ Kd4 3. Qd2+ Bd3 4. Qe3+ Kxe3 5.
|
|
119
|
+
1. Qc5+ Kd3 2. Qc2+ Kd4 3. Qd2+ Bd3 4. Qe3+ Kxe3 (4... Kc3 5. Qc1+ Kb3 6. Qa3+
|
|
120
|
+
Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
|
|
119
121
|
})
|
|
120
122
|
|
|
121
123
|
it('should add move at the end of the history', () => {
|