Fix Berolina notation + Marseille PGN
[vchess.git] / public / javascripts / base_rules.js
index ba77d71..891948b 100644 (file)
@@ -137,9 +137,9 @@ class ChessRules
        }
 
        // d --> 3 (column letter to number)
-       static ColumnToCoord(colnum)
+       static ColumnToCoord(column)
        {
-               return String.fromCharCode(97 + colnum);
+               return column.charCodeAt(0) - 97;
        }
 
        // a4 --> {x:3,y:0}
@@ -975,8 +975,20 @@ class ChessRules
        // After move is played, update variables + flags
        updateVariables(move)
        {
-               const piece = move.vanish[0].p;
-               let c = move.vanish[0].c;
+               let piece = undefined;
+               let c = undefined;
+               if (move.vanish.length >= 1)
+               {
+                       // Usual case, something is moved
+                       piece = move.vanish[0].p;
+                       c = move.vanish[0].c;
+               }
+               else
+               {
+                       // Crazyhouse-like variants
+                       piece = move.appear[0].p;
+                       c = move.appear[0].c;
+               }
                if (c == "c") //if (!["w","b"].includes(c))
                {
                        // 'c = move.vanish[0].c' doesn't work for Checkered