Fix Synchrone2::filterValid()
[vchess.git] / client / src / variants / Synchrone2.js
index 00d68ad..5539c9e 100644 (file)
@@ -5,7 +5,7 @@ import { randInt } from "@/utils/alea";
 export class Synchrone2Rules extends Synchrone1Rules {
 
   static get CanAnalyze() {
-    return true;//false;
+    return false;
   }
 
   static get HasEnpassant() {
@@ -118,10 +118,10 @@ export class Synchrone2Rules extends Synchrone1Rules {
   }
 
   filterValid(moves) {
-    if (moves.length == 0) return [];
-    if (moves.length == 1 && moves[0].vanish.length == 0) return moves;
+    const nonEmptyMove = moves.find(m => m.vanish.length > 0);
+    if (!nonEmptyMove) return moves;
     // filterValid can be called when it's "not our turn":
-    const color = moves.find(m => m.vanish.length > 0).vanish[0].c;
+    const color = nonEmptyMove.vanish[0].c;
     return moves.filter(m => {
       if (m.vanish.length == 0) return true;
       const piece = m.vanish[0].p;
@@ -199,7 +199,17 @@ export class Synchrone2Rules extends Synchrone1Rules {
     this.turn = V.GetOppCol(this.turn);
     this.movesCount--;
     if (this.movesCount % 4 == 0) this.initfenStack.pop();
-    if (move.vanish.length > 0) super.postUndo(move);
+    this.postUndo(move);
+  }
+
+  postUndo(move) {
+    if (this.turn == 'w') {
+      // Reset king positions: scan board (TODO: could be more efficient)
+      if (move.vanish.length > 0) this.scanKings();
+      // Also reset whiteMove
+      this.whiteMove = null;
+    }
+    else this.whiteMove = move.whiteMove;
   }
 
   getCurrentScore() {