X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fbase_rules.js;h=6cab3496b2f9def3bda447e73b7be8b5b94ff6a1;hb=cf1303697774a12ef9bb154014a38797716944cf;hp=42775dab1553cae4d181eb522f28353cada25f1b;hpb=efb20746c30ac26f258f9c5de6dfb70b91980de4;p=vchess.git diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 42775dab..6cab3496 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -298,9 +298,9 @@ class ChessRules const V = VariantRules; const [sizeX,sizeY] = VariantRules.size; const shift = (color == "w" ? -1 : 1); - const firstRank = (color == 'w' ? sizeY-1 : 0); - const startRank = (color == "w" ? sizeY-2 : 1); - const lastRank = (color == "w" ? 0 : sizeY-1); + const firstRank = (color == 'w' ? sizeX-1 : 0); + const startRank = (color == "w" ? sizeX-2 : 1); + const lastRank = (color == "w" ? 0 : sizeX-1); if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank) { @@ -417,7 +417,7 @@ class ChessRules let step = finalSquares[castleSide][0] < y ? -1 : 1; for (i=y; i!=finalSquares[castleSide][0]; i+=step) { - if (this.isAttacked([x,i], oppCol) || (this.board[x][i] != V.EMPTY && + if (this.isAttacked([x,i], [oppCol]) || (this.board[x][i] != V.EMPTY && // NOTE: next check is enough, because of chessboard constraints (this.getColor(x,i) != c || ![V.KING,V.ROOK].includes(this.getPiece(x,i))))) { @@ -631,7 +631,7 @@ class ChessRules { const color = this.turn; this.play(move); - let res = this.isAttacked(this.kingPos[color], this.getOppCol(color)); + let res = this.isAttacked(this.kingPos[color], [this.getOppCol(color)]); this.undo(move); return res; } @@ -641,7 +641,7 @@ class ChessRules { this.play(move); const color = this.turn; //opponent - let res = this.isAttacked(this.kingPos[color], this.getOppCol(color)) + let res = this.isAttacked(this.kingPos[color], [this.getOppCol(color)]) ? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate! : [ ]; this.undo(move); @@ -773,7 +773,7 @@ class ChessRules { const color = this.turn; // No valid move: stalemate or checkmate? - if (!this.isAttacked(this.kingPos[color], this.getOppCol(color))) + if (!this.isAttacked(this.kingPos[color], [this.getOppCol(color)])) return "1/2"; // OK, checkmate return color == "w" ? "0-1" : "1-0";