From: Benjamin Auder Date: Wed, 18 Mar 2020 09:45:10 +0000 (+0100) Subject: Add Rugby variant X-Git-Url: https://git.auder.net/variants/img/pieces/doc/doc/html/left.jpg?a=commitdiff_plain;h=7769191167d394c3b52625dae62b4af93803d656;p=vchess.git Add Rugby variant --- diff --git a/TODO b/TODO index 094de496..1fd349b8 100644 --- 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 -Cannibal Chess with forced captures. - S-chess https://en.wikipedia.org/wiki/Seirawan_chess Generator variant, called "Matrix" ? diff --git a/client/src/translations/en.js b/client/src/translations/en.js index c0c95a29..328f0895 100644 --- a/client/src/translations/en.js +++ b/client/src/translations/en.js @@ -195,5 +195,6 @@ export const translations = { "Shoot pieces": "Shoot pieces", "Squares disappear": "Squares disappear", "Standard rules": "Standard rules", + "Transform an essay": "Transform an essay", "Unidentified pieces": "Unidentified pieces" }; diff --git a/client/src/translations/es.js b/client/src/translations/es.js index c9f30e93..78c0b054 100644 --- a/client/src/translations/es.js +++ b/client/src/translations/es.js @@ -195,5 +195,6 @@ export const translations = { "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" }; diff --git a/client/src/translations/fr.js b/client/src/translations/fr.js index b02969f8..8c782953 100644 --- a/client/src/translations/fr.js +++ b/client/src/translations/fr.js @@ -195,5 +195,6 @@ export const translations = { "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" }; diff --git a/client/src/translations/rules/Rugby/en.pug b/client/src/translations/rules/Rugby/en.pug new file mode 100644 index 00000000..7bfe4852 --- /dev/null +++ b/client/src/translations/rules/Rugby/en.pug @@ -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 + |  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 index 00000000..cf35eba0 --- /dev/null +++ b/client/src/translations/rules/Rugby/es.pug @@ -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 + |  (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 index 00000000..16f3a811 --- /dev/null +++ b/client/src/translations/rules/Rugby/fr.pug @@ -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 index 00000000..04306c26 --- /dev/null +++ b/client/src/variants/Rugby.js @@ -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"; + } +}; diff --git a/server/db/populate.sql b/server/db/populate.sql index a1921062..cee29708 100644 --- a/server/db/populate.sql +++ b/server/db/populate.sql @@ -35,8 +35,9 @@ insert or ignore into Variants (name,description) values ('Marseille', 'Move twice'), ('Racingkings', 'Kings cross the 8x8 board'), ('Rifle', 'Shoot pieces'), - ('Royalrace', 'Kings cross the 11x11 board'), ('Recycle', 'Reuse pieces'), + ('Royalrace', 'Kings cross the 11x11 board'), + ('Rugby', 'Score a try'), ('Shatranj', 'Ancient rules'), ('Suicide', 'Lose all pieces'), ('Suction', 'Attract opposite king'),