From: Benjamin Auder <benjamin.auder@somewhere>
Date: Mon, 3 Dec 2018 14:27:07 +0000 (+0100)
Subject: Fix Atomic when an init rook is taken
X-Git-Url: https://git.auder.net/variants/%24%7Bvname%7D/current/pieces/%3C?a=commitdiff_plain;h=383387d2404756263a52da5c37de30ff71afa37b;p=vchess.git

Fix Atomic when an init rook is taken
---

diff --git a/public/javascripts/variants/Atomic.js b/public/javascripts/variants/Atomic.js
index a6934e73..633e70a9 100644
--- a/public/javascripts/variants/Atomic.js
+++ b/public/javascripts/variants/Atomic.js
@@ -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