Fix Pandemonium pieces' values
[vchess.git] / client / src / variants / Pandemonium.js
index 34dc77e..dae0886 100644 (file)
@@ -287,8 +287,12 @@ export class PandemoniumRules extends ChessRules {
       const firstRank = (this.movesCount == 0 ? 9 : 0);
       // TODO: initDestFile currently hardcoded for deterministic setup
       const initDestFile = new Map([[1, 2], [8, 7]]);
-      // Only option is knight / bishop swap:
-      if (x == firstRank && !!initDestFile.get(y)) {
+      // Only option is knight --> bishop swap:
+      if (
+        x == firstRank &&
+        !!initDestFile.get(y) &&
+        this.getPiece(x, y) == V.KNIGHT
+      ) {
         const destFile = initDestFile.get(y);
         return [
           new Move({
@@ -585,11 +589,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 +662,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 +685,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)]--;
   }
 
@@ -716,7 +722,10 @@ export class PandemoniumRules extends ChessRules {
 
   static get VALUES() {
     return Object.assign(
+      {},
+      ChessRules.VALUES,
       {
+        n: 2.5, //knight is weaker
         g: 9,
         s: 5,
         h: 6,
@@ -725,8 +734,7 @@ export class PandemoniumRules extends ChessRules {
         w: 9,
         m: 8,
         a: 9
-      },
-      ChessRules.VALUES
+      }
     );
   }