[Paco-Sako] At least forbid to castle when under direct check
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 4 Jan 2021 17:43:18 +0000 (18:43 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 4 Jan 2021 17:43:18 +0000 (18:43 +0100)
client/src/variants/Pacosako.js

index 2048d2c..b88f2e3 100644 (file)
@@ -405,6 +405,23 @@ export class PacosakoRules extends ChessRules {
     return moves;
   }
 
+  getPotentialKingMoves(sq) {
+    let moves = this.getSlideNJumpMoves(
+      sq,
+      V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
+      "oneStep"
+    );
+    const c = this.turn;
+    const oppCol = V.GetOppCol(c);
+    if (
+      !this.isAttacked(this.kingPos[c], oppCol) &&
+      this.castleFlags[c].some(v => v < V.size.y)
+    ) {
+      moves = moves.concat(super.getCastleMoves(sq, null, true));
+    }
+    return moves;
+  }
+
   getEpSquare(moveOrSquare) {
     if (typeof moveOrSquare === "string") {
       const square = moveOrSquare;