X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=20e123b3602483de16ba238e8b6868b369e604be;hb=2beba6db1bec978f55ff0da465f6a17cd40346da;hp=8cf86a861a8be4457103ef0f38e15745d695f5c6;hpb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 8cf86a86..20e123b3 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -512,12 +512,6 @@ export const ChessRules = class ChessRules return (color=="w" ? "b" : "w"); } - // Get next color (for compatibility with 3 and 4 players games) - static GetNextCol(color) - { - return V.GetOppCol(color); - } - // Pieces codes (for a clearer code) static get PAWN() { return 'p'; } static get ROOK() { return 'r'; } @@ -754,10 +748,11 @@ export const ChessRules = class ChessRules continue; // If this code is reached, rooks and king are on initial position - // Nothing on the path of the king ? - // (And no checks; OK also if y==finalSquare) - let step = finalSquares[castleSide][0] < y ? -1 : 1; - for (i=y; i!=finalSquares[castleSide][0]; i+=step) + // Nothing on the path of the king ? (and no checks) + const finDist = finalSquares[castleSide][0] - y; + let step = finDist / Math.max(1, Math.abs(finDist)); + i = y; + do { if (this.isAttacked([x,i], [oppCol]) || (this.board[x][i] != V.EMPTY && // NOTE: next check is enough, because of chessboard constraints @@ -766,10 +761,12 @@ export const ChessRules = class ChessRules { continue castlingCheck; } + i += step; } + while (i!=finalSquares[castleSide][0]); // Nothing on the path to the rook? - step = castleSide == 0 ? -1 : 1; + step = (castleSide == 0 ? -1 : 1); for (i = y + step; i != this.INIT_COL_ROOK[c][castleSide]; i += step) { if (this.board[x][i] != V.EMPTY)