From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 16 Feb 2021 21:55:04 +0000 (+0100)
Subject: Fix Pandemonium computer play
X-Git-Url: https://git.auder.net/variants/img/pieces/css/doc/pieces/cq.svg?a=commitdiff_plain;h=1220a5b9053097b2eae90ee69d1b39d46ba00d52;p=vchess.git

Fix Pandemonium computer play
---

diff --git a/client/src/variants/Pandemonium.js b/client/src/variants/Pandemonium.js
index 34dc77e1..7795a7b1 100644
--- a/client/src/variants/Pandemonium.js
+++ b/client/src/variants/Pandemonium.js
@@ -585,11 +585,13 @@ export class PandemoniumRules extends ChessRules {
 
   getAllValidMoves() {
     let moves = super.getAllPotentialMoves();
-    const color = this.turn;
-    for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
-      moves = moves.concat(
-        this.getReserveMoves([V.size.x + (color == "w" ? 0 : 1), i])
-      );
+    if (this.movesCount >= 2) {
+      const color = this.turn;
+      for (let i = 0; i < V.RESERVE_PIECES.length; i++) {
+        moves = moves.concat(
+          this.getReserveMoves([V.size.x + (color == "w" ? 0 : 1), i])
+        );
+      }
     }
     return this.filterValid(moves);
   }
@@ -656,7 +658,7 @@ export class PandemoniumRules extends ChessRules {
     if (move.vanish.length == 0)
       // Drop unpromoted piece:
       this.reserve[color][move.appear[0].p]--;
-    else if (move.vanish.length == 2)
+    else if (move.vanish.length == 2 && move.appear.length == 1)
       // May capture a promoted piece:
       this.reserve[color][V.MayDecode(move.vanish[1].p)]++;
   }
@@ -679,7 +681,7 @@ export class PandemoniumRules extends ChessRules {
     const color = move.appear[0].c;
     if (move.vanish.length == 0)
       this.reserve[color][move.appear[0].p]++;
-    else if (move.vanish.length == 2)
+    else if (move.vanish.length == 2 && move.appear.length == 1)
       this.reserve[color][V.MayDecode(move.vanish[1].p)]--;
   }