X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FOtage.js;h=3e35767af8c618e4c603e827259400b1212ede22;hb=f3f8470750e91ac7b5bf57a4e01c5791c54b65fb;hp=938ef0ee054e80c24a26f4f08249d349bcb4d513;hpb=22c591c5862e7ff769ba117f5b6c88d074271352;p=vchess.git diff --git a/client/src/variants/Otage.js b/client/src/variants/Otage.js index 938ef0ee..3e35767a 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,24 @@ 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, position: this.getBaseFen() }; + const repet = + this.repetitions.some(r => { + return ( + r.piece == newState.piece && + r.position == newState.position + ); + }); + V.UndoOnBoard(this.board, m); + return !repet; + }); } updateCastleFlags(move, piece) { @@ -702,6 +719,15 @@ 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, + position: this.getBaseFen() + } + ); + } } undo(move) { @@ -713,6 +739,7 @@ export class OtageRules extends ChessRules { this.turn = V.GetOppCol(this.turn); this.movesCount--; } + if (!!move.end.releasd) this.repetitions.pop(); this.postUndo(move); }