Better behavior in Dynamo. Some image attributions in rules
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 25 Jan 2021 22:49:05 +0000 (23:49 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 25 Jan 2021 22:49:05 +0000 (23:49 +0100)
client/src/translations/rules/Bario/en.pug
client/src/translations/rules/Bario/es.pug
client/src/translations/rules/Bario/fr.pug
client/src/translations/rules/Dynamo/en.pug
client/src/translations/rules/Dynamo/es.pug
client/src/translations/rules/Dynamo/fr.pug
client/src/translations/rules/Emergo/en.pug
client/src/translations/rules/Emergo/es.pug
client/src/translations/rules/Emergo/fr.pug
client/src/variants/Dynamo.js

index fc93a66..6c8508c 100644 (file)
@@ -13,7 +13,9 @@ p
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
-  figcaption.text-center Undefined pieces on first ranks.
+  figcaption.text-center.
+    [From author's website with his permission]
+    Undefined pieces on first ranks.
 
 p.
   Queens, rooks, bishops and knights begin the game in a reserve below
 
 p.
   Queens, rooks, bishops and knights begin the game in a reserve below
index 65334fc..710979c 100644 (file)
@@ -13,7 +13,9 @@ p
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
-  figcaption.text-center Piezas no definidas en las primeras filas.
+  figcaption.text-center.
+    [Del sitio del autor, con su permiso]
+    Piezas no definidas en las primeras filas.
 
 p.
   Damas, torres, alfiles y caballos comienzan el juego en una reserva bajo
 
 p.
   Damas, torres, alfiles y caballos comienzan el juego en una reserva bajo
index bfae7c2..f2d1896 100644 (file)
@@ -13,7 +13,9 @@ p
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
 
 figure
   img.img-center(src="/variants/Bario/chessboard.png")
-  figcaption.text-center Pièces indéfinies sur les premières rangées.
+  figcaption.text-center.
+    [Depuis le site de l'auteur, avec sa permission]
+    Pièces indéfinies sur les premières rangées.
 
 p.
   Dames, tours, fous et cavaliers commencent la partie dans une réserve sous
 
 p.
   Dames, tours, fous et cavaliers commencent la partie dans une réserve sous
index ac4263c..874ae27 100644 (file)
@@ -38,8 +38,8 @@ p.
   bishop or the queen.
 
 p.
   bishop or the queen.
 
 p.
-  Note: if you don't want to play a second part in a move, just click on any
-  empty square: this will replace the second part by an empty move.
+  Note: if an action is possible but you don't want to play a second part in
+  a move, click on any empty square: this will send an empty move.
 
 figure.diagram-container
   .diagram.diag12
 
 figure.diagram-container
   .diagram.diag12
index e7843ce..b28e32a 100644 (file)
@@ -38,8 +38,8 @@ p.
   empujado afuera por el alfil o la dama.
 
 p.
   empujado afuera por el alfil o la dama.
 
 p.
-  Nota: si no desea ejecutar un segundo movimiento, haga clic simplemente en un
-  cuadrado vacío: esto reemplazará la segunda parte con un movimiento vacío.
+  Nota: si una acción es posible pero no desea ejecutar una segunda parte del
+  movimiento, haga clic en un cuadrado vacío: esto enviará una jugada vacía.
 
 figure.diagram-container
   .diagram.diag12
 
 figure.diagram-container
   .diagram.diag12
index a31d514..ea254bc 100644 (file)
@@ -38,9 +38,9 @@ p.
   poussé en dehors par le fou ou la dame.
 
 p.
   poussé en dehors par le fou ou la dame.
 
 p.
-  Note : si vous ne voulez pas exécuter une seconde partie de coup, cliquez
-  simplement sur une case vide : cela remplacera la seconde partie par un coup
-  vide.
+  Note : si une action est possible mais vous ne voulez pas exécuter une
+  seconde partie de coup, cliquez sur une case vide :
+  cela enverra un coup vide.
 
 figure.diagram-container
   .diagram.diag12
 
 figure.diagram-container
   .diagram.diag12
index 492ceef..25397c0 100644 (file)
@@ -4,6 +4,7 @@ p.boxed
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
+    [Wikipedia]
     Game played on an orthogonal depiction of a standard 9x9 Emergo board.
 
 p
     Game played on an orthogonal depiction of a standard 9x9 Emergo board.
 
 p
index 7388479..37191bc 100644 (file)
@@ -4,6 +4,7 @@ p.boxed
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
+    [Wikipedia]
     Juego jugado en una representación ortogonal
     de un tablero de Emergo estándar 9x9.
 
     Juego jugado en una representación ortogonal
     de un tablero de Emergo estándar 9x9.
 
index 22f30f7..52f3d7f 100644 (file)
@@ -4,6 +4,7 @@ p.boxed
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
 figure.diagram-container
   img.img-center(src="/variants/Emergo/match_2004_U-con.jpg")
   figcaption.text-center.
+    [Wikipedia]
     Partie jouée sur une représentation orthogonale
     d'un plateau d'Emergo standard 9x9.
 
     Partie jouée sur une représentation orthogonale
     d'un plateau d'Emergo standard 9x9.
 
index 35c41c5..9b29e3c 100644 (file)
@@ -739,6 +739,15 @@ export class DynamoRules extends ChessRules {
     return potentialMoves;
   }
 
     return potentialMoves;
   }
 
+  getEmptyMove() {
+    return new Move({
+      start: { x: -1, y: -1 },
+      end: { x: -1, y: -1 },
+      appear: [],
+      vanish: []
+    });
+  }
+
   doClick(square) {
     // A click to promote a piece on subTurn 2 would trigger this.
     // For now it would then return [NaN, NaN] because surrounding squares
   doClick(square) {
     // A click to promote a piece on subTurn 2 would trigger this.
     // For now it would then return [NaN, NaN] because surrounding squares
@@ -754,36 +763,55 @@ export class DynamoRules extends ChessRules {
       !this.underCheck(this.turn) &&
       (La == 0 || !this.oppositeMoves(this.amoves[La-1], this.firstMove[Lf-1]))
     ) {
       !this.underCheck(this.turn) &&
       (La == 0 || !this.oppositeMoves(this.amoves[La-1], this.firstMove[Lf-1]))
     ) {
-      return {
-        start: { x: -1, y: -1 },
-        end: { x: -1, y: -1 },
-        appear: [],
-        vanish: []
-      };
+      return this.getEmptyMove();
     }
     return null;
   }
 
   play(move) {
     }
     return null;
   }
 
   play(move) {
-    move.flags = JSON.stringify(this.aggregateFlags());
-    V.PlayOnBoard(this.board, move);
-    // NOTE; if subTurn == 1, there may be no available moves at subTurn == 2.
-    // However, it's quite easier to wait for a user click.
-    if (this.subTurn == 2) {
+    const color = this.turn;
+    move.subTurn = this.subTurn; //for undo
+    const gotoNext = (mv) => {
       const L = this.firstMove.length;
       const L = this.firstMove.length;
-      this.amoves.push(this.getAmove(this.firstMove[L-1], move));
-      this.turn = V.GetOppCol(this.turn);
+      this.amoves.push(this.getAmove(this.firstMove[L-1], mv));
+      this.turn = V.GetOppCol(color);
+      this.subTurn = 1;
       this.movesCount++;
       this.movesCount++;
+    };
+    move.flags = JSON.stringify(this.aggregateFlags());
+    V.PlayOnBoard(this.board, move);
+    if (this.subTurn == 2) gotoNext(move);
+    else {
+      this.subTurn = 2;
+      this.firstMove.push(move);
+      this.toNewKingPos(move);
+      if (
+        // Condition is true on empty arrays:
+        this.getAllPotentialMoves().every(m => {
+          V.PlayOnBoard(this.board, m);
+          this.toNewKingPos(m);
+          const res = this.underCheck(color);
+          V.UndoOnBoard(this.board, m);
+          this.toOldKingPos(m);
+          return res;
+        })
+      ) {
+        // No valid move at subTurn 2
+        gotoNext(this.getEmptyMove());
+      }
+      this.toOldKingPos(move);
     }
     }
-    else this.firstMove.push(move);
-    this.subTurn = 3 - this.subTurn;
     this.postPlay(move);
   }
 
     this.postPlay(move);
   }
 
-  postPlay(move) {
-    if (move.start.x < 0) return;
+  toNewKingPos(move) {
     for (let a of move.appear)
       if (a.p == V.KING) this.kingPos[a.c] = [a.x, a.y];
     for (let a of move.appear)
       if (a.p == V.KING) this.kingPos[a.c] = [a.x, a.y];
+  }
+
+  postPlay(move) {
+    if (move.start.x < 0) return;
+    this.toNewKingPos(move);
     this.updateCastleFlags(move);
   }
 
     this.updateCastleFlags(move);
   }
 
@@ -806,12 +834,12 @@ export class DynamoRules extends ChessRules {
       this.turn = V.GetOppCol(this.turn);
       this.movesCount--;
     }
       this.turn = V.GetOppCol(this.turn);
       this.movesCount--;
     }
-    else this.firstMove.pop();
-    this.subTurn = 3 - this.subTurn;
-    this.postUndo(move);
+    if (move.subTurn == 1) this.firstMove.pop();
+    this.subTurn = move.subTurn;
+    this.toOldKingPos(move);
   }
 
   }
 
-  postUndo(move) {
+  toOldKingPos(move) {
     // (Potentially) Reset king position
     for (let v of move.vanish)
       if (v.p == V.KING) this.kingPos[v.c] = [v.x, v.y];
     // (Potentially) Reset king position
     for (let v of move.vanish)
       if (v.p == V.KING) this.kingPos[v.c] = [v.x, v.y];