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, 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) {
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) {
this.turn = V.GetOppCol(this.turn);
this.movesCount--;
}
+ if (!!move.end.releasd) this.repetitions.pop();
this.postUndo(move);
}
end: ChessRules.SquareToCoords(umove.substr(2))
});
}
+ // Local stack of positions to avoid redundant moves:
+ this.repetitions = [];
}
static IsGoodFen(fen) {
getCheckSquares() {
return [];
}
+
filterValid(moves) {
if (moves.length == 0) return [];
const L = this.umoves.length; //at least 1: init from FEN
- return moves.filter(m => !this.oppositeMoves(this.umoves[L - 1], m));
+ return moves.filter(m => {
+ if (this.oppositeMoves(this.umoves[L - 1], m)) return false;
+ 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) {
}
V.PlayOnBoard(this.board, move);
this.umoves.push(this.getUmove(move));
+ if (!move.end.released) this.repetitions = [];
+ else {
+ this.repetitions.push(
+ {
+ piece: move.end.released,
+ position: this.getBaseFen()
+ }
+ );
+ }
}
undo(move) {
this.movesCount--;
}
this.umoves.pop();
+ if (!!move.end.releasd) this.repetitions.pop();
this.postUndo(move);
}