Fix Benedict rules
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 22 Feb 2020 10:48:08 +0000 (11:48 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 22 Feb 2020 10:48:08 +0000 (11:48 +0100)
client/src/base_rules.js
client/src/translations/rules/Benedict/en.pug
client/src/translations/rules/Benedict/es.pug
client/src/translations/rules/Benedict/fr.pug
client/src/variants/Benedict.js

index 656f701..5bf47f7 100644 (file)
@@ -1055,7 +1055,6 @@ export const ChessRules = class ChessRules {
   // What is the score ? (Interesting if game is over)
   getCurrentScore() {
     if (this.atLeastOneMove())
   // What is the score ? (Interesting if game is over)
   getCurrentScore() {
     if (this.atLeastOneMove())
-      // game not over
       return "*";
 
     // Game over
       return "*";
 
     // Game over
index 805dbf4..9f6da6f 100644 (file)
@@ -14,8 +14,8 @@ figure.diagram-container
 h3 End of the game
 
 p.
 h3 End of the game
 
 p.
-  The game ends when a king changes color.
-  There can be no stalemate since all pieces remain on the board.
+  The game ends when a king changes color,
+  or when a side cannot make a move (stalemate, draw).
 
 p.
   In the diagram position, 2...g6?? for example would allow 3.Nf6 which
 
 p.
   In the diagram position, 2...g6?? for example would allow 3.Nf6 which
index 30a7b74..439d5da 100644 (file)
@@ -10,8 +10,8 @@ figure.diagram-container
 h3 Fin de la partida
 
 p.
 h3 Fin de la partida
 
 p.
-  El juego termina cuando un rey cambia de color.
-  No puede hay empate ya que todas las piezas permanecen en el tablero.
+  El juego termina cuando un rey cambia de color,
+  o cuando un lado ya no tiene un movimiento legal (pat, tablas).
 
 p.
   En la posición del diagrama, 2...g6?? por ejemplo permitiría 3.Nf6 que
 
 p.
   En la posición del diagrama, 2...g6?? por ejemplo permitiría 3.Nf6 que
index 6625912..542a189 100644 (file)
@@ -10,8 +10,8 @@ figure.diagram-container
 h3 Fin de la partie
 
 p.
 h3 Fin de la partie
 
 p.
-  La partie s'achève quand un roi change de couleur.
-  Il ne peut pas y avoir de pat puisque toutes les pièces restent sur l'échiquier.
+  La partie s'achève quand un roi change de couleur,
+  ou qu'un camp ne dispose plus de coups légaux (pat, match nul).
 
 p.
   Dans la position du diagrame, 2...g6?? par exemple permettrait 3.Nf6 qui
 
 p.
   Dans la position du diagrame, 2...g6?? par exemple permettrait 3.Nf6 qui
index e3e55eb..fbeef89 100644 (file)
@@ -140,27 +140,34 @@ export const VariantRules = class BenedictRules extends ChessRules {
     // Get all moves from x,y without captures:
     let moves = super.getPotentialMovesFrom([x, y]);
     // Add flips:
     // Get all moves from x,y without captures:
     let moves = super.getPotentialMovesFrom([x, y]);
     // Add flips:
+    let newAppear = [];
+    let newVanish = [];
     moves.forEach(m => {
       V.PlayOnBoard(this.board, m);
     moves.forEach(m => {
       V.PlayOnBoard(this.board, m);
-      const flipped = this.findCaptures([m.end.x, m.end.y]);
-      V.UndoOnBoard(this.board, m);
-      flipped.forEach(sq => {
-        const piece = this.getPiece(sq[0],sq[1]);
-        const pipoA = new PiPo({
-          x:sq[0],
-          y:sq[1],
-          c:color,
-          p:piece
-        });
-        const pipoV = new PiPo({
-          x:sq[0],
-          y:sq[1],
-          c:oppCol,
-          p:piece
+      // If castling, m.appear has 2 elements:
+      m.appear.forEach(a => {
+        const flipped = this.findCaptures([a.x, a.y]);
+        flipped.forEach(sq => {
+          const piece = this.getPiece(sq[0],sq[1]);
+          const pipoA = new PiPo({
+            x:sq[0],
+            y:sq[1],
+            c:color,
+            p:piece
+          });
+          const pipoV = new PiPo({
+            x:sq[0],
+            y:sq[1],
+            c:oppCol,
+            p:piece
+          });
+          newAppear.push(pipoA);
+          newVanish.push(pipoV);
         });
         });
-        m.appear.push(pipoA);
-        m.vanish.push(pipoV);
+        Array.prototype.push.apply(m.appear, newAppear);
+        Array.prototype.push.apply(m.vanish, newVanish);
       });
       });
+      V.UndoOnBoard(this.board, m);
     });
     return moves;
   }
     });
     return moves;
   }
@@ -175,12 +182,31 @@ export const VariantRules = class BenedictRules extends ChessRules {
     return [];
   }
 
     return [];
   }
 
+  // Stop at the first move found
+  atLeastOneMove() {
+    const color = this.turn;
+    const oppCol = V.GetOppCol(color);
+    for (let i = 0; i < V.size.x; i++) {
+      for (let j = 0; j < V.size.y; j++) {
+        if (this.board[i][j] != V.EMPTY && this.getColor(i, j) != oppCol) {
+          const moves = this.getPotentialMovesFrom([i, j]);
+          if (moves.length > 0)
+            return true;
+        }
+      }
+    }
+    return false;
+  }
+
   getCurrentScore() {
     const color = this.turn;
     // Did a king change color?
     const kp = this.kingPos[color];
     if (this.getColor(kp[0], kp[1]) != color)
       return color == "w" ? "0-1" : "1-0";
   getCurrentScore() {
     const color = this.turn;
     // Did a king change color?
     const kp = this.kingPos[color];
     if (this.getColor(kp[0], kp[1]) != color)
       return color == "w" ? "0-1" : "1-0";
-    return "*";
+    if (this.atLeastOneMove())
+      return "*";
+    // Stalemate:
+    return "1/2";
   }
 };
   }
 };