cm-chess 3.3.0 → 3.3.2

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": "3.3.0",
3
+ "version": "3.3.2",
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/Chess.js CHANGED
@@ -230,7 +230,7 @@ export class Chess {
230
230
  try {
231
231
  const moveResult = this.pgn.history.addMove(move, previousMove, sloppy)
232
232
  publishEvent(this.observers,
233
- {type: EVENT_TYPE.legalMove, move: move, previousMove: previousMove})
233
+ {type: EVENT_TYPE.legalMove, move: moveResult, previousMove: previousMove})
234
234
  return moveResult
235
235
  } catch (e) {
236
236
  publishEvent(this.observers,
@@ -294,7 +294,7 @@ export class Chess {
294
294
  * @returns {[]} the pieces (positions) at a specific move
295
295
  */
296
296
  pieces(type = undefined, color = undefined, move = this.lastMove()) {
297
- const chessJs = move ? new ChessJs(move.fen) : new ChessJs()
297
+ const chessJs = move ? new ChessJs(move.fen) : new ChessJs(this.fen())
298
298
  let result = []
299
299
  for (let i = 0; i < 64; i++) {
300
300
  const square = SQUARES[i]
@@ -322,7 +322,7 @@ export class Chess {
322
322
  * @returns {{color: any, type: any}|null}
323
323
  */
324
324
  piece(square, move = this.lastMove()) {
325
- const chessJs = move ? new ChessJs(move.fen) : new ChessJs()
325
+ const chessJs = move ? new ChessJs(move.fen) : new ChessJs(this.fen())
326
326
  return chessJs.get(square)
327
327
  }
328
328
 
package/test/TestChess.js CHANGED
@@ -215,7 +215,7 @@ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
215
215
  assert.true(chess.move("e4"))
216
216
  })
217
217
 
218
- it("should validate Moves", function() {
218
+ it("should validate Moves", function () {
219
219
  const chess = new Chess()
220
220
  assert.notEqual(chess.validateMove("e4"), null)
221
221
  assert.notEqual(chess.validateMove("e3"), null)
@@ -224,11 +224,13 @@ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
224
224
  assert.equal(chess.validateMove("e6"), null)
225
225
  })
226
226
 
227
- it("should publish events", function() {
227
+ it("should publish events", function () {
228
228
  return new Promise((resolve, reject) => {
229
229
  const chess = new Chess()
230
230
  chess.addObserver((event) => {
231
- if(event.type === "legalMove" && event.move === "e4") {
231
+ if (event.type === "legalMove" &&
232
+ event.move.from === "e2" &&
233
+ event.move.to === "e4") {
232
234
  resolve()
233
235
  } else {
234
236
  reject("error event")
@@ -238,18 +240,18 @@ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
238
240
  })
239
241
  })
240
242
 
241
- it("should provide valid moves", function() {
243
+ it("should provide valid moves", function () {
242
244
  const chess = new Chess()
243
245
  assert.equal(chess.moves().length, 20)
244
246
  chess.move("Nc3")
245
247
  assert.equal(chess.moves().length, 20)
246
248
  chess.move("e5")
247
249
  assert.equal(chess.moves().length, 22)
248
- assert.equal(JSON.stringify(chess.moves({ square: "e2"})), '["e3","e4"]')
249
- assert.equal(JSON.stringify(chess.moves({ piece: "n" })), '["Na4","Nb5","Nd5","Ne4","Nb1","Nf3","Nh3"]')
250
+ assert.equal(JSON.stringify(chess.moves({square: "e2"})), '["e3","e4"]')
251
+ assert.equal(JSON.stringify(chess.moves({piece: "n"})), '["Na4","Nb5","Nd5","Ne4","Nb1","Nf3","Nh3"]')
250
252
  })
251
253
 
252
- it("should detect a check in a game without moves", function() {
254
+ it("should detect a check in a game without moves", function () {
253
255
  const chess = new Chess("4k3/1P6/8/b7/6r1/8/pp2PPPP/2R1KBNR w K - 0 1")
254
256
  assert.true(chess.inCheck())
255
257
  })