More robust in-check indications (ready for Antiking)
[vchess.git] / public / javascripts / base_rules.js
index 9a4ef91..b604e79 100644 (file)
@@ -629,6 +629,7 @@ class ChessRules
                return false;
        }
 
+       // Is color c under check after move ?
        underCheck(move, c)
        {
                this.play(move);
@@ -637,6 +638,17 @@ class ChessRules
                return res;
        }
 
+       // On which squares is color c under check (after move) ?
+       getCheckSquares(move, c)
+       {
+               this.play(move);
+               let res = this.isAttacked(this.kingPos[c], this.getOppCol(c))
+                       ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] //need to duplicate!
+                       : [ ];
+               this.undo(move);
+               return res;
+       }
+
        // Apply a move on board
        static PlayOnBoard(board, move)
        {