Fix Titan (king tracking)
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 24 Mar 2021 13:47:33 +0000 (14:47 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 24 Mar 2021 13:47:33 +0000 (14:47 +0100)
client/src/variants/Titan.js

index 836acc1..427eecd 100644 (file)
@@ -228,11 +228,21 @@ export class TitanRules extends ChessRules {
   }
 
   postPlay(move) {
   }
 
   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) {
   }
 
   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() {
   }
 
   evalPosition() {