X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FBerolina.js;h=517a93e59579a6f3723d74504616ebd17881b017;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=dc9e25740f622be88c720a4ec53c4a6cc1eff395;hpb=f6dbe8e31a3260487664f1e0b50710b3f3efaf5f;p=vchess.git diff --git a/public/javascripts/variants/Berolina.js b/public/javascripts/variants/Berolina.js index dc9e2574..517a93e5 100644 --- a/public/javascripts/variants/Berolina.js +++ b/public/javascripts/variants/Berolina.js @@ -10,17 +10,26 @@ class BerolinaRules extends ChessRules const square = moveOrSquare; if (square == "-") return undefined; - return V.SquareToCoords(square); + // Enemy pawn initial column must be given too: + let res = []; + const epParts = square.split(","); + res.push(V.SquareToCoords(epParts[0])); + res.push(V.ColumnToCoord(epParts[1])); + return res; } // Argument is a move: const move = moveOrSquare; const [sx,ex,sy] = [move.start.x,move.end.x,move.start.y]; if (this.getPiece(sx,sy) == V.PAWN && Math.abs(sx - ex) == 2) { - return { - x: (ex + sx)/2, - y: (move.end.y + sy)/2 - }; + return + [ + { + x: (ex + sx)/2, + y: (move.end.y + sy)/2 + }, + move.end.y + ]; } return undefined; //default } @@ -35,47 +44,48 @@ class BerolinaRules extends ChessRules const firstRank = (color == 'w' ? sizeX-1 : 0); const startRank = (color == "w" ? sizeX-2 : 1); const lastRank = (color == "w" ? 0 : sizeX-1); + const finalPieces = x + shiftX == lastRank + ? [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN] + : [V.PAWN]; - if (x+shiftX >= 0 && x+shiftX < sizeX) //TODO: always true + // One square diagonally + for (let shiftY of [-1,1]) { - const finalPieces = x + shiftX == lastRank - ? [V.ROOK,V.KNIGHT,V.BISHOP,V.QUEEN] - : [V.PAWN] - // One square diagonally - for (let shiftY of [-1,1]) + if (this.board[x+shiftX][y+shiftY] == V.EMPTY) { - if (this.board[x+shiftX][y+shiftY] == V.EMPTY) + for (let piece of finalPieces) { - for (let piece of finalPieces) - moves.push(this.getBasicMove([x,y], [x+shiftX,y+shiftY], {c:color,p:piece})); - if (x == startRank && y+2*shiftY>=0 && y+2*shiftY=0 && y+2*shiftY=0 && x+pawnShift