From 7caf0e69252d0635a8d8e241b24655c48cb2622c Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Sat, 6 Feb 2021 18:46:30 +0100
Subject: [PATCH] Fix Empire Chess

---
 client/src/variants/Empire.js | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/client/src/variants/Empire.js b/client/src/variants/Empire.js
index 2ce84930..c8577a72 100644
--- a/client/src/variants/Empire.js
+++ b/client/src/variants/Empire.js
@@ -164,9 +164,6 @@ export class EmpireRules extends ChessRules {
     // or if move.end.x == enemy king rank.
     const color = this.getColor(sq[0], sq[1]);
     const oppCol = V.GetOppCol(color);
-    // check == -1 if (row, or col) unchecked, 1 if checked and occupied,
-    //          0 if checked and clear
-    let check = [-1, -1];
     return moves.filter(m => {
       if (
         m.end.y != this.kingPos[oppCol][1] &&
@@ -174,13 +171,15 @@ export class EmpireRules extends ChessRules {
       ) {
         return true;
       }
+      // check == -1 if (row, or col) unchecked, 1 if checked and occupied,
+      //          0 if checked and clear
+      let check = [-1, -1];
       // TODO: factor two next "if"...
       if (m.end.x == this.kingPos[oppCol][0]) {
         if (check[0] < 0) {
           // Do the check:
           check[0] = 0;
-          let [kingPos1, kingPos2] =
-            [this.kingPos[color][1], this.kingPos[oppCol][1]];
+          let [kingPos1, kingPos2] = [m.end.y, this.kingPos[oppCol][1]];
           if (kingPos1 > kingPos2) [kingPos1, kingPos2] = [kingPos2, kingPos1];
           for (let i = kingPos1 + 1; i < kingPos2; i++) {
             if (this.board[m.end.x][i] != V.EMPTY) {
@@ -197,8 +196,7 @@ export class EmpireRules extends ChessRules {
       if (check[1] < 0) {
         // Do the check:
         check[1] = 0;
-        let [kingPos1, kingPos2] =
-          [this.kingPos[color][0], this.kingPos[oppCol][0]];
+        let [kingPos1, kingPos2] = [m.end.x, this.kingPos[oppCol][0]];
         if (kingPos1 > kingPos2) [kingPos1, kingPos2] = [kingPos2, kingPos1];
         for (let i = kingPos1 + 1; i < kingPos2; i++) {
           if (this.board[i][m.end.y] != V.EMPTY) {
-- 
2.44.0