rename getOppCol into static GetOppCol + start thinking about problems page
[vchess.git] / public / javascripts / variants / Switching.js
index ee84e4c..d898ff6 100644 (file)
@@ -57,7 +57,7 @@ class SwitchingRules extends ChessRules
                const piece = this.getPiece(x,y);
                const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]);
                const kp = this.kingPos[color];
-               const oppCol = this.getOppCol(color);
+               const oppCol = V.GetOppCol(color);
                for (let step of steps)
                {
                        let [i,j] = [x+step[0],y+step[1]];
@@ -81,7 +81,7 @@ class SwitchingRules extends ChessRules
        getAllValidMoves(computer)
        {
                const color = this.turn;
-               const oppCol = this.getOppCol(color);
+               const oppCol = V.GetOppCol(color);
                let potentialMoves = [];
                for (let i=0; i<V.size.x; i++)
                {
@@ -104,7 +104,7 @@ class SwitchingRules extends ChessRules
                        && move.appear[1].p == V.KING)
                {
                        // Switch with the king; not castle, and not handled by main class
-                       const color = this.getColor(move.start.x, move.start.y);
+                       const color = move.vanish[0].c;
                        this.kingPos[color] = [move.appear[1].x, move.appear[1].y];
                }
        }
@@ -115,7 +115,7 @@ class SwitchingRules extends ChessRules
                if (move.appear.length == 2 && move.vanish.length == 2
                        && move.appear[1].p == V.KING)
                {
-                       const color = this.getColor(move.start.x, move.start.y);
+                       const color = move.vanish[0].c;
                        this.kingPos[color] = [move.appear[0].x, move.appear[0].y];
                }
        }
@@ -130,10 +130,8 @@ class SwitchingRules extends ChessRules
                if (move.appear[0].p == V.KING && move.appear[1].p == V.ROOK)
                        return (move.end.y < move.start.y ? "0-0-0" : "0-0");
                // Switch:
-               const startSquare =
-                       String.fromCharCode(97 + move.start.y) + (V.size.x-move.start.x);
-               const finalSquare =
-                       String.fromCharCode(97 + move.end.y) + (V.size.x-move.end.x);
-               return "S" + startSquare + finalSquare;
+               return "S" + V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end);
        }
 }
+
+const VariantRules = SwitchingRules;