if (['K','k'].includes(row[i])) kings[row[i]]++;
if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
else {
if (['K','k'].includes(row[i])) kings[row[i]]++;
if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
else {
return {
// NOTE: column is always one char => max 26 columns
// row is counted from black side => subtraction
return {
// NOTE: column is always one char => max 26 columns
// row is counted from black side => subtraction
let j = 0;
for (let indexInRow = 0; indexInRow < rows[i].length; indexInRow++) {
const character = rows[i][indexInRow];
let j = 0;
for (let indexInRow = 0; indexInRow < rows[i].length; indexInRow++) {
const character = rows[i][indexInRow];
// If num is a number, just shift j:
if (!isNaN(num)) j += num;
// Else: something at position i,j
// If num is a number, just shift j:
if (!isNaN(num)) j += num;
// Else: something at position i,j
const fenParsed = V.ParseFen(fen);
this.board = V.GetBoard(fenParsed.position);
this.turn = fenParsed.turn;
const fenParsed = V.ParseFen(fen);
this.board = V.GetBoard(fenParsed.position);
this.turn = fenParsed.turn;
const c = this.getColor(x, y);
if (x != (c == "w" ? V.size.x - 1 : 0) || y != this.INIT_COL_KING[c])
return []; //x isn't first rank, or king has moved (shortcut)
const c = this.getColor(x, y);
if (x != (c == "w" ? V.size.x - 1 : 0) || y != this.INIT_COL_KING[c])
return []; //x isn't first rank, or king has moved (shortcut)
- if (this.board[x][rookPos] == V.EMPTY || this.getColor(x, rookPos) != c)
+ if (
+ this.board[x][rookPos] == V.EMPTY ||
+ this.getColor(x, rookPos) != c ||
+ (!!castleWith && !castleWith.includes(this.getPiece(x, rookPos)))
+ ) {
// Nothing on the path of the king ? (and no checks)
const castlingPiece = this.getPiece(x, rookPos);
// Nothing on the path of the king ? (and no checks)
const castlingPiece = this.getPiece(x, rookPos);
- updateCastleFlags(move, piece) {
- const c = V.GetOppCol(this.turn);
+ updateCastleFlags(move, piece, color) {
+ const c = color || V.GetOppCol(this.turn);
const firstRank = (c == "w" ? V.size.x - 1 : 0);
// Update castling flags if rooks are moved
const oppCol = this.turn;
const firstRank = (c == "w" ? V.size.x - 1 : 0);
// Update castling flags if rooks are moved
const oppCol = this.turn;