Better Schess notation when introducing pieces while castling
[vchess.git] / client / src / variants / Schess.js
index 06644c7..d8e1b1c 100644 (file)
@@ -1,6 +1,7 @@
 import { ChessRules, PiPo } from "@/base_rules";
 
 export class SchessRules extends ChessRules {
+
   static get PawnSpecs() {
     return Object.assign(
       {},
@@ -119,12 +120,12 @@ export class SchessRules extends ChessRules {
     const fenParsed = V.ParseFen(fen);
     this.pocket = {
       "w": {
-        h: parseInt(fenParsed.pocket[0]),
-        e: parseInt(fenParsed.pocket[1])
+        h: parseInt(fenParsed.pocket[0], 10),
+        e: parseInt(fenParsed.pocket[1], 10)
       },
       "b": {
-        h: parseInt(fenParsed.pocket[2]),
-        e: parseInt(fenParsed.pocket[3])
+        h: parseInt(fenParsed.pocket[2], 10),
+        e: parseInt(fenParsed.pocket[3], 10)
       }
     };
   }
@@ -341,7 +342,14 @@ export class SchessRules extends ChessRules {
       const nothingAppear = (move.appear[0].p == V.NOTHING);
       if (pPieceAppear || nothingAppear) {
         let suffix = "";
-        if (pPieceAppear) suffix = "/" + move.appear[0].p.toUpperCase();
+        if (pPieceAppear) {
+          suffix = "/" + move.appear[0].p.toUpperCase();
+          if (move.appear.length == 3) {
+            // Castling; indicate square
+            suffix +=
+              V.CoordsToSquare({ x: move.appear[0].x, y: move.appear[0].y });
+          }
+        }
         let cmove = JSON.parse(JSON.stringify(move));
         cmove.appear.shift();
         return super.getNotation(cmove) + suffix;
@@ -349,4 +357,5 @@ export class SchessRules extends ChessRules {
     }
     return super.getNotation(move);
   }
+
 };