X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FAlice.js;h=04b4a3466169df2698bb236796ea41cdd636afdd;hb=b955c65b942d09d24b5c3bed0d755d4f2f8f71f1;hp=ece59cdc75e06e5201de2f0168ebfbd46c5b27db;hpb=7931e479adf93c87771ded1892a0873af72ae46d;p=vchess.git diff --git a/public/javascripts/variants/Alice.js b/public/javascripts/variants/Alice.js index ece59cdc..04b4a346 100644 --- a/public/javascripts/variants/Alice.js +++ b/public/javascripts/variants/Alice.js @@ -29,24 +29,24 @@ class AliceRules extends ChessRules return (Object.keys(this.ALICE_PIECES).includes(b[1]) ? "Alice/" : "") + b; } - static get PIECES() { + static get PIECES() + { return ChessRules.PIECES.concat(Object.keys(V.ALICE_PIECES)); } - initVariables(fen) + setOtherVariables(fen) { - super.initVariables(fen); - const fenParts = fen.split(" "); - const position = fenParts[0].split("/"); + super.setOtherVariables(fen); + const rows = V.ParseFen(fen).position.split("/"); if (this.kingPos["w"][0] < 0 || this.kingPos["b"][0] < 0) { - // INIT_COL_XXX won't be used, so no need to set them for Alice kings - for (let i=0; i { + // 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 @@ -160,13 +174,19 @@ class AliceRules extends ChessRules if (moves.length == 0) return []; let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; - return moves.filter(m => { return !this.underCheck(m, sideBoard); }); + const color = this.turn; + return moves.filter(m => { + this.playSide(m, sideBoard); //no need to track flags + const res = !this.underCheck(color, sideBoard); + this.undoSide(m, sideBoard); + return res; + }); } 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 move.appear.length ? "x" : ""); let pawnMark = ""; if (["p","s"].includes(piece) && captureMark.length == 1) - pawnMark = String.fromCharCode(97 + move.start.y); //start column + pawnMark = V.CoordToColumn(move.start.y); //start column // Piece or pawn movement let notation = piece.toUpperCase() + pawnMark + captureMark + finalSquare;