Fix Pandemonium updateCastleFlags()
[vchess.git] / client / src / variants / Pandemonium.js
index 7795a7b..287aa3b 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({
@@ -644,7 +648,7 @@ export class PandemoniumRules extends ChessRules {
   }
 
   updateCastleFlags(move, piece) {
-    if (move.appear.length == 2) {
+    if (piece == V.KING && move.appear.length == 2) {
       // Castling (only move which disable flags)
       this.castleFlags[move.appear[0].c][0] = 10;
       this.castleFlags[move.appear[0].c][1] = 10;
@@ -718,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,
@@ -727,8 +734,7 @@ export class PandemoniumRules extends ChessRules {
         w: 9,
         m: 8,
         a: 9
-      },
-      ChessRules.VALUES
+      }
     );
   }