X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FBerolina.js;h=31630ab52bbfca0799c40b21b6060364201ab041;hb=69f3d8014e594ef949792d04d97b8286e9c2c268;hp=c556f51758c6a8122f1c4818cd363a352097049c;hpb=375ecdd1387e729f85ed114e82253469e4849869;p=vchess.git diff --git a/public/javascripts/variants/Berolina.js b/public/javascripts/variants/Berolina.js index c556f517..31630ab5 100644 --- a/public/javascripts/variants/Berolina.js +++ b/public/javascripts/variants/Berolina.js @@ -10,23 +10,31 @@ 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, - y: (move.end.y + sy)/2 - }; + return + [ + { + x: (ex + sx)/2, + y: (move.end.y + sy)/2 + }, + move.end.y + ]; } return undefined; //default } - // Special pawn rules: promotions to captured friendly pieces, - // optional on ranks 8-9 and mandatory on rank 10. + // Special pawns movements getPotentialPawnMoves([x,y]) { const color = this.turn; @@ -36,58 +44,94 @@ 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) - { - for (let piece of finalPieces) - { - moves.push(this.getBasicMove([x,y], [x+shiftX,y+shiftY], - {c:pawnColor,p:piece})); - } - if (x == startRank && this.board[x+2*shiftX][y] == V.EMPTY) - { - // Two squares jump - moves.push(this.getBasicMove([x,y], [x+2*shiftX,y+2*shiftY]); - } - } - } - // Capture - if (this.board[x+shiftX][y] != V.EMPTY - && this.canTake([x,y], [x+shiftX,y])) + if (this.board[x+shiftX][y+shiftY] == V.EMPTY) { for (let piece of finalPieces) { moves.push(this.getBasicMove([x,y], [x+shiftX,y+shiftY], - {c:pawnColor,p:piece})); + {c:color,p:piece})); + } + if (x == startRank && y+2*shiftY>=0 && y+2*shiftY=0 && x+pawnShift