X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAtomic.js;h=51346da991dc3dc318174e1e89365cd30d8b436e;hb=3a2a7b5fd3c6bfd0752838094c27e1fb6172d109;hp=2fcb5a6b5f7736864773ecc896b82c14c80719e6;hpb=8b405c81769b822dd2d0db28c613da259f68c071;p=vchess.git diff --git a/client/src/variants/Atomic.js b/client/src/variants/Atomic.js index 2fcb5a6b..51346da9 100644 --- a/client/src/variants/Atomic.js +++ b/client/src/variants/Atomic.js @@ -1,6 +1,13 @@ import { ChessRules, PiPo } from "@/base_rules"; export const VariantRules = class AtomicRules extends ChessRules { + getEpSquare(moveOrSquare) { + if (typeof moveOrSquare !== "object" || moveOrSquare.appear.length > 0) + return super.getEpSquare(moveOrSquare); + // Capturing move: no en-passant + return undefined; + } + getPotentialMovesFrom([x, y]) { let moves = super.getPotentialMovesFrom([x, y]); @@ -73,10 +80,10 @@ export const VariantRules = class AtomicRules extends ChessRules { ); } - updateVariables(move) { - super.updateVariables(move); + postPlay(move) { + super.postPlay(move); if (move.appear.length == 0) { - //capture + // Capture const firstRank = { w: 7, b: 0 }; for (let c of ["w", "b"]) { // Did we explode king of color c ? (TODO: remove move earlier) @@ -85,29 +92,25 @@ export const VariantRules = class AtomicRules extends ChessRules { Math.abs(this.kingPos[c][1] - move.end.y) <= 1 ) { this.kingPos[c] = [-1, -1]; - this.castleFlags[c] = [false, false]; + this.castleFlags[c] = [8, 8]; } else { // Now check if init rook(s) exploded if (Math.abs(move.end.x - firstRank[c]) <= 1) { - if (Math.abs(move.end.y - this.INIT_COL_ROOK[c][0]) <= 1) - this.castleFlags[c][0] = false; - if (Math.abs(move.end.y - this.INIT_COL_ROOK[c][1]) <= 1) - this.castleFlags[c][1] = false; + if (Math.abs(move.end.y - this.castleFlags[c][0]) <= 1) + this.castleFlags[c][0] = 8; + if (Math.abs(move.end.y - this.castleFlags[c][1]) <= 1) + this.castleFlags[c][1] = 8; } } } } } - unupdateVariables(move) { - super.unupdateVariables(move); - const c = move.vanish[0].c; + postUndo(move) { + super.postUndo(move); + const c = this.turn; const oppCol = V.GetOppCol(c); - if ( - [this.kingPos[c][0], this.kingPos[oppCol][0]].some(e => { - return e < 0; - }) - ) { + if ([this.kingPos[c][0], this.kingPos[oppCol][0]].some(e => e < 0)) { // There is a chance that last move blowed some king away.. for (let psq of move.vanish) { if (psq.p == "k") @@ -143,10 +146,9 @@ export const VariantRules = class AtomicRules 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 "*"; if (!this.isAttacked(kp, [V.GetOppCol(color)])) return "1/2"; return color == "w" ? "0-1" : "1-0"; //checkmate