X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAlice.js;h=e80e13b6a1ee0bc37b790b4f88f8ff9318337811;hp=2feb8b8f37975427c7684d5c36bc10d316147e46;hb=1c9f093dad69e4c7b6d2b42cb5e0bd3bc7224ec9;hpb=1acda11cd124a446c8bb451feae380efcc8a1cbc diff --git a/client/src/variants/Alice.js b/client/src/variants/Alice.js index 2feb8b8f..e80e13b6 100644 --- a/client/src/variants/Alice.js +++ b/client/src/variants/Alice.js @@ -2,6 +2,7 @@ import { ChessRules } from "@/base_rules"; import { ArrayFun} from "@/utils/array"; // NOTE: alternative implementation, probably cleaner = use only 1 board +// TODO? atLeastOneMove() would be more efficient if rewritten here (less sideBoard computations) export const VariantRules = class AliceRules extends ChessRules { static get ALICE_PIECES() @@ -98,12 +99,14 @@ export const VariantRules = 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); + if (!sideBoard) + sideBoard = [this.getSideBoard(1), this.getSideBoard(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]) + const saveBoard = this.board; + this.board = sideBoard[mirrorSide-1]; + const moves = super.getPotentialMovesFrom([x,y]) .filter(m => { // Filter out king moves which result in under-check position on // current board (before mirror traversing) @@ -111,7 +114,7 @@ export const VariantRules = class AliceRules extends ChessRules if (m.appear[0].p == V.KING) { this.play(m); - if (this.underCheck(color)) + if (this.underCheck(color, sideBoard)) aprioriValid = false; this.undo(m); } @@ -120,7 +123,7 @@ export const VariantRules = class AliceRules extends ChessRules this.board = saveBoard; // Finally filter impossible moves - let res = moves.filter(m => { + const res = moves.filter(m => { if (m.appear.length == 2) //castle { // appear[i] must be an empty square on the other board @@ -172,11 +175,12 @@ export const VariantRules = class AliceRules extends ChessRules return res; } - filterValid(moves) + filterValid(moves, sideBoard) { if (moves.length == 0) return []; - let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; + if (!sideBoard) + sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; const color = this.turn; return moves.filter(m => { this.playSide(m, sideBoard); //no need to track flags @@ -190,20 +194,16 @@ export const VariantRules = class AliceRules extends ChessRules { const color = this.turn; const oppCol = V.GetOppCol(color); - var potentialMoves = []; - let sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; + let potentialMoves = []; + const sideBoard = [this.getSideBoard(1), this.getSideBoard(2)]; for (var i=0; i