X-Git-Url: https://git.auder.net/css/rpsls.css?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FOtage.js;h=742c6ee19e02c0cf6217be9fa9ac48e17da2bb55;hb=d2af3400944331ffd0c770f83857257c2f48e487;hp=938ef0ee054e80c24a26f4f08249d349bcb4d513;hpb=afcfb85255ee152e3d6bced74260f586ced0f3e8;p=vchess.git diff --git a/client/src/variants/Otage.js b/client/src/variants/Otage.js index 938ef0ee..742c6ee1 100644 --- a/client/src/variants/Otage.js +++ b/client/src/variants/Otage.js @@ -167,6 +167,7 @@ export class OtageRules extends ChessRules { super.setOtherVariables(fen); // Stack of "last move" only for intermediate chaining this.lastMoveEnd = [null]; + this.repetitions = []; } static IsGoodFlags(flags) { @@ -638,8 +639,32 @@ export class OtageRules extends ChessRules { getCheckSquares() { return []; } + filterValid(moves) { - return moves; + if (moves.length == 0) return []; + return moves.filter(m => { + if (!m.end.released) return true; + // Check for repetitions: + V.PlayOnBoard(this.board, m); + const newState = { + piece: m.end.released, + square: { x: m.end.x, y: m.end.y }, + position: this.getBaseFen() + }; + const repet = + this.repetitions.some(r => { + return ( + r.piece == newState.piece && + ( + r.square.x == newState.square.x && + r.square.y == newState.square.y && + ) && + r.position == newState.position + ); + }); + V.UndoOnBoard(this.board, m); + return !repet; + }); } updateCastleFlags(move, piece) { @@ -702,6 +727,16 @@ export class OtageRules extends ChessRules { else this.lastMoveEnd.push(Object.assign({ p: move.end.released }, move.end)); V.PlayOnBoard(this.board, move); + if (!move.end.released) this.repetitions = []; + else { + this.repetitions.push( + { + piece: move.end.released, + square: { x: move.end.x, y: move.end.y }, + position: this.getBaseFen() + } + ); + } } undo(move) { @@ -713,6 +748,7 @@ export class OtageRules extends ChessRules { this.turn = V.GetOppCol(this.turn); this.movesCount--; } + if (!!move.end.released) this.repetitions.pop(); this.postUndo(move); }