X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAllmate.js;h=6225b928aa3dbd8d646f0e3159874b6b1fced62d;hb=54b7b81b12f4c4e95959583830aef61226ff0010;hp=1cfd94a3498f0a65c163efb0982dc4004e25bd37;hpb=9e3f662f10d803ef4f491f9339fb41f341ec8549;p=vchess.git diff --git a/client/src/variants/Allmate.js b/client/src/variants/Allmate.js index 1cfd94a3..6225b928 100644 --- a/client/src/variants/Allmate.js +++ b/client/src/variants/Allmate.js @@ -175,15 +175,74 @@ 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 v.p == V.KING)) this.kingPos[this.turn] = [-1, -1]; } } @@ -192,8 +251,9 @@ export const VariantRules = class AllmateRules extends ChessRules { super.unupdateVariables(move); 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 vIdx = move.vanish.findIndex(v => v.p == V.KING) + if (vIdx >= 0) + this.kingPos[move.vanish[vIdx].c] = [move.vanish[vIdx].x,move.vanish[vIdx].y]; } } @@ -216,8 +276,13 @@ 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) - notation = notation.replace("x","") + "X"; + if (move.vanish.length > 1 && move.appear[0].p != V.KING) { + if (notation.match(/^[a-h]/)) + // Pawn capture: remove "bx" in bxc4 for example + notation = notation.substr(2); + else + notation = notation.replace("x","") + "X"; + } return notation; } };