Add chessvariants.com link to Paco-Sako rules
[vchess.git] / client / src / variants / Pacosako.js
index 2048d2c..bf84719 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;
@@ -455,6 +472,7 @@ export class PacosakoRules extends ChessRules {
   }
 
   play(move) {
+    move.flags = JSON.stringify(this.aggregateFlags());
     this.epSquares.push(this.getEpSquare(move));
     // Check if the move is the last of the turn: all cases except releases
     if (!move.released) {
@@ -482,6 +500,7 @@ export class PacosakoRules extends ChessRules {
 
   undo(move) {
     this.epSquares.pop();
+    this.disaggregateFlags(JSON.parse(move.flags));
     V.UndoOnBoard(this.board, move);
     this.lastMoveEnd.pop();
     if (!move.released) {