X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FDark.js;h=8f941762e701dc9be5f4eb6a699080c2d4cefd38;hb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;hp=3944ca16308c88d7d8f5258d0b9452e7a6be099b;hpb=241bf8f2a9a2c48d793aeb0b1d20207f6371de70;p=vchess.git diff --git a/client/src/variants/Dark.js b/client/src/variants/Dark.js index 3944ca16..8f941762 100644 --- a/client/src/variants/Dark.js +++ b/client/src/variants/Dark.js @@ -2,7 +2,7 @@ import { ChessRules } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; -export const VariantRules = class DarkRules extends ChessRules { +export class DarkRules extends ChessRules { // Analyse in Dark mode makes no sense static get CanAnalyze() { return false; @@ -37,16 +37,16 @@ export const VariantRules = class DarkRules extends ChessRules { 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 color = this.getColor(i, j); - this.enlightened[color][i][j] = true; + const c = this.getColor(i, j); + this.enlightened[c][i][j] = true; // Add potential squares visible by "impossible pawn capture" if (this.getPiece(i, j) == V.PAWN) { for (let shiftY of [-1, 1]) { if ( - V.OnBoard(i + pawnShift[color], j + shiftY) && - this.board[i + pawnShift[color]][j + shiftY] == V.EMPTY + V.OnBoard(i + pawnShift[c], j + shiftY) && + this.board[i + pawnShift[c]][j + shiftY] == V.EMPTY ) { - this.enlightened[color][i + pawnShift[color]][j + shiftY] = true; + this.enlightened[c][i + pawnShift[c]][j + shiftY] = true; } } } @@ -63,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 @@ -85,8 +103,8 @@ export const VariantRules = class DarkRules extends ChessRules { return []; } - updateVariables(move) { - super.updateVariables(move); + 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]; @@ -95,8 +113,8 @@ export const VariantRules = class DarkRules extends ChessRules { 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) @@ -223,19 +241,19 @@ 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; } } }