super.setOtherVariables(fen);
// Stack of "last move" only for intermediate chaining
this.lastMoveEnd = [null];
+ this.repetitions = [];
}
static IsGoodFlags(flags) {
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) {
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) {
this.turn = V.GetOppCol(this.turn);
this.movesCount--;
}
+ if (!!move.end.released) this.repetitions.pop();
this.postUndo(move);
}