From 6037f1d82232e62b669018b548845baf480f9e64 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 20 Nov 2018 15:46:19 +0100
Subject: [PATCH] Antiking seems OK now

---
 public/javascripts/base_rules.js        | 24 ++++++++++++------------
 public/javascripts/variants/Antiking.js | 23 +++++++++++++++--------
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js
index 8626b888..cdd75727 100644
--- a/public/javascripts/base_rules.js
+++ b/public/javascripts/base_rules.js
@@ -65,37 +65,37 @@ class ChessRules
 		const position = fenParts[0].split("/");
 		for (let i=0; i<position.length; i++)
 		{
-			let j = 0;
-			while (j < position[i].length)
+			let k = 0; //column index on board
+			for (let j=0; j<position[i].length; j++)
 			{
 				switch (position[i].charAt(j))
 				{
 					case 'k':
-						this.kingPos['b'] = [i,j];
-						this.INIT_COL_KING['b'] = j;
+						this.kingPos['b'] = [i,k];
+						this.INIT_COL_KING['b'] = k;
 						break;
 					case 'K':
-						this.kingPos['w'] = [i,j];
-						this.INIT_COL_KING['w'] = j;
+						this.kingPos['w'] = [i,k];
+						this.INIT_COL_KING['w'] = k;
 						break;
 					case 'r':
 						if (this.INIT_COL_ROOK['b'][0] < 0)
-							this.INIT_COL_ROOK['b'][0] = j;
+							this.INIT_COL_ROOK['b'][0] = k;
 						else
-							this.INIT_COL_ROOK['b'][1] = j;
+							this.INIT_COL_ROOK['b'][1] = k;
 						break;
 					case 'R':
 						if (this.INIT_COL_ROOK['w'][0] < 0)
-							this.INIT_COL_ROOK['w'][0] = j;
+							this.INIT_COL_ROOK['w'][0] = k;
 						else
-							this.INIT_COL_ROOK['w'][1] = j;
+							this.INIT_COL_ROOK['w'][1] = k;
 						break;
 					default:
 						let num = parseInt(position[i].charAt(j));
 						if (!isNaN(num))
-							j += (num-1);
+							k += (num-1);
 				}
-				j++;
+				k++;
 			}
 		}
 		const epSq = this.moves.length > 0 ? this.getEpSquare(this.lastMove) : undefined;
diff --git a/public/javascripts/variants/Antiking.js b/public/javascripts/variants/Antiking.js
index 2770261a..53e55188 100644
--- a/public/javascripts/variants/Antiking.js
+++ b/public/javascripts/variants/Antiking.js
@@ -15,23 +15,23 @@ class AntikingRules extends ChessRules
 		const position = fen.split(" ")[0].split("/");
 		for (let i=0; i<position.length; i++)
 		{
-			let j = 0;
-			while (j < position[i].length)
+			let k = 0;
+			for (let j=0; j<position[i].length; j++)
 			{
 				switch (position[i].charAt(j))
 				{
 					case 'a':
-						this.antikingPos['b'] = [i,j];
+						this.antikingPos['b'] = [i,k];
 						break;
 					case 'A':
-						this.antikingPos['w'] = [i,j];
+						this.antikingPos['w'] = [i,k];
 						break;
 					default:
 						let num = parseInt(position[i].charAt(j));
 						if (!isNaN(num))
-							j += (num-1);
+							k += (num-1);
 				}
-				j++;
+				k++;
 			}
 		}
 	}
@@ -67,12 +67,19 @@ class AntikingRules extends ChessRules
 		return (super.isAttacked(sq, colors) || this.isAttackedByAntiking(sq, colors));
 	}
 
+	isAttackedByKing([x,y], colors)
+	{
+		if (this.getPiece(x,y) == VariantRules.ANTIKING)
+			return false; //antiking is not attacked by king
+		return this.isAttackedBySlideNJump([x,y], colors,
+			VariantRules.KING, VariantRules.steps[VariantRules.QUEEN], "oneStep");
+	}
+
 	isAttackedByAntiking([x,y], colors)
 	{
-		console.log(x + " " + y); //TODO: debug -1, -1 (wrong undo ?!)
 		if (this.getPiece(x,y) == VariantRules.KING)
 			return false; //king is not attacked by antiking
-		return super.isAttackedBySlideNJump([x,y], colors,
+		return this.isAttackedBySlideNJump([x,y], colors,
 			VariantRules.ANTIKING, VariantRules.steps[VariantRules.QUEEN], "oneStep");
 	}
 
-- 
2.44.0