From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 24 Mar 2021 13:47:33 +0000 (+0100)
Subject: Fix Titan (king tracking)
X-Git-Url: https://git.auder.net/variants/current/css/doc/img/pieces/cb.svg?a=commitdiff_plain;h=70c94aa7b7c3cb8832a728881a29feeb26118eb9;p=vchess.git

Fix Titan (king tracking)
---

diff --git a/client/src/variants/Titan.js b/client/src/variants/Titan.js
index 836acc1f..427eecdb 100644
--- a/client/src/variants/Titan.js
+++ b/client/src/variants/Titan.js
@@ -228,11 +228,21 @@ export class TitanRules extends ChessRules {
   }
 
   postPlay(move) {
-    if (this.movesCount > 4) super.postPlay(move);
+    if (this.movesCount > 4) {
+      let piece = move.vanish[0].p;
+      if (['j', 'l'].includes(piece)) piece = V.KING;
+      if (piece == V.KING && move.appear.length > 0)
+        this.kingPos[c] = [move.appear[0].x, move.appear[0].y];
+      this.updateCastleFlags(move, piece);
+    }
   }
 
   postUndo(move) {
-    if (this.movesCount >= 4) super.postUndo(move);
+    if (this.movesCount >= 4) {
+      const c = this.getColor(move.start.x, move.start.y);
+      if (['j', 'k', 'l'].includes(this.getPiece(move.start.x, move.start.y)))
+        this.kingPos[c] = [move.start.x, move.start.y];
+    }
   }
 
   evalPosition() {