X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FSwitching.js;h=e53ab6926d9e5e7be2b70bed410d7db70e4d3656;hb=643479f8d7c3622b57fc49c4f10d9950793ebf4f;hp=3ddf50322c500db93ac8c90343594283ff444cb6;hpb=9f18af3bf306f89ae67c5cb5ba4ab3f581787256;p=vchess.git diff --git a/public/javascripts/variants/Switching.js b/public/javascripts/variants/Switching.js index 3ddf5032..e53ab692 100644 --- a/public/javascripts/variants/Switching.js +++ b/public/javascripts/variants/Switching.js @@ -6,6 +6,8 @@ class SwitchingRules extends ChessRules const c = this.getColor(x1,y1); //same as color at square 2 const p1 = this.getPiece(x1,y1); const p2 = this.getPiece(x2,y2); + if (p1 == V.KING && p2 == V.ROOK) + return []; //avoid duplicate moves (potential conflict with castle) let move = new Move({ appear: [ new PiPo({x:x2,y:y2,c:c,p:p1}), @@ -19,9 +21,7 @@ class SwitchingRules extends ChessRules end: {x:x2,y:y2} }); // Move completion: promote switched pawns (as in Magnetic) - const sizeX = VariantRules.size[0]; - const lastRank = (c == "w" ? 0 : sizeX-1); - const V = VariantRules; + const lastRank = (c == "w" ? 0 : V.size.x-1); let moves = []; if ((p1==V.PAWN && x2==lastRank) || (p2==V.PAWN && x1==lastRank)) { @@ -49,21 +49,21 @@ class SwitchingRules extends ChessRules return moves; } - getPotentialMovesFrom([x,y]) + getPotentialMovesFrom([x,y], computer) { let moves = super.getPotentialMovesFrom([x,y]); - // Add switches: - const V = VariantRules; + // Add switches: respecting chessboard ordering if "computer" is on const color = this.turn; const piece = this.getPiece(x,y); - const [sizeX,sizeY] = V.size; const steps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); const kp = this.kingPos[color]; const oppCol = this.getOppCol(color); for (let step of steps) { let [i,j] = [x+step[0],y+step[1]]; - if (i>=0 && i=0 && j