Add Swap, Switching, pawns variants
[vchess.git] / client / src / variants / Pawns.js
diff --git a/client/src/variants/Pawns.js b/client/src/variants/Pawns.js
new file mode 100644 (file)
index 0000000..83ccca7
--- /dev/null
@@ -0,0 +1,39 @@
+import { ChessRules } from "@/base_rules";
+
+export class PawnsRules extends ChessRules {
+  static get PawnSpecs() {
+    return Object.assign(
+      {},
+      ChessRules.PawnSpecs,
+      // The promotion piece doesn't matter, the game is won
+      { promotions: [V.QUEEN] }
+    );
+  }
+
+  static get HasFlags() {
+    return false;
+  }
+
+  static GenRandInitFen() {
+    return "8/pppppppp/8/8/8/8/PPPPPPPP/8 w 0 -";
+  }
+
+  filterValid(moves) {
+    return moves;
+  }
+
+  getCheckSquares() {
+    return [];
+  }
+
+  getCurrentScore() {
+    const oppCol = V.GetOppCol(this.turn);
+    if (this.board.some(b =>
+      b.some(cell => cell[0] == oppCol && cell[1] != V.PAWN))
+    ) {
+      return (oppCol == 'w' ? "1-0" : "0-1");
+    }
+    if (!this.atLeastOneMove()) return "1/2";
+    return "*";
+  }
+};