Add Rugby variant
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 18 Mar 2020 09:45:10 +0000 (10:45 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 18 Mar 2020 09:45:10 +0000 (10:45 +0100)
TODO
client/src/translations/en.js
client/src/translations/es.js
client/src/translations/fr.js
client/src/translations/rules/Rugby/en.pug [new file with mode: 0644]
client/src/translations/rules/Rugby/es.pug [new file with mode: 0644]
client/src/translations/rules/Rugby/fr.pug [new file with mode: 0644]
client/src/variants/Rugby.js [new file with mode: 0644]
server/db/populate.sql

diff --git a/TODO b/TODO
index 094de49..1fd349b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,16 +1,9 @@
-# Improvements
-
-Find a way to generalize getCastleMoves and getPotentialPawnMoves,
-to limit code duplication.
-
 # New variants
 Landing pieces from empty board:
 https://www.chessvariants.com/diffsetup.dir/unachess.html
 
 Rugby http://www.echecspourtous.com/?page_id=7945
 
 # New variants
 Landing pieces from empty board:
 https://www.chessvariants.com/diffsetup.dir/unachess.html
 
 Rugby http://www.echecspourtous.com/?page_id=7945
 
-Cannibal Chess with forced captures.
-
 S-chess https://en.wikipedia.org/wiki/Seirawan_chess
 
 Generator variant, called "Matrix" ?
 S-chess https://en.wikipedia.org/wiki/Seirawan_chess
 
 Generator variant, called "Matrix" ?
index c0c95a2..328f089 100644 (file)
@@ -195,5 +195,6 @@ export const translations = {
   "Shoot pieces": "Shoot pieces",
   "Squares disappear": "Squares disappear",
   "Standard rules": "Standard rules",
   "Shoot pieces": "Shoot pieces",
   "Squares disappear": "Squares disappear",
   "Standard rules": "Standard rules",
+  "Transform an essay": "Transform an essay",
   "Unidentified pieces": "Unidentified pieces"
 };
   "Unidentified pieces": "Unidentified pieces"
 };
index c9f30e9..78c0b05 100644 (file)
@@ -195,5 +195,6 @@ export const translations = {
   "Shoot pieces": "Tirar de las piezas",
   "Squares disappear": "Las casillas desaparecen",
   "Standard rules": "Reglas estandar",
   "Shoot pieces": "Tirar de las piezas",
   "Squares disappear": "Las casillas desaparecen",
   "Standard rules": "Reglas estandar",
+  "Transform an essay": "Transformar un ensayo",
   "Unidentified pieces": "Piezas no identificadas"
 };
   "Unidentified pieces": "Piezas no identificadas"
 };
index b02969f..8c78295 100644 (file)
@@ -195,5 +195,6 @@ export const translations = {
   "Shoot pieces": "Tirez sur les pièces",
   "Squares disappear": "Les cases disparaissent",
   "Standard rules": "Règles usuelles",
   "Shoot pieces": "Tirez sur les pièces",
   "Squares disappear": "Les cases disparaissent",
   "Standard rules": "Règles usuelles",
+  "Transform an essay": "Transformer un essai",
   "Unidentified pieces": "Pièces non identifiées"
 };
   "Unidentified pieces": "Pièces non identifiées"
 };
diff --git a/client/src/translations/rules/Rugby/en.pug b/client/src/translations/rules/Rugby/en.pug
new file mode 100644 (file)
index 0000000..7bfe485
--- /dev/null
@@ -0,0 +1,18 @@
+p.boxed
+  | Only pawns. The first who crosses the board wins.
+
+p.
+  Pawns are given extra abilities: they can also move (but not capture)
+  like a king. The goal is to bring a pawn on the last rank.
+
+figure.diagram-container
+  .diagram
+    | fen:pppppppp/8/8/8/8/8/8/PPPPPPPP:
+  figcaption Initial position.
+
+h3 Source
+
+p
+  | I've read about this rule on 
+  a(href="http://www.echecspourtous.com/?page_id=7945") this page
+  | &nbsp;on (in French). It seems interesting :)
diff --git a/client/src/translations/rules/Rugby/es.pug b/client/src/translations/rules/Rugby/es.pug
new file mode 100644 (file)
index 0000000..cf35eba
--- /dev/null
@@ -0,0 +1,18 @@
+p.boxed
+  | Solo peones. El primer jugador que cruza el tablero gana.
+
+p.
+  Los peones ven aumentar sus poderes: también pueden moverse
+  (pero no capturar) como el rey. El objetivo es traer un peón al última fila.
+
+figure.diagram-container
+  .diagram
+    | fen:pppppppp/8/8/8/8/8/8/PPPPPPPPP:
+  figcaption Posición inicial.
+
+h3 Fuente
+
+p
+  | Descubrí esta regla en
+  a(href="http://www.echecspourtous.com/?page_id=7945") esta página
+  | &nbsp;(en francés). Se ve interesante :)
diff --git a/client/src/translations/rules/Rugby/fr.pug b/client/src/translations/rules/Rugby/fr.pug
new file mode 100644 (file)
index 0000000..16f3a81
--- /dev/null
@@ -0,0 +1,19 @@
+p.boxed
+  | Seulement des pions. Le premier qui traverse l'échiquier gagne.
+
+p.
+  Les pions voient leurs pouvoirs augmenter : ils peuvent aussi se déplacer
+  (mais pas capturer) comme des rois. L'objectif est d'amener un pion sur la
+  dernière rangée.
+
+figure.diagram-container
+  .diagram
+    | fen:pppppppp/8/8/8/8/8/8/PPPPPPPP:
+  figcaption Position initiale.
+
+h3 Source
+
+p
+  | J'ai découvert cette règle sur 
+  a(href="http://www.echecspourtous.com/?page_id=7945") cette page
+  | . Elle semble intéressante :)
diff --git a/client/src/variants/Rugby.js b/client/src/variants/Rugby.js
new file mode 100644 (file)
index 0000000..04306c2
--- /dev/null
@@ -0,0 +1,58 @@
+import { ChessRules } from "@/base_rules";
+import { ArrayFun } from "@/utils/array";
+
+export class RugbyRules extends ChessRules {
+  static get HasFlags() {
+    return false;
+  }
+
+  static get PawnSpecs() {
+    return Object.assign(
+      {},
+      ChessRules.PawnSpecs,
+      { promotions: [V.PAWN] }
+    );
+  }
+
+  getPotentialMovesFrom(sq) {
+    // There are only pawns:
+    return this.getPotentialPawnMoves(sq);
+  }
+
+  getPotentialPawnMoves(sq) {
+    const moves = super.getPotentialPawnMoves(sq);
+    // Add king movements, without capturing
+    const steps =
+      this.turn == 'w'
+        ? [ [-1,-1], [-1,1], [0,1], [0,-1], [1,-1], [1,0], [1,1] ]
+        : [ [1,-1], [1,1], [0,1], [0,-1], [-1,-1], [-1,0], [-1,1] ];
+    let addMoves = this.getSlideNJumpMoves(sq, steps, "oneStep");
+    return moves.concat(addMoves.filter(m => m.vanish.length == 1));
+  }
+
+  static GenRandInitFen() {
+    // Non-randomized variant. En-passant possible:
+    return "pppppppp/8/8/8/8/8/8/PPPPPPPP w 0 -";
+  }
+
+  filterValid(moves) {
+    return moves;
+  }
+
+  prePlay() {}
+  postPlay() {}
+  preUndo() {}
+  postUndo() {}
+
+  getCurrentScore() {
+    // Turn has changed:
+    const color = V.GetOppCol(this.turn);
+    const lastRank = (color == "w" ? 0 : V.size.x - 1);
+    if (ArrayFun.range(8).some(i => this.getColor(lastRank, i) == color))
+      // The opposing edge is reached!
+      return color == "w" ? "1-0" : "0-1";
+    if (this.atLeastOneMove()) return "*";
+    // Stalemate (will probably never happen)
+    return "1/2";
+  }
+};
index a192106..cee2970 100644 (file)
@@ -35,8 +35,9 @@ insert or ignore into Variants (name,description) values
   ('Marseille', 'Move twice'),
   ('Racingkings', 'Kings cross the 8x8 board'),
   ('Rifle', 'Shoot pieces'),
   ('Marseille', 'Move twice'),
   ('Racingkings', 'Kings cross the 8x8 board'),
   ('Rifle', 'Shoot pieces'),
-  ('Royalrace', 'Kings cross the 11x11 board'),
   ('Recycle', 'Reuse pieces'),
   ('Recycle', 'Reuse pieces'),
+  ('Royalrace', 'Kings cross the 11x11 board'),
+  ('Rugby', 'Score a try'),
   ('Shatranj', 'Ancient rules'),
   ('Suicide', 'Lose all pieces'),
   ('Suction', 'Attract opposite king'),
   ('Shatranj', 'Ancient rules'),
   ('Suicide', 'Lose all pieces'),
   ('Suction', 'Attract opposite king'),