X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered.js;h=ac99602b5d07e632f1659fc44010b13e04f2e568;hp=e930fb847317315be5fa0197059d2ba0b1925a28;hb=d1be804633f9632b35662c0b10743ca50e10030f;hpb=bc06c9bbc9c8ead4ae270204d10f4ff686c764a4 diff --git a/client/src/variants/Checkered.js b/client/src/variants/Checkered.js index e930fb84..ac99602b 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) { @@ -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,13 +280,15 @@ 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)]; + } } } }