Experimental loss on repetition for Shogi and Pandemonium. Simplify Crazyhouse, with...
[vchess.git] / client / src / variants / Shogi.js
index 6c522dc..bca3762 100644 (file)
@@ -3,6 +3,7 @@ import { ArrayFun } from "@/utils/array";
 import { sample, shuffle } from "@/utils/alea";
 
 export class ShogiRules extends ChessRules {
+
   static get HasFlags() {
     return false;
   }
@@ -15,10 +16,19 @@ export class ShogiRules extends ChessRules {
     return true;
   }
 
+  get showFirstTurn() {
+    return true;
+  }
+
   static get Notoodark() {
     return true;
   }
 
+  loseOnRepetition() {
+    // If current side is under check: lost
+    return this.underCheck(this.turn);
+  }
+
   static IsGoodFen(fen) {
     if (!ChessRules.IsGoodFen(fen)) return false;
     const fenParsed = V.ParseFen(fen);
@@ -277,7 +287,9 @@ export class ShogiRules extends ChessRules {
           if (p == V.PAWN) {
             // Do not drop on checkmate:
             this.play(mv);
-            const res = (this.underCheck(oppCol) && !this.atLeastOneMove());
+            const res = (
+              this.underCheck(oppCol) && !this.atLeastOneMove("noReserve")
+            );
             this.undo(mv);
             if (res) continue;
           }
@@ -307,7 +319,7 @@ export class ShogiRules extends ChessRules {
       case V.LANCE:
         return this.getPotentialLanceMoves([x, y]);
       case V.KING:
-        return this.getPotentialKingMoves([x, y]);
+        return super.getPotentialKingMoves([x, y]);
       case V.P_ROOK:
         return this.getPotentialDragonMoves([x, y]);
       case V.P_BISHOP:
@@ -446,14 +458,6 @@ export class ShogiRules extends ChessRules {
     );
   }
 
-  getPotentialKingMoves(sq) {
-    return this.getSlideNJumpMoves(
-      sq,
-      V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
-      { oneStep: true }
-    );
-  }
-
   isAttacked(sq, color) {
     return (
       this.isAttackedByPawn(sq, color) ||
@@ -551,14 +555,16 @@ export class ShogiRules extends ChessRules {
     return this.filterValid(moves);
   }
 
-  atLeastOneMove() {
+  atLeastOneMove(noReserve) {
     if (!super.atLeastOneMove()) {
-      // Search one reserve move
-      for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
-        let moves = this.filterValid(
-          this.getReserveMoves([V.size.x + (this.turn == "w" ? 0 : 1), i])
-        );
-        if (moves.length > 0) return true;
+      if (!noReserve) {
+        // Search one reserve move
+        for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
+          let moves = this.filterValid(
+            this.getReserveMoves([V.size.x + (this.turn == "w" ? 0 : 1), i])
+          );
+          if (moves.length > 0) return true;
+        }
       }
       return false;
     }
@@ -656,4 +662,5 @@ export class ShogiRules extends ChessRules {
       )
     );
   }
+
 };