X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered.js;h=5f9bf8f6843618f4e56b1b2a983870d979d69358;hb=7ba4a5bc5b64e19a1e7f26aa232d5c50770d07ad;hp=d477a6d05ecd015c2ec6aa1c1da5e39e28f55ea0;hpb=241bf8f2a9a2c48d793aeb0b1d20207f6371de70;p=vchess.git diff --git a/client/src/variants/Checkered.js b/client/src/variants/Checkered.js index d477a6d0..5f9bf8f6 100644 --- a/client/src/variants/Checkered.js +++ b/client/src/variants/Checkered.js @@ -37,7 +37,7 @@ export const VariantRules = class CheckeredRules extends ChessRules { } getPpath(b) { - return b[0] == "c" ? "Checkered/" + b : b; + return (b[0] == "c" ? "Checkered/" : "") + b; } setOtherVariables(fen) { @@ -74,7 +74,6 @@ export const VariantRules = class CheckeredRules extends ChessRules { w: [...Array(8).fill(true)], //pawns can move 2 squares? b: [...Array(8).fill(true)] }; - if (!fenflags) return; const flags = fenflags.substr(4); //skip first 4 digits, for castle for (let c of ["w", "b"]) { for (let i = 0; i < 8; i++) @@ -112,7 +111,8 @@ export const VariantRules = class CheckeredRules extends ChessRules { getPotentialMovesFrom([x, y]) { let standardMoves = super.getPotentialMovesFrom([x, y]); const lastRank = this.turn == "w" ? 0 : 7; - if (this.getPiece(x, y) == V.KING) return standardMoves; //king has to be treated differently (for castles) + // King has to be treated differently (for castles) + if (this.getPiece(x, y) == V.KING) return standardMoves; let moves = []; standardMoves.forEach(m => { if (m.vanish[0].p == V.PAWN) { @@ -180,6 +180,41 @@ export const VariantRules = class CheckeredRules extends ChessRules { }); } + getAllValidMoves() { + const oppCol = V.GetOppCol(this.turn); + let potentialMoves = []; + for (let i = 0; i < V.size.x; i++) { + for (let j = 0; j < V.size.y; j++) { + // NOTE: just testing == color isn't enough because of checkred pieces + if (this.board[i][j] != V.EMPTY && this.getColor(i, j) != oppCol) { + Array.prototype.push.apply( + potentialMoves, + this.getPotentialMovesFrom([i, j]) + ); + } + } + } + return this.filterValid(potentialMoves); + } + + atLeastOneMove() { + const oppCol = V.GetOppCol(this.turn); + for (let i = 0; i < V.size.x; i++) { + for (let j = 0; j < V.size.y; j++) { + // NOTE: just testing == color isn't enough because of checkred pieces + if (this.board[i][j] != V.EMPTY && this.getColor(i, j) != oppCol) { + const moves = this.getPotentialMovesFrom([i, j]); + if (moves.length > 0) { + for (let k = 0; k < moves.length; k++) { + if (this.filterValid([moves[k]]).length > 0) return true; + } + } + } + } + } + return false; + } + isAttackedByPawn([x, y], colors) { for (let c of colors) { const color = c == "c" ? this.turn : c; @@ -245,23 +280,25 @@ export const VariantRules = class CheckeredRules extends ChessRules { evalPosition() { let evaluation = 0; - //Just count material for now, considering checkered neutral (...) + // Just count material for now, considering checkered neutral (...) for (let i = 0; i < V.size.x; i++) { for (let j = 0; j < V.size.y; j++) { if (this.board[i][j] != V.EMPTY) { const sqColor = this.getColor(i, j); - const sign = sqColor == "w" ? 1 : sqColor == "b" ? -1 : 0; - evaluation += sign * V.VALUES[this.getPiece(i, j)]; + if (["w","b"].includes(sqColor)) { + const sign = sqColor == "w" ? 1 : -1; + evaluation += sign * V.VALUES[this.getPiece(i, j)]; + } } } } return evaluation; } - static GenRandInitFen() { - const randFen = ChessRules.GenRandInitFen(); - // Add 16 pawns flags + empty cmove: - return randFen.replace(" w 0 1111", " w 0 11111111111111111111 -"); + static GenRandInitFen(randomness) { + return ChessRules.GenRandInitFen(randomness) + // Add 16 pawns flags + empty cmove: + .replace(" w 0 1111", " w 0 11111111111111111111 -"); } static ParseFen(fen) {