From 7097b7363df7d1d632a4c94c1f3ba8a3431d62d0 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Mon, 22 Feb 2021 15:27:16 +0100
Subject: [PATCH] Fix king tracking in Fusion variant

---
 client/src/variants/Fusion.js | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/client/src/variants/Fusion.js b/client/src/variants/Fusion.js
index a0098ab6..2eb8b2da 100644
--- a/client/src/variants/Fusion.js
+++ b/client/src/variants/Fusion.js
@@ -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() {
-- 
2.44.0