cm-chess 3.4.0 → 3.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Chess.js +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chess",
3
- "version": "3.4.0",
3
+ "version": "3.4.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
@@ -327,9 +327,11 @@ export class Chess {
327
327
  }
328
328
 
329
329
  /**
330
+ * @param move
330
331
  * @returns {string} "b" or "w" the color to move in the main variation
331
332
  */
332
- turn() {
333
+ turn(move = this.lastMove()) {
334
+ console.log("move", move)
333
335
  let factor = 0
334
336
  if (this.setUpFen()) {
335
337
  const fenParts = this.setUpFen().split(" ")
@@ -337,7 +339,8 @@ export class Chess {
337
339
  factor = 1
338
340
  }
339
341
  }
340
- return (this.pgn.history.moves.length) % 2 === factor ? COLOR.white : COLOR.black
342
+ const ply = move ? move.ply : 0
343
+ return (ply) % 2 === factor ? COLOR.white : COLOR.black
341
344
  }
342
345
 
343
346
  /**