X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDark.js;h=a7edb916898fd967584e81fc8ce9918ad5f6f87d;hb=3a2a7b5fd3c6bfd0752838094c27e1fb6172d109;hp=d6515efd8989312a83c28562e1e826ae86443b71;hpb=8477e53d8e78606e4c4e4bf91c77b1011aab583c;p=vchess.git diff --git a/client/src/variants/Dark.js b/client/src/variants/Dark.js index d6515efd..a7edb916 100644 --- a/client/src/variants/Dark.js +++ b/client/src/variants/Dark.js @@ -46,9 +46,7 @@ export const VariantRules = class DarkRules extends ChessRules { V.OnBoard(i + pawnShift[color], j + shiftY) && this.board[i + pawnShift[color]][j + shiftY] == V.EMPTY ) { - this.enlightened[color][i + pawnShift[color]][ - j + shiftY - ] = true; + this.enlightened[color][i + pawnShift[color]][j + shiftY] = true; } } } @@ -65,6 +63,24 @@ export const VariantRules = class DarkRules extends ChessRules { this.enlightened["w"][move.end.x][move.end.y] = true; for (let move of movesBlack) this.enlightened["b"][move.end.x][move.end.y] = true; + // Include en-passant capturing square if any: + let moves = currentTurn == "w" ? movesWhite : movesBlack; + for (let m of moves) { + if ( + m.appear[0].p == V.PAWN && + m.vanish.length == 2 && + m.vanish[1].x != m.end.x + ) { + const psq = m.vanish[1]; + this.enlightened[currentTurn][psq.x][psq.y] = true; + break; + } + } + } + + filterValid(moves) { + // Used in the interface + return moves; } // Has to be redefined to avoid an infinite loop @@ -83,43 +99,27 @@ export const VariantRules = class DarkRules extends ChessRules { return potentialMoves; //because there are no checks } - atLeastOneMove() { - if (this.kingPos[this.turn][0] < 0) return false; - return true; //TODO: is it right? - } - - underCheck() { - return false; //there is no check - } - getCheckSquares() { return []; } - updateVariables(move) { - super.updateVariables(move); - if (move.vanish.length >= 2 && move.vanish[1].p == V.KING) { - // We took opponent king ! (because if castle vanish[1] is a rook) + postPlay(move) { + super.postPlay(move); + if (move.vanish.length >= 2 && move.vanish[1].p == V.KING) + // We took opponent king (because if castle vanish[1] is a rook) this.kingPos[this.turn] = [-1, -1]; - } // Update lights for both colors: this.updateEnlightened(); } - unupdateVariables(move) { - super.unupdateVariables(move); + postUndo(move) { + super.postUndo(move); const c = move.vanish[0].c; const oppCol = V.GetOppCol(c); - if (this.kingPos[oppCol][0] < 0) { - // Last move took opponent's king - for (let psq of move.vanish) { - if (psq.p == "k") { - this.kingPos[oppCol] = [psq.x, psq.y]; - break; - } - } - } + if (this.kingPos[oppCol][0] < 0) + // Last move took opponent's king: + this.kingPos[oppCol] = [move.vanish[1].x, move.vanish[1].y]; // Update lights for both colors: this.updateEnlightened(); @@ -129,12 +129,10 @@ export const VariantRules = class DarkRules extends ChessRules { const color = this.turn; const kp = this.kingPos[color]; if (kp[0] < 0) - //king disappeared + // King disappeared return color == "w" ? "0-1" : "1-0"; - if (this.atLeastOneMove()) - // game not over - return "*"; - return "1/2"; //no moves but kings still there (seems impossible) + // Assume that stalemate is impossible (I think so. Would need proof...) + return "*"; } static get THRESHOLD_MATE() { @@ -243,19 +241,18 @@ export const VariantRules = class DarkRules extends ChessRules { // Can I take something ? If yes, do it if it seems good... if (move.vanish.length == 2 && move.vanish[1].c != color) { - //avoid castle + // OK this isn't a castling move const myPieceVal = V.VALUES[move.appear[0].p]; const hisPieceVal = V.VALUES[move.vanish[1].p]; - if (myPieceVal <= hisPieceVal) move.eval = hisPieceVal - myPieceVal + 2; - //favor captures + // Favor captures + if (myPieceVal <= hisPieceVal) move.eval = hisPieceVal - myPieceVal + 1; else { // Taking a pawn with minor piece, // or minor piece or pawn with a rook, // or anything but a queen with a queen, // or anything with a king. - // ==> Do it at random, although - // this is clearly inferior to what a human can deduce... - move.eval = Math.random() < 0.5 ? 1 : -1; + move.eval = hisPieceVal - myPieceVal; + //Math.random() < 0.5 ? 1 : -1; } } }