return (f.charCodeAt()<=90 ? "w"+f.toLowerCase() : "b"+f);
}
- // Check if FEN describe a position
+ // Check if FEN describe a board situation correctly
static IsGoodFen(fen)
{
const fenParsed = V.ParseFen(fen);
return (color=="w" ? "b" : "w");
}
- // Get next color (for compatibility with 3 and 4 players games)
- static GetNextCol(color)
- {
- return V.GetOppCol(color);
- }
-
// Pieces codes (for a clearer code)
static get PAWN() { return 'p'; }
static get ROOK() { return 'r'; }
continue;
// If this code is reached, rooks and king are on initial position
- // Nothing on the path of the king ?
- // (And no checks; OK also if y==finalSquare)
- let step = finalSquares[castleSide][0] < y ? -1 : 1;
- for (i=y; i!=finalSquares[castleSide][0]; i+=step)
+ // Nothing on the path of the king ? (and no checks)
+ const finDist = finalSquares[castleSide][0] - y;
+ let step = finDist / Math.max(1, Math.abs(finDist));
+ i = y;
+ do
{
if (this.isAttacked([x,i], [oppCol]) || (this.board[x][i] != V.EMPTY &&
// NOTE: next check is enough, because of chessboard constraints
{
continue castlingCheck;
}
+ i += step;
}
+ while (i!=finalSquares[castleSide][0]);
// Nothing on the path to the rook?
- step = castleSide == 0 ? -1 : 1;
+ step = (castleSide == 0 ? -1 : 1);
for (i = y + step; i != this.INIT_COL_ROOK[c][castleSide]; i += step)
{
if (this.board[x][i] != V.EMPTY)