A few bugs fixes
authorBenjamin Auder <benjamin.auder@somewhere>
Tue, 1 Sep 2020 12:33:49 +0000 (14:33 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Tue, 1 Sep 2020 12:33:49 +0000 (14:33 +0200)
client/src/variants/Checkered1.js
client/src/variants/Clorange.js
client/src/variants/Hiddenqueen.js

index 4556f07..fd0d68d 100644 (file)
@@ -131,7 +131,7 @@ export class Checkered1Rules extends ChessRules {
     );
   }
 
     );
   }
 
-  getPotentialMovesFrom([x, y]) {
+  getPotentialMovesFrom([x, y], noswitch) {
     let standardMoves = super.getPotentialMovesFrom([x, y]);
     if (this.stage == 1) {
       const color = this.turn;
     let standardMoves = super.getPotentialMovesFrom([x, y]);
     if (this.stage == 1) {
       const color = this.turn;
@@ -141,7 +141,10 @@ export class Checkered1Rules extends ChessRules {
       // King is treated differently: it never turn checkered
       if (this.getPiece(x, y) == V.KING) {
         // If at least one checkered piece, allow switching:
       // King is treated differently: it never turn checkered
       if (this.getPiece(x, y) == V.KING) {
         // If at least one checkered piece, allow switching:
-        if (this.board.some(b => b.some(cell => cell[0] == 'c'))) {
+        if (
+          !noswitch &&
+          this.board.some(b => b.some(cell => cell[0] == 'c'))
+        ) {
           const oppCol = V.GetOppCol(color);
           moves.push(
             new Move({
           const oppCol = V.GetOppCol(color);
           moves.push(
             new Move({
@@ -328,7 +331,7 @@ export class Checkered1Rules extends ChessRules {
             )
           )
         ) {
             )
           )
         ) {
-          const moves = this.getPotentialMovesFrom([i, j]);
+          const moves = this.getPotentialMovesFrom([i, j], "noswitch");
           if (moves.length > 0) {
             for (let k = 0; k < moves.length; k++)
               if (this.filterValid([moves[k]]).length > 0) return true;
           if (moves.length > 0) {
             for (let k = 0; k < moves.length; k++)
               if (this.filterValid([moves[k]]).length > 0) return true;
index 4c54e94..e96d851 100644 (file)
@@ -168,7 +168,7 @@ export class ClorangeRules extends ChessRules {
       return this.getReserveMoves([x, y]);
     // Standard moves
     switch (this.getPiece(x, y)) {
       return this.getReserveMoves([x, y]);
     // Standard moves
     switch (this.getPiece(x, y)) {
-      case 's': return super.getPotentialPawnMoves([x, y]);
+      case 's': return this.getPotentialPawnMoves([x, y]);
       case 'u': return super.getPotentialRookMoves([x, y]);
       case 'o': return super.getPotentialKnightMoves([x, y]);
       case 'c': return super.getPotentialBishopMoves([x, y]);
       case 'u': return super.getPotentialRookMoves([x, y]);
       case 'o': return super.getPotentialKnightMoves([x, y]);
       case 'c': return super.getPotentialBishopMoves([x, y]);
@@ -180,13 +180,17 @@ export class ClorangeRules extends ChessRules {
 
   getPotentialPawnMoves(sq) {
     let moves = super.getPotentialPawnMoves(sq);
 
   getPotentialPawnMoves(sq) {
     let moves = super.getPotentialPawnMoves(sq);
-    moves.forEach(m => {
-      if (m.vanish[0].p == 's' && m.appear[0].p != 's') {
-        // Promotion pieces should be non-violent as well:
-        const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p)
-        m.appear[0].p = V.NON_VIOLENT[pIdx];
-      }
-    });
+    if (moves.length > 0 && moves[0].vanish[0].p == 's') {
+      // Remove captures for non-violent pawns:
+      moves = moves.filter(m => m.vanish.length == 1);
+      moves.forEach(m => {
+        if (m.appear[0].p != 's') {
+          // Promotion pieces should be non-violent as well:
+          const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p)
+          m.appear[0].p = V.NON_VIOLENT[pIdx];
+        }
+      });
+    }
     return moves;
   }
 
     return moves;
   }
 
index b180c6f..f1607a6 100644 (file)
@@ -180,6 +180,11 @@ export class HiddenqueenRules extends ChessRules {
       this.kingPos[oppCol] = [move.vanish[1].x, move.vanish[1].y];
   }
 
       this.kingPos[oppCol] = [move.vanish[1].x, move.vanish[1].y];
   }
 
+  underCheck(color) {
+    if (this.kingPos[color][0] < 0) return false;
+    return super.underCheck(color);
+  }
+
   getCurrentScore() {
     const color = this.turn;
     if (this.kingPos[color][0] < 0)
   getCurrentScore() {
     const color = this.turn;
     if (this.kingPos[color][0] < 0)