From 84ac89c2fe7f191a9c19e23750b7fa705d44961b Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Fri, 1 Jan 2021 02:42:18 +0100
Subject: [PATCH] Fix Jangqi + Xiangqi moves' notation

---
 client/src/variants/Jangqi.js  | 42 ++++++++++++++++++++++------------
 client/src/variants/Xiangqi.js |  2 +-
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/client/src/variants/Jangqi.js b/client/src/variants/Jangqi.js
index 154fa325..14204d88 100644
--- a/client/src/variants/Jangqi.js
+++ b/client/src/variants/Jangqi.js
@@ -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;
   }
 
diff --git a/client/src/variants/Xiangqi.js b/client/src/variants/Xiangqi.js
index b3024332..6215ea9b 100644
--- a/client/src/variants/Xiangqi.js
+++ b/client/src/variants/Xiangqi.js
@@ -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;
   }
 
-- 
2.44.0