Fix king tracking in Fusion variant
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 22 Feb 2021 14:27:16 +0000 (15:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 22 Feb 2021 14:27:16 +0000 (15:27 +0100)
client/src/variants/Fusion.js

index a0098ab..2eb8b2d 100644 (file)
@@ -399,16 +399,17 @@ export class FusionRules extends ChessRules {
 
   postPlay(move) {
     const c = V.GetOppCol(this.turn);
-    const piece = move.appear[0].p;
-    if ([V.KING, V.KN, V.KB, V.KR].includes(piece))
-      this.kingPos[c] = [move.appear[0].x, move.appear[0].y];
-    this.updateCastleFlags(move, piece);
+    move.kingMove = (
+      [V.KING, V.KN, V.KB, V.KR].includes(move.appear[0].p) &&
+      [V.KING, V.KN, V.KB, V.KR].includes(move.vanish[0].p)
+    );
+    if (move.kingMove) this.kingPos[c] = [move.appear[0].x, move.appear[0].y];
+    this.updateCastleFlags(move, move.appear[0].p);
   }
 
   postUndo(move) {
     const c = this.getColor(move.start.x, move.start.y);
-    if ([V.KING, V.KN, V.KB, V.KR].includes(move.appear[0].p))
-      this.kingPos[c] = [move.start.x, move.start.y];
+    if (!!move.kingMove) this.kingPos[c] = [move.start.x, move.start.y];
   }
 
   static get VALUES() {