cm-chess 3.2.2 → 3.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 +1 -1
- package/src/Chess.js +35 -11
- package/test/TestChess.js +5 -0
package/package.json
CHANGED
package/src/Chess.js
CHANGED
|
@@ -96,7 +96,11 @@ export class Chess {
|
|
|
96
96
|
* @returns {boolean} true, if the game is over at that move
|
|
97
97
|
*/
|
|
98
98
|
gameOver(move = this.lastMove()) {
|
|
99
|
-
|
|
99
|
+
if(move) {
|
|
100
|
+
return move.gameOver
|
|
101
|
+
} else {
|
|
102
|
+
return new ChessJs(this.fen()).game_over()
|
|
103
|
+
}
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
@@ -104,7 +108,11 @@ export class Chess {
|
|
|
104
108
|
* @returns {boolean} true, if the game is in draw at that move
|
|
105
109
|
*/
|
|
106
110
|
inDraw(move = this.lastMove()) {
|
|
107
|
-
|
|
111
|
+
if(move) {
|
|
112
|
+
return move.inDraw === true
|
|
113
|
+
} else {
|
|
114
|
+
return new ChessJs(this.fen()).in_draw()
|
|
115
|
+
}
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
/**
|
|
@@ -112,7 +120,11 @@ export class Chess {
|
|
|
112
120
|
* @returns {boolean} true, if the game is in statemate at that move
|
|
113
121
|
*/
|
|
114
122
|
inStalemate(move = this.lastMove()) {
|
|
115
|
-
|
|
123
|
+
if(move) {
|
|
124
|
+
return move.inStalemate === true
|
|
125
|
+
} else {
|
|
126
|
+
return new ChessJs(this.fen()).in_stalemate()
|
|
127
|
+
}
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
/**
|
|
@@ -120,7 +132,11 @@ export class Chess {
|
|
|
120
132
|
* @returns {boolean} true, if the game is in draw, because of unsufficiant material at that move
|
|
121
133
|
*/
|
|
122
134
|
insufficientMaterial(move = this.lastMove()) {
|
|
123
|
-
|
|
135
|
+
if(move) {
|
|
136
|
+
return move.insufficientMaterial === true
|
|
137
|
+
} else {
|
|
138
|
+
return new ChessJs(this.fen()).insufficient_material()
|
|
139
|
+
}
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
/**
|
|
@@ -136,7 +152,11 @@ export class Chess {
|
|
|
136
152
|
* @returns {boolean} true, if the game is in checkmate at that move
|
|
137
153
|
*/
|
|
138
154
|
inCheckmate(move = this.lastMove()) {
|
|
139
|
-
|
|
155
|
+
if(move) {
|
|
156
|
+
return move.inCheckmate === true
|
|
157
|
+
} else {
|
|
158
|
+
return new ChessJs(this.fen()).in_checkmate()
|
|
159
|
+
}
|
|
140
160
|
}
|
|
141
161
|
|
|
142
162
|
/**
|
|
@@ -144,7 +164,11 @@ export class Chess {
|
|
|
144
164
|
* @returns {boolean} true, if the game is in check at that move
|
|
145
165
|
*/
|
|
146
166
|
inCheck(move = this.lastMove()) {
|
|
147
|
-
|
|
167
|
+
if(move) {
|
|
168
|
+
return move.inCheck === true
|
|
169
|
+
} else {
|
|
170
|
+
return new ChessJs(this.fen()).in_check()
|
|
171
|
+
}
|
|
148
172
|
}
|
|
149
173
|
|
|
150
174
|
/**
|
|
@@ -232,11 +256,11 @@ export class Chess {
|
|
|
232
256
|
* k - kingside castling
|
|
233
257
|
* q - queenside castling
|
|
234
258
|
* A flags value of pc would mean that a pawn captured a piece on the 8th rank and promoted.
|
|
235
|
-
* @param
|
|
259
|
+
* @param move
|
|
236
260
|
* @returns {{}}
|
|
237
261
|
*/
|
|
238
|
-
moves(options = undefined,
|
|
239
|
-
const chessJs = new ChessJs(this.fen(
|
|
262
|
+
moves(options = undefined, move = this.lastMove()) {
|
|
263
|
+
const chessJs = new ChessJs(this.fen(move))
|
|
240
264
|
return chessJs.moves(options)
|
|
241
265
|
}
|
|
242
266
|
|
|
@@ -270,7 +294,7 @@ export class Chess {
|
|
|
270
294
|
* @returns {[]} the pieces (positions) at a specific move
|
|
271
295
|
*/
|
|
272
296
|
pieces(type = undefined, color = undefined, move = this.lastMove()) {
|
|
273
|
-
const chessJs = move ? new ChessJs(move.fen) : new ChessJs()
|
|
297
|
+
const chessJs = move ? new ChessJs(move.fen) : new ChessJs(this.fen())
|
|
274
298
|
let result = []
|
|
275
299
|
for (let i = 0; i < 64; i++) {
|
|
276
300
|
const square = SQUARES[i]
|
|
@@ -298,7 +322,7 @@ export class Chess {
|
|
|
298
322
|
* @returns {{color: any, type: any}|null}
|
|
299
323
|
*/
|
|
300
324
|
piece(square, move = this.lastMove()) {
|
|
301
|
-
const chessJs = move ? new ChessJs(move.fen) : new ChessJs()
|
|
325
|
+
const chessJs = move ? new ChessJs(move.fen) : new ChessJs(this.fen())
|
|
302
326
|
return chessJs.get(square)
|
|
303
327
|
}
|
|
304
328
|
|
package/test/TestChess.js
CHANGED
|
@@ -249,4 +249,9 @@ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
|
|
|
249
249
|
assert.equal(JSON.stringify(chess.moves({ piece: "n" })), '["Na4","Nb5","Nd5","Ne4","Nb1","Nf3","Nh3"]')
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
+
it("should detect a check in a game without moves", function() {
|
|
253
|
+
const chess = new Chess("4k3/1P6/8/b7/6r1/8/pp2PPPP/2R1KBNR w K - 0 1")
|
|
254
|
+
assert.true(chess.inCheck())
|
|
255
|
+
})
|
|
256
|
+
|
|
252
257
|
})
|