X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FAlice.js;h=3a613585d31f9371655e0861de52d546a240bd55;hb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;hp=2788e2101701cc60621bf6e973a96cf45eaa5de1;hpb=26c1e3bd4d3e9fb7c86e25c0f423bea57b977111;p=vchess.git diff --git a/public/javascripts/variants/Alice.js b/public/javascripts/variants/Alice.js index 2788e210..3a613585 100644 --- a/public/javascripts/variants/Alice.js +++ b/public/javascripts/variants/Alice.js @@ -95,11 +95,25 @@ class AliceRules extends ChessRules const pieces = Object.keys(V.ALICE_CODES); const codes = Object.keys(V.ALICE_PIECES); const mirrorSide = (pieces.includes(this.getPiece(x,y)) ? 1 : 2); + const color = this.getColor(x,y); // Search valid moves on sideBoard let saveBoard = this.board; this.board = sideBoard || this.getSideBoard(mirrorSide); - let moves = super.getPotentialMovesFrom([x,y]); + let moves = super.getPotentialMovesFrom([x,y]) + .filter(m => { + // Filter out king moves which result in under-check position on + // current board (before mirror traversing) + let aprioriValid = true; + if (m.appear[0].p == V.KING) + { + this.play(m); + if (this.underCheck(color)) + aprioriValid = false; + this.undo(m); + } + return aprioriValid; + }); this.board = saveBoard; // Finally filter impossible moves @@ -140,7 +154,7 @@ class AliceRules extends ChessRules if (m.vanish[0].p == V.PAWN && m.vanish.length == 2 && this.board[m.end.x][m.end.y] == V.EMPTY) { - m.vanish[1].c = this.getOppCol(this.getColor(x,y)); + m.vanish[1].c = V.GetOppCol(this.getColor(x,y)); // In the special case of en-passant, if // - board1 takes board2 : vanish[1] --> Alice // - board2 takes board1 : vanish[1] --> normal @@ -172,7 +186,7 @@ class AliceRules extends ChessRules getAllValidMoves() { const color = this.turn; - const oppCol = this.getOppCol(color); + const oppCol = V.GetOppCol(color); var potentialMoves = []; let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; for (var i=0; i