Fix Jangqi + Xiangqi moves' notation
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 1 Jan 2021 01:42:18 +0000 (02:42 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 1 Jan 2021 01:42:18 +0000 (02:42 +0100)
client/src/variants/Jangqi.js
client/src/variants/Xiangqi.js

index 154fa32..14204d8 100644 (file)
@@ -62,19 +62,6 @@ export class JangqiRules extends ChessRules {
     return { x: 10, y: 9};
   }
 
-  getPotentialMovesFrom(sq) {
-    switch (this.getPiece(sq[0], sq[1])) {
-      case V.PAWN: return this.getPotentialPawnMoves(sq);
-      case V.ROOK: return this.getPotentialRookMoves(sq);
-      case V.KNIGHT: return this.getPotentialKnightMoves(sq);
-      case V.ELEPHANT: return this.getPotentialElephantMoves(sq);
-      case V.ADVISOR: return this.getPotentialAdvisorMoves(sq);
-      case V.KING: return this.getPotentialKingMoves(sq);
-      case V.CANNON: return this.getPotentialCannonMoves(sq);
-    }
-    return []; //never reached
-  }
-
   static IsGoodFlags(flags) {
     // bikjang status of last move + pass
     return !!flags.match(/^[0-2]{2,2}$/);
@@ -161,8 +148,33 @@ export class JangqiRules extends ChessRules {
         );
       }
     }
-    else
-      Array.prototype.push.apply(moves, super.getPotentialMovesFrom([x, y]));
+    else {
+      let normalMoves = [];
+      switch (this.getPiece(x, y)) {
+        case V.PAWN:
+          normalMoves = this.getPotentialPawnMoves([x, y]);
+          break;
+        case V.ROOK:
+          normalMoves = this.getPotentialRookMoves([x, y]);
+          break;
+        case V.KNIGHT:
+          normalMoves = this.getPotentialKnightMoves([x, y]);
+          break;
+        case V.ELEPHANT:
+          normalMoves = this.getPotentialElephantMoves([x, y]);
+          break;
+        case V.ADVISOR:
+          normalMoves = this.getPotentialAdvisorMoves([x, y]);
+          break;
+        case V.KING:
+          normalMoves = this.getPotentialKingMoves([x, y]);
+          break;
+        case V.CANNON:
+          normalMoves = this.getPotentialCannonMoves([x, y]);
+          break;
+      }
+      Array.prototype.push.apply(moves, normalMoves);
+    }
     return moves;
   }
 
index b302433..6215ea9 100644 (file)
@@ -395,7 +395,7 @@ export class XiangqiRules extends ChessRules {
   getNotation(move) {
     let notation = super.getNotation(move);
     if (move.vanish.length == 2 && move.vanish[0].p == V.PAWN)
-      notation = "P" + substr(notation, 1);
+      notation = "P" + notation.substr(1);
     return notation;
   }