Fix Atomic when an init rook is taken
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Dec 2018 14:27:07 +0000 (15:27 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Dec 2018 14:27:07 +0000 (15:27 +0100)
public/javascripts/variants/Atomic.js

index a6934e7..633e70a 100644 (file)
@@ -66,7 +66,8 @@ class AtomicRules extends ChessRules
                        && this.board[move.end.x][move.end.y] != VariantRules.EMPTY)
                {
                        const oppCol = this.getOppCol(c);
-                       const oppFirstRank = (oppCol == "w" ? 7 : 0);
+                       const firstRank = (c == "w" ? 7 : 0);
+                       const oppFirstRank = 7 - firstRank;
 
                        // Did we explode our king ? (TODO: remove move earlier)
                        if (Math.abs(this.kingPos[c][0]-move.end.x) <= 1
@@ -75,6 +76,17 @@ class AtomicRules extends ChessRules
                                this.kingPos[c] = [-1,-1];
                                this.castleFlags[c] = [false,false];
                        }
+                       else
+                       {
+                               // Now check if our init rook(s) exploded
+                               if (Math.abs(move.end.x-firstRank) <= 1)
+                               {
+                                       if (Math.abs(move.end.y-this.INIT_COL_ROOK[oppCol][0]) <= 1)
+                                               this.castleFlags[c][0] = false;
+                                       if (Math.abs(move.end.y-this.INIT_COL_ROOK[oppCol][1]) <= 1)
+                                               this.castleFlags[c][1] = false;
+                               }
+                       }
 
                        // Did we explode opponent king ?
                        if (Math.abs(this.kingPos[oppCol][0]-move.end.x) <= 1