// Turn "p" into "bp" (for board)
static fen2board(f) {
- return f.charCodeAt() <= 90 ? "w" + f.toLowerCase() : "b" + f;
+ return f.charCodeAt(0) <= 90 ? "w" + f.toLowerCase() : "b" + f;
}
// Check if FEN describes a board situation correctly
static IsGoodFen(fen) {
+console.log("ddd");
const fenParsed = V.ParseFen(fen);
// 1) Check position
if (!V.IsGoodPosition(fenParsed.position)) return false;
}
// Scan board for kings positions
+ // TODO: should be done from board, no need for the complete FEN
scanKings(fen) {
// Squares of white and black king:
this.kingPos = { w: [-1, -1], b: [-1, -1] };
const fenRows = V.ParseFen(fen).position.split("/");
- const startRow = { 'w': V.size.x - 1, 'b': 0 };
for (let i = 0; i < fenRows.length; i++) {
let k = 0; //column index on board
for (let j = 0; j < fenRows[i].length; j++) {
// Castling ?
const oppCol = V.GetOppCol(c);
let moves = [];
- let i = 0;
// King, then rook:
finalSquares = finalSquares || [ [2, 3], [V.size.y - 2, V.size.y - 3] ];
const castlingKing = this.board[x][y].charAt(1);
// 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;
+ let i = y;
do {
if (
(!castleInCheck && this.isAttacked([x, i], oppCol)) ||
this.board[rx][ry] != V.EMPTY &&
this.getPiece(rx, ry) == piece &&
this.getColor(rx, ry) == color &&
- this.canTake([rx, ry], [x, y])
+ this.canTake([rx, ry], [x, y]) //for Paco-Sako (TODO: necessary?)
) {
return true;
}
}
updateCastleFlags(move, piece, color) {
+ // TODO: check flags. If already off, no need to always re-evaluate
const c = color || V.GetOppCol(this.turn);
const firstRank = (c == "w" ? V.size.x - 1 : 0);
// Update castling flags if rooks are moved