Teleport2 (no king repositioning) + do not relay some challenges
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 20 Mar 2021 17:00:30 +0000 (18:00 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 20 Mar 2021 17:00:30 +0000 (18:00 +0100)
16 files changed:
client/src/translations/en.js
client/src/translations/es.js
client/src/translations/fr.js
client/src/translations/rules/Teleport1/en.pug [moved from client/src/translations/rules/Teleport/en.pug with 99% similarity]
client/src/translations/rules/Teleport1/es.pug [moved from client/src/translations/rules/Teleport/es.pug with 94% similarity]
client/src/translations/rules/Teleport1/fr.pug [moved from client/src/translations/rules/Teleport/fr.pug with 99% similarity]
client/src/translations/rules/Teleport2/en.pug [new file with mode: 0644]
client/src/translations/rules/Teleport2/es.pug [new file with mode: 0644]
client/src/translations/rules/Teleport2/fr.pug [new file with mode: 0644]
client/src/translations/variants/en.pug
client/src/translations/variants/es.pug
client/src/translations/variants/fr.pug
client/src/variants/Teleport1.js [moved from client/src/variants/Teleport.js with 99% similarity]
client/src/variants/Teleport2.js [new file with mode: 0644]
server/db/populate.sql
server/sockets.js

index e3f361c..e93b434 100644 (file)
@@ -299,7 +299,8 @@ export const translations = {
   "Reach the last rank (v2)": "Reach the last rank (v2)",
   "Rearrange enemy pieces": "Rearrange enemy pieces",
   "Replace pieces": "Replace pieces",
   "Reach the last rank (v2)": "Reach the last rank (v2)",
   "Rearrange enemy pieces": "Rearrange enemy pieces",
   "Replace pieces": "Replace pieces",
-  "Reposition pieces": "Reposition pieces",
+  "Reposition pieces (v1)": "Reposition pieces (v1)",
+  "Reposition pieces (v2)": "Reposition pieces (v2)",
   "Reuse pieces": "Reuse pieces",
   "Reverse captures": "Reverse captures",
   "Roll the dice": "Roll the dice",
   "Reuse pieces": "Reuse pieces",
   "Reverse captures": "Reverse captures",
   "Roll the dice": "Roll the dice",
index 3869b5d..d776b26 100644 (file)
@@ -299,7 +299,8 @@ export const translations = {
   "Reach the last rank (v2)": "Llegar a la última fila (v2)",
   "Rearrange enemy pieces": "Reorganizar piezas opuestas",
   "Replace pieces": "Reemplazar piezas",
   "Reach the last rank (v2)": "Llegar a la última fila (v2)",
   "Rearrange enemy pieces": "Reorganizar piezas opuestas",
   "Replace pieces": "Reemplazar piezas",
-  "Reposition pieces": "Reposicionar las piezas",
+  "Reposition pieces (v1)": "Reposicionar las piezas (v1)",
+  "Reposition pieces (v2)": "Reposicionar las piezas (v2)",
   "Reuse pieces": "Reutilizar piezas",
   "Reverse captures": "Capturas invertidas",
   "Roll the dice": "Tirar los dados",
   "Reuse pieces": "Reutilizar piezas",
   "Reverse captures": "Capturas invertidas",
   "Roll the dice": "Tirar los dados",
index e75273a..4752d91 100644 (file)
@@ -299,7 +299,8 @@ export const translations = {
   "Reach the last rank (v2)": "Atteignez la dernière rangée (v2)",
   "Rearrange enemy pieces": "Réorganisez les pièces adverses",
   "Replace pieces": "Remplacer les pièces",
   "Reach the last rank (v2)": "Atteignez la dernière rangée (v2)",
   "Rearrange enemy pieces": "Réorganisez les pièces adverses",
   "Replace pieces": "Remplacer les pièces",
-  "Reposition pieces": "Replacer les pièces",
+  "Reposition pieces (v1)": "Replacer les pièces (v1)",
+  "Reposition pieces (v2)": "Replacer les pièces (v2)",
   "Reuse pieces": "Réutiliser les pièces",
   "Reverse captures": "Captures inversées",
   "Roll the dice": "Lancez le dé",
   "Reuse pieces": "Réutiliser les pièces",
   "Reverse captures": "Captures inversées",
   "Roll the dice": "Lancez le dé",
@@ -7,6 +7,8 @@ p.
   A king may remain under check while the move isn't complete.
   A repositioned piece can give checkmate.
   A pawn cannot be placed on the last rank.
   A king may remain under check while the move isn't complete.
   A repositioned piece can give checkmate.
   A pawn cannot be placed on the last rank.
+
+p.
   A king can reposition a piece or be repositioned,
   possibly to escape from a check.
 
   A king can reposition a piece or be repositioned,
   possibly to escape from a check.
 
@@ -8,7 +8,8 @@ p.
   Un rey puede quedarse en jaque durante esta acción.
   Una pieza movida en el tablero puede dar jaque mate.
   Un peón no se puede mover a la última fila.
   Un rey puede quedarse en jaque durante esta acción.
   Una pieza movida en el tablero puede dar jaque mate.
   Un peón no se puede mover a la última fila.
-  Un rey puede moverse y ser movido, incluso para evitar jaques.
+
+p Un rey puede moverse y ser movido, incluso para evitar jaques.
 
 figure.diagram-container
   .diagram.diag12
 
 figure.diagram-container
   .diagram.diag12
@@ -8,6 +8,8 @@ p.
   en échec durant cette action.
   Une pièce déplacée sur l'échiquier peut mater.
   Un pion ne peut pas être déplacé en dernière rangée.
   en échec durant cette action.
   Une pièce déplacée sur l'échiquier peut mater.
   Un pion ne peut pas être déplacé en dernière rangée.
+
+p.
   Un roi peut déplacer et être déplacé,
   y compris pour se soustraire à un échec.
 
   Un roi peut déplacer et être déplacé,
   y compris pour se soustraire à un échec.
 
diff --git a/client/src/translations/rules/Teleport2/en.pug b/client/src/translations/rules/Teleport2/en.pug
new file mode 100644 (file)
index 0000000..7f31849
--- /dev/null
@@ -0,0 +1,7 @@
+p.boxed.
+  You can capture your pieces to teleport them instead of a regular move.
+
+p
+  a(href="/#/variants/Teleport1") Teleport1
+  | , but the king cannot be repositioned.
+  | This removes some unusual defensive options.
diff --git a/client/src/translations/rules/Teleport2/es.pug b/client/src/translations/rules/Teleport2/es.pug
new file mode 100644 (file)
index 0000000..cdad5ae
--- /dev/null
@@ -0,0 +1,8 @@
+p.boxed.
+  Puedes capturar tus piezas para teletransportarlas en lugar de jugar
+  un movimiento normal.
+
+p
+  a(href="/#/variants/Teleport1") Teleport1
+  | , pero el rey no se puede reposicionar.
+  | Esto evita algunas posibilidades defensivas inusuales.
diff --git a/client/src/translations/rules/Teleport2/fr.pug b/client/src/translations/rules/Teleport2/fr.pug
new file mode 100644 (file)
index 0000000..4eb9ddc
--- /dev/null
@@ -0,0 +1,8 @@
+p.boxed.
+  Vous pouvez capturer vos pièces pour les téléporter au lieu de jouer
+  un coup normal.
+
+p
+  a(href="/#/variants/Teleport1") Teleport1
+  | , mais le roi ne peut pas être repositionné.
+  | Cela empêche quelques possibilités défensives inhabituelles.
index 15a8aa5..a6e5bd8 100644 (file)
@@ -324,7 +324,8 @@ p Pieces can be dropped on the board, either immediately or later in the game.
     "Rampage",
     "Recycle",
     "Shogun",
     "Rampage",
     "Recycle",
     "Shogun",
-    "Teleport"
+    "Teleport1",
+    "Teleport2"
   ]
 ul
   for v in varlist
   ]
 ul
   for v in varlist
index cc85500..2db4ef9 100644 (file)
@@ -333,7 +333,8 @@ p.
     "Rampage",
     "Recycle",
     "Shogun",
     "Rampage",
     "Recycle",
     "Shogun",
-    "Teleport"
+    "Teleport1",
+    "Teleport2"
   ]
 ul
   for v in varlist
   ]
 ul
   for v in varlist
index f23512e..ba52eca 100644 (file)
@@ -332,7 +332,8 @@ p.
     "Rampage",
     "Recycle",
     "Shogun",
     "Rampage",
     "Recycle",
     "Shogun",
-    "Teleport"
+    "Teleport1",
+    "Teleport2"
   ]
 ul
   for v in varlist
   ]
 ul
   for v in varlist
similarity index 99%
rename from client/src/variants/Teleport.js
rename to client/src/variants/Teleport1.js
index cbf6a78..faa503a 100644 (file)
@@ -201,7 +201,7 @@ export class TeleportRules extends ChessRules {
       this.kingPos[move.vanish[1].c] = [-1, -1];
     else if (move.appear[0].p == V.KING)
       this.kingPos[move.appear[0].c] = [move.appear[0].x, move.appear[0].y];
       this.kingPos[move.vanish[1].c] = [-1, -1];
     else if (move.appear[0].p == V.KING)
       this.kingPos[move.appear[0].c] = [move.appear[0].x, move.appear[0].y];
-    this.updateCastleFlags(move);
+    if (move.vanish.length > 0) this.updateCastleFlags(move);
   }
 
   // NOTE: no need to update if castleFlags already off
   }
 
   // NOTE: no need to update if castleFlags already off
diff --git a/client/src/variants/Teleport2.js b/client/src/variants/Teleport2.js
new file mode 100644 (file)
index 0000000..4e0fe23
--- /dev/null
@@ -0,0 +1,57 @@
+import { Teleport1Rules } from "@/variants/Teleport1";
+
+export class Teleport2Rules extends Teleport1Rules {
+
+  canTake([x1, y1], [x2, y2]) {
+    // Cannot teleport king:
+    return (this.subTurn == 1 && this.getPiece(x2, y2) != V.KING);
+  }
+
+  underCheck(color) {
+    // Standard method:
+    return this.isAttacked(this.kingPos[color], V.GetOppCol(color));
+  }
+
+  postPlay(move) {
+    if (move.vaish.length > 0) {
+      // Standard method:
+      if (move.appear[0].p == V.KING)
+        this.kingPos[move.appear[0].c] = [move.appear[0].x, move.appear[0].y];
+      this.updateCastleFlags(move);
+    }
+  }
+
+  updateCastleFlags(move) {
+    // Standard method: TODO = find a better way... (not rewriting)
+    const c = color || V.GetOppCol(this.turn);
+    const firstRank = (c == "w" ? V.size.x - 1 : 0);
+    const oppCol = this.turn;
+    const oppFirstRank = V.size.x - 1 - firstRank;
+    if (piece == V.KING && move.appear.length > 0)
+      this.castleFlags[c] = [V.size.y, V.size.y];
+    else if (
+      move.start.x == firstRank &&
+      this.castleFlags[c].includes(move.start.y)
+    ) {
+      const flagIdx = (move.start.y == this.castleFlags[c][0] ? 0 : 1);
+      this.castleFlags[c][flagIdx] = V.size.y;
+    }
+    if (
+      move.end.x == oppFirstRank &&
+      this.castleFlags[oppCol].includes(move.end.y)
+    ) {
+      const flagIdx = (move.end.y == this.castleFlags[oppCol][0] ? 0 : 1);
+      this.castleFlags[oppCol][flagIdx] = V.size.y;
+    }
+  }
+
+  postUndo(move) {
+    if (move.vanish.length > 0) {
+      // Standard method:
+      const c = this.getColor(move.start.x, move.start.y);
+      if (this.getPiece(move.start.x, move.start.y) == V.KING)
+        this.kingPos[c] = [move.start.x, move.start.y];
+    }
+  }
+
+};
index f9722f6..f0c87ed 100644 (file)
@@ -161,7 +161,8 @@ insert or ignore into Variants (name, description) values
   ('Switching', 'Exchange pieces'' positions'),
   ('Synochess', 'Dynasty versus Kingdom'),
   ('Takenmake', 'Prolongated captures'),
   ('Switching', 'Exchange pieces'' positions'),
   ('Synochess', 'Dynasty versus Kingdom'),
   ('Takenmake', 'Prolongated captures'),
-  ('Teleport', 'Reposition pieces'),
+  ('Teleport (v1)', 'Reposition pieces (v1)'),
+  ('Teleport (v2)', 'Reposition pieces (v2)'),
   ('Tencubed', 'Four new pieces'),
   ('Threechecks', 'Give three checks'),
   ('Titan', 'Extra bishops and knights'),
   ('Tencubed', 'Four new pieces'),
   ('Threechecks', 'Give three checks'),
   ('Titan', 'Extra bishops and knights'),
index 88cc2f2..4a61f68 100644 (file)
@@ -219,10 +219,19 @@ module.exports = function(wss) {
           // "newgame" message can provide a page (corr Game --> Hall)
           notifyRoom(
             obj.page || page, obj.code, {data: obj.data}, obj.excluded);
           // "newgame" message can provide a page (corr Game --> Hall)
           notifyRoom(
             obj.page || page, obj.code, {data: obj.data}, obj.excluded);
-          if (!!discordChannel && obj.code == "newchallenge") {
-            discordChannel.send("New challenge: **" +
-              obj.data.vname +
-              "** [" + obj.data.cadence + "]");
+          if (
+            obj.code == "newchallenge" &&
+            !obj.data.to && //filter out targeted challenges
+            obj.data.cadence.indexOf('d') < 0 //and correspondance games
+          ) {
+            const challMsg = (
+              "New challenge: **" + obj.data.vname + "** " +
+              "[" + obj.data.cadence + "]"
+            );
+            if (!!discordChannel) discordChannel.send(challMsg);
+            else
+              // Log when running locally (dev, debug):
+              console.log(challMsg);
           }
           break;
 
           }
           break;