Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / variants / Titan.js
index 836acc1..425e08d 100644 (file)
@@ -154,6 +154,8 @@ export class TitanRules extends ChessRules {
     const [x, y] = [square[0], square[1]];
     if ((color == 'w' && x != 7) || (color == 'b' && x != 0)) return null;
     const selectedPiece = this.board[x][y][1];
+    // Prevent re-augmenting a chosen piece:
+    if (!ChessRules.PIECES.includes(selectedPiece)) return null;
     return new Move({
       appear: [
         new PiPo({
@@ -228,11 +230,20 @@ 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)
+        this.kingPos[move.appear[0].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) {
+      if (['j', 'k', 'l'].includes(this.getPiece(move.start.x, move.start.y)))
+        this.kingPos[move.vanish[0].c] = [move.start.x, move.start.y];
+    }
   }
 
   evalPosition() {