// "positions" = array of FENs to detect infinite loops. Example:
// r1q1k2r/p1Pb1ppp/5n2/1f1p4/AV5P/P1eDP3/3B1PP1/R3K1NR,
// Bxd2 Bxc3 Bxb4 Bxc3 Bxb4 etc.
- const newPos = { fen: super.getBaseFen(), piece: released };
- if (positions.some(p => p.piece == newPos.piece && p.fen == newPos.fen))
+ const newPos = {
+ fen: super.getBaseFen(),
+ piece: released,
+ from: fromSquare
+ };
+ if (
+ positions.some(p => {
+ return (
+ p.piece == newPos.piece &&
+ p.fen == newPos.fen &&
+ p.from == newPos.from
+ );
+ })
+ ) {
// Start of an infinite loop: exit
return false;
+ }
positions.push(newPos);
const rank = (color == 'w' ? 0 : 7);
const moves = this.getPotentialMovesFrom(fromSquare);
return res;
}
+ isAttackedBySlideNJump([x, y], color, piece, steps, oneStep) {
+ for (let step of steps) {
+ let rx = x + step[0],
+ ry = y + step[1];
+ while (V.OnBoard(rx, ry) && this.board[rx][ry] == V.EMPTY && !oneStep) {
+ rx += step[0];
+ ry += step[1];
+ }
+ if (
+ V.OnBoard(rx, ry) &&
+ this.board[rx][ry] != V.EMPTY &&
+ this.getPiece(rx, ry) == piece &&
+ this.getColor(rx, ry) == color &&
+ this.canTake([rx, ry], [x, y]) //TODO: necessary line?
+ //If not, generic method is OK
+ ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// Do not consider checks, except to forbid castling
getCheckSquares() {
return [];