Revise pieces images
[vchess.git] / client / src / variants / Allmate.js
index 6225b92..728de25 100644 (file)
@@ -5,10 +5,6 @@ export const VariantRules = class AllmateRules extends ChessRules {
     return false;
   }
 
-  canTake(sq1, sq2) {
-    return false; //Captures handled differently
-  }
-
   getCheckSquares() {
     // No notion of check
     return [];
@@ -20,6 +16,10 @@ export const VariantRules = class AllmateRules extends ChessRules {
 
   getPotentialMovesFrom([x, y]) {
     let moves = super.getPotentialMovesFrom([x, y]);
+    // Remove standard captures (without removing castling):
+    moves = moves.filter(m => {
+      return m.vanish.length == 1 || m.appear.length == 2;
+    });
 
     // Augment moves with "mate-captures":
     // TODO: this is coded in a highly inefficient way...
@@ -240,20 +240,34 @@ export const VariantRules = class AllmateRules extends ChessRules {
 
   updateVariables(move) {
     super.updateVariables(move);
-    if (move.vanish.length == 2 && move.appear.length == 1) {
-      // Did opponent king disappeared?
-      if (move.vanish.some(v => v.p == V.KING))
-        this.kingPos[this.turn] = [-1, -1];
+    const color = V.GetOppCol(this.turn);
+    if (move.vanish.length >= 2 && move.appear.length == 1) {
+      move.vanish.forEach(v => {
+        if (v.c == color)
+          return;
+        // Did opponent king disappeared?
+        if (v.p == V.KING)
+          this.kingPos[this.turn] = [-1, -1];
+        // Or maybe a rook?
+        else if (v.p == V.ROOK) {
+          if (v.y < this.INIT_COL_KING[v.c])
+            this.castleFlags[v.c][0] = false;
+          else
+            // v.y > this.INIT_COL_KING[v.c]
+            this.castleFlags[v.c][1] = false;
+        }
+      });
     }
   }
 
   unupdateVariables(move) {
     super.unupdateVariables(move);
-    if (move.vanish.length == 2 && move.appear.length == 1) {
+    const color = this.turn;
+    if (move.vanish.length >= 2 && move.appear.length == 1) {
       // Did opponent king disappeared?
-      const vIdx = move.vanish.findIndex(v => v.p == V.KING)
-      if (vIdx >= 0)
-        this.kingPos[move.vanish[vIdx].c] = [move.vanish[vIdx].x,move.vanish[vIdx].y];
+      const psq = move.vanish.find(v => v.p == V.KING && v.c != color)
+      if (psq)
+        this.kingPos[psq.c] = [psq.x, psq.y];
     }
   }
 
@@ -276,12 +290,11 @@ export const VariantRules = class AllmateRules extends ChessRules {
   getNotation(move) {
     let notation = super.getNotation(move);
     // Add a capture mark (not describing what is captured...):
-    if (move.vanish.length > 1 && move.appear[0].p != V.KING) {
-      if (notation.match(/^[a-h]/))
-        // Pawn capture: remove "bx" in bxc4 for example
-        notation = notation.substr(2);
-      else
-        notation = notation.replace("x","") + "X";
+    if (move.vanish.length > 1 && move.appear.length == 1) {
+      if (notation.match(/^[a-h]x/))
+        // Pawn capture: remove initial "b" in bxc4 for example
+        notation = notation.substr(1);
+      notation = notation.replace("x","") + "X";
     }
     return notation;
   }