X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAllmate.js;h=5636f5682194bf9128dbab0a64b71bf633dee642;hb=23ecf00824691b5622b468e0409fc543c87d75dc;hp=1cfd94a3498f0a65c163efb0982dc4004e25bd37;hpb=e9b736ee3e72e2ddb9bf4da0c0f1e22a70f7448f;p=vchess.git diff --git a/client/src/variants/Allmate.js b/client/src/variants/Allmate.js index 1cfd94a3..5636f568 100644 --- a/client/src/variants/Allmate.js +++ b/client/src/variants/Allmate.js @@ -175,25 +175,99 @@ export const VariantRules = class AllmateRules extends ChessRules { return moves; } + // TODO: allow pieces to "commit suicide"? (Currently yes except king) filterValid(moves) { - return moves; + // Remove moves which let the king mate-captured: + if (moves.length == 0) return []; + const color = this.turn; + const oppCol = V.GetOppCol(color); + return moves.filter(m => { + let res = true; + this.play(m); + if (this.underCheck(color)) { + res = false; + const attacked = this.kingPos[color]; + // Try to find a move to escape check + // TODO: very inefficient method. + outerLoop: for (let i=0; i= 2 && move.appear.length == 1) { + move.vanish.forEach(v => { + if (v.c == color) + return; + // Did opponent king disappeared? + if (v.p == V.KING) + this.kingPos[this.turn] = [-1, -1]; + // Or maybe a rook? + else if (v.p == V.ROOK) { + if (v.y < this.INIT_COL_KING[v.c]) + this.castleFlags[v.c][0] = false; + else + // v.y > this.INIT_COL_KING[v.c] + this.castleFlags[v.c][1] = false; + } + }); } } unupdateVariables(move) { super.unupdateVariables(move); - if (move.vanish.length == 2 && move.appear.length == 1) { + const color = this.turn; + if (move.vanish.length >= 2 && move.appear.length == 1) { // Did opponent king disappeared? - if (move.vanish[1].p == V.KING) - this.kingPos[move.vanish[1].c] = [move.vanish[1].x,move.vanish[1].y]; + const psq = move.vanish.find(v => v.p == V.KING && v.c != color) + if (psq) + this.kingPos[psq.c] = [psq.x, psq.y]; } } @@ -216,8 +290,12 @@ export const VariantRules = class AllmateRules extends ChessRules { getNotation(move) { let notation = super.getNotation(move); // Add a capture mark (not describing what is captured...): - if (move.vanish.length > 1 && move.appear[0].p != V.KING) + if (move.vanish.length > 1 && move.appear.length == 1) { + if (notation.match(/^[a-h]x/)) + // Pawn capture: remove initial "b" in bxc4 for example + notation = notation.substr(1); notation = notation.replace("x","") + "X"; + } return notation; } };