X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FSwitching.js;h=cedba3dbdb2e15c8dbc869329355d2ad6032bd8d;hb=15952ada1d73262371654351ab8a4471f64010fd;hp=cc2febd1e646f64fbdec59e520e9a94fa7ee1243;hpb=1221ac47836806efb287b0323b92957d9129c653;p=vchess.git diff --git a/public/javascripts/variants/Switching.js b/public/javascripts/variants/Switching.js index cc2febd1..cedba3db 100644 --- a/public/javascripts/variants/Switching.js +++ b/public/javascripts/variants/Switching.js @@ -3,10 +3,12 @@ class SwitchingRules extends ChessRules // Build switch move between squares x1,y1 and x2,y2 getSwitchMove_s([x1,y1],[x2,y2]) { - const c = this.getColor(x1,y1); //same as color at square 2 const p1 = this.getPiece(x1,y1); const p2 = this.getPiece(x2,y2); + const V = VariantRules; + 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}), @@ -22,28 +24,37 @@ class SwitchingRules extends ChessRules // Move completion: promote switched pawns (as in Magnetic) const sizeX = VariantRules.size[0]; const lastRank = (c == "w" ? 0 : sizeX-1); - const V = VariantRules; let moves = []; - if (p1==V.PAWN && x2==lastRank) //TODO: also the case p2==V.PAWN and x1==lastRank! see Magnetic chess + if ((p1==V.PAWN && x2==lastRank) || (p2==V.PAWN && x1==lastRank)) { - move.appear[0].p = V.ROOK; + const idx = (p1==V.PAWN ? 0 : 1); + move.appear[idx].p = V.ROOK; moves.push(move); for (let piece of [V.KNIGHT, V.BISHOP, V.QUEEN]) { let cmove = JSON.parse(JSON.stringify(move)); - cmove.appear[0].p = piece; + cmove.appear[idx].p = piece; moves.push(cmove); } + if (idx == 1) + { + // Swap moves[i].appear[0] and [1] for moves presentation [TODO...] + moves.forEach(m => { + let tmp = m.appear[0]; + m.appear[0] = m.appear[1]; + m.appear[1] = tmp; + }); + } } else //other cases moves.push(move); return moves; } - getPotentialMovesFrom([x,y]) + getPotentialMovesFrom([x,y], computer) { let moves = super.getPotentialMovesFrom([x,y]); - // Add switches: + // Add switches: respecting chessboard ordering if "computer" is on const V = VariantRules; const color = this.turn; const piece = this.getPiece(x,y); @@ -54,6 +65,8 @@ class SwitchingRules extends ChessRules for (let step of steps) { let [i,j] = [x+step[0],y+step[1]]; + if (!!computer && (i=0 && i=0 && j