X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FInterweave.js;h=8e0c3cc6ac021aa7568b3a8816ef1ec1de5f08b2;hb=7ddfec38b0804bf0bd0c5b5c6972d355902e9fb0;hp=c776889f10be2e8a8482b9e023209573210cc8ec;hpb=1d92e1e913d216fa96c12a5dc810fe117c384196;p=vchess.git diff --git a/client/src/variants/Interweave.js b/client/src/variants/Interweave.js index c776889f..8e0c3cc6 100644 --- a/client/src/variants/Interweave.js +++ b/client/src/variants/Interweave.js @@ -195,56 +195,21 @@ export class InterweaveRules extends ChessRules { ); } - getPotentialMovesFrom([x, y], noPostprocess) { - const L = this.lastMoveEnd.length; - if ( - !!this.lastMoveEnd[L-1] && - ( - x != this.lastMoveEnd[L-1].x || - y != this.lastMoveEnd[L-1].y - ) - ) { - // A capture must continue: wrong square - return []; - } - let moves = []; + getPotentialMovesFrom([x, y]) { switch (this.getPiece(x, y)) { case V.PAWN: - moves = this.getPotentialPawnMoves([x, y]); - break; + return this.getPotentialPawnMoves([x, y]); case V.ROOK: - moves = this.getPotentialRookMoves([x, y]); - break; + return this.getPotentialRookMoves([x, y]); case V.KNIGHT: - moves = this.getPotentialKnightMoves([x, y]); - break; + return this.getPotentialKnightMoves([x, y]); case V.BISHOP: - moves = this.getPotentialBishopMoves([x, y]); - break; + return this.getPotentialBishopMoves([x, y]); case V.KING: - moves = this.getPotentialKingMoves([x, y]); - break; + return this.getPotentialKingMoves([x, y]); // No queens } - if (!noPostprocess) { - // Post-process: if capture, - // can another capture be achieved with the same piece? - moves.forEach(m => { - if (m.vanish.length >= 2 || m.appear.length == 0) { - this.play(m); - const moreCaptures = ( - V.KeepCaptures( - this.getPotentialMovesFrom([m.end.x, m.end.y], "noPostprocess") - ) - .length > 0 - ); - this.undo(m); - if (!moreCaptures) m.last = true; - } - else m.last = true; - }); - } - return moves; + return []; } // Special pawns movements @@ -590,11 +555,23 @@ export class InterweaveRules extends ChessRules { for (let i=1; i= 2 || move.appear.length == 0) { + const moreCaptures = ( + V.KeepCaptures( + this.getPotentialMovesFrom([move.end.x, move.end.y]) + ) + .length > 0 + ); + move.last = !moreCaptures; + } + else move.last = true; if (!!move.last) { // No capture, or no more capture available this.turn = V.GetOppCol(this.turn); this.movesCount++; this.lastMoveEnd.push(null); + move.last = true; //will be used in undo and computer play } else this.lastMoveEnd.push(move.end); } @@ -639,14 +616,14 @@ export class InterweaveRules extends ChessRules { while (moves.length > 0) { const mv = moves[randInt(moves.length)]; mvArray.push(mv); + this.play(mv); if (!mv.last) { - this.play(mv); moves = V.KeepCaptures( this.getPotentialMovesFrom([mv.end.x, mv.end.y])); } else break; } - for (let i = mvArray.length - 2; i >= 0; i--) this.undo(mvArray[i]); + for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]); return (mvArray.length > 1 ? mvArray : mvArray[0]); }