X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FAlice.js;h=e81d3fc87f15a46db2d604d64a086e2978b50c90;hb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;hp=5a2d48cfac715e236a035d430abf225324a5fc91;hpb=03608482744c433ad284f4b61e85b2e8cff4f5f3;p=vchess.git diff --git a/client/src/variants/Alice.js b/client/src/variants/Alice.js index 5a2d48cf..e81d3fc8 100644 --- a/client/src/variants/Alice.js +++ b/client/src/variants/Alice.js @@ -1,5 +1,8 @@ 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() @@ -81,7 +84,7 @@ export const VariantRules = class AliceRules extends ChessRules getSideBoard(mirrorSide) { // Build corresponding board from complete board - let sideBoard = doubleArray(V.size.x, V.size.y, ""); + let sideBoard = ArrayFun.init(V.size.x, V.size.y, ""); for (let i=0; i { // Filter out king moves which result in under-check position on // current board (before mirror traversing) @@ -109,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); } @@ -118,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 @@ -170,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 @@ -188,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