Pandemonium: promotion on last 2 ranks
[vchess.git] / client / src / variants / Pandemonium.js
index 963ee8d..4894ec1 100644 (file)
@@ -4,14 +4,6 @@ import { ArrayFun } from "@/utils/array";
 
 export class PandemoniumRules extends ChessRules {
 
-  static get PawnSpecs() {
-    return Object.assign(
-      {},
-      ChessRules.PawnSpecs,
-      { promotions: [V.GILDING] }
-    );
-  }
-
   loseOnRepetition() {
     // If current side is under check: lost
     return this.underCheck(this.turn);
@@ -216,7 +208,7 @@ export class PandemoniumRules extends ChessRules {
       pieces["b"].join("") +
       "/pppppppppp/91/91/91/91/91/91/PPPPPPPPPP/" +
       pieces["w"].join("").toUpperCase() +
-      " w 0 " + flags + " -"
+      " w 0 " + flags + " - 00000000000000"
     );
   }
 
@@ -414,10 +406,10 @@ export class PandemoniumRules extends ChessRules {
     // Maybe apply promotions:
     if (Object.keys(V.PromoteMap).includes(p)) {
       const promoted = V.PromoteMap[p];
-      const lastRank = (c == 'w' ? 0 : 9);
+      const lastRanks = (c == 'w' ? [0, 1] : [9, 8]);
       let promotions = [];
       moves.forEach(m => {
-        if (m.start.x == lastRank || m.end.x == lastRank) {
+        if (lastRanks.includes(m.start.x) || lastRanks.includes(m.end.x)) {
           let pMove = JSON.parse(JSON.stringify(m));
           pMove.appear[0].p = promoted;
           promotions.push(pMove);
@@ -428,6 +420,21 @@ export class PandemoniumRules extends ChessRules {
     return moves;
   }
 
+  addPawnMoves([x1, y1], [x2, y2], moves) {
+    const color = this.turn;
+    const lastRanks = (color == "w" ? [0, 1] : [9, 8]);
+    if (!lastRanks.includes(x2)) {
+      moves.push(this.getBasicMove([x1, y1], [x2, y2]));
+      return;
+    }
+    let finalPieces = [V.GILDING];
+    if (x2 == lastRanks[1]) finalPieces.push(V.PAWN);
+    for (let piece of finalPieces) {
+      const tr = (piece != V.PAWN ? { c: color, p: piece } : null);
+      moves.push(this.getBasicMove([x1, y1], [x2, y2], tr));
+    }
+  }
+
   getPotentialPawnMoves([x, y]) {
     const color = this.turn;
     const shiftX = (color == 'w' ? -1 : 1);
@@ -590,7 +597,7 @@ export class PandemoniumRules extends ChessRules {
 
   isAttackedByHorse(sq, color) {
     return (
-      super.isAttackedBySlideNJump(sq, color, V.steps[V.BISHOP], V.HORSE) ||
+      super.isAttackedBySlideNJump(sq, color, V.HORSE, V.steps[V.BISHOP]) ||
       super.isAttackedBySlideNJump(
         sq, color, V.HORSE, V.steps[V.ROOK], "oneStep")
     );
@@ -598,7 +605,7 @@ export class PandemoniumRules extends ChessRules {
 
   isAttackedByDragon(sq, color) {
     return (
-      super.isAttackedBySlideNJump(sq, color, V.steps[V.ROOK], V.DRAGON) ||
+      super.isAttackedBySlideNJump(sq, color, V.DRAGON, V.steps[V.ROOK]) ||
       super.isAttackedBySlideNJump(
         sq, color, V.DRAGON, V.steps[V.BISHOP], "oneStep")
     );