Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Synchrone1.js
index ba9cf9f..2aa5b45 100644 (file)
@@ -53,8 +53,8 @@ export class Synchrone1Rules extends ChessRules {
     );
   }
 
-  static GenRandInitFen(randomness) {
-    return ChessRules.GenRandInitFen(randomness).slice(0, -1) + "-,- -";
+  static GenRandInitFen(options) {
+    return ChessRules.GenRandInitFen(options).slice(0, -1) + "-,- -";
   }
 
   getFen() {
@@ -363,9 +363,11 @@ export class Synchrone1Rules extends ChessRules {
     return smove;
   }
 
-  play(move) {
-    move.flags = JSON.stringify(this.aggregateFlags()); //save flags (for undo)
-    this.epSquares.push(this.getEpSquare(move));
+  play(move, noFlag) {
+    if (!noFlag) {
+      move.flags = JSON.stringify(this.aggregateFlags());
+      this.epSquares.push(this.getEpSquare(move));
+    }
     // Do not play on board (would reveal the move...)
     this.turn = V.GetOppCol(this.turn);
     this.movesCount++;
@@ -399,7 +401,7 @@ export class Synchrone1Rules extends ChessRules {
 
     // Update king position + flags
     let kingAppear = { 'w': false, 'b': false };
-    for (let i=0; i<smove.appear.length; i++) {
+    for (let i = 0; i < smove.appear.length; i++) {
       if (smove.appear[i].p == V.KING) {
         const c = smove.appear[i].c;
         kingAppear[c] = true;
@@ -407,7 +409,7 @@ export class Synchrone1Rules extends ChessRules {
         this.kingPos[c][1] = smove.appear[i].y;
       }
     }
-    for (let i=0; i<smove.vanish.length; i++) {
+    for (let i = 0; i < smove.vanish.length; i++) {
       if (smove.vanish[i].p == V.KING) {
         const c = smove.vanish[i].c;
         if (!kingAppear[c]) {
@@ -421,9 +423,11 @@ export class Synchrone1Rules extends ChessRules {
     move.smove = smove;
   }
 
-  undo(move) {
-    this.epSquares.pop();
-    this.disaggregateFlags(JSON.parse(move.flags));
+  undo(move, noFlag) {
+    if (!noFlag) {
+      this.epSquares.pop();
+      this.disaggregateFlags(JSON.parse(move.flags));
+    }
     if (this.turn == 'w')
       // Back to the middle of the move
       V.UndoOnBoard(this.board, move.smove);
@@ -434,7 +438,7 @@ export class Synchrone1Rules extends ChessRules {
 
   postUndo(move) {
     if (this.turn == 'w') {
-      // Reset king positions: scan board
+      // Reset king positions: scan board (TODO: could be more efficient)
       this.scanKings();
       // Also reset whiteMove
       this.whiteMove = null;
@@ -447,14 +451,14 @@ export class Synchrone1Rules extends ChessRules {
     if (color == 'b') {
       // kingPos must be reset for appropriate highlighting:
       var lastMove = JSON.parse(JSON.stringify(this.whiteMove));
-      this.undo(lastMove); //will erase whiteMove, thus saved above
+      this.undo(lastMove, "noFlag"); //will erase whiteMove, thus saved above
     }
     let res = [];
     if (this.kingPos['w'][0] >= 0 && this.underCheck('w'))
       res.push(JSON.parse(JSON.stringify(this.kingPos['w'])));
     if (this.kingPos['b'][0] >= 0 && this.underCheck('b'))
       res.push(JSON.parse(JSON.stringify(this.kingPos['b'])));
-    if (color == 'b') this.play(lastMove);
+    if (color == 'b') this.play(lastMove, "noFlag");
     return res;
   }