return false;
}
- // Some games are drawn unusually (bottomr right corner is black)
+ // Some games are drawn unusually (bottom right corner is black)
static get DarkBottomRight() {
return false;
}
// 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;
if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
else {
const num = parseInt(row[i], 10);
- if (isNaN(num)) return false;
+ if (isNaN(num) || num <= 0) return false;
sumElts += num;
}
}
// En-passant square, if any
getEpSquare(moveOrSquare) {
- if (!moveOrSquare) return undefined;
+ if (!moveOrSquare) return undefined; //TODO: necessary line?!
if (typeof moveOrSquare === "string") {
const square = moveOrSquare;
if (square == "-") return undefined;
}
// 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++) {
// MOVES GENERATION
// All possible moves from selected square
- getPotentialMovesFrom([x, y]) {
- switch (this.getPiece(x, y)) {
- case V.PAWN: return this.getPotentialPawnMoves([x, y]);
- case V.ROOK: return this.getPotentialRookMoves([x, y]);
- case V.KNIGHT: return this.getPotentialKnightMoves([x, y]);
- case V.BISHOP: return this.getPotentialBishopMoves([x, y]);
- case V.QUEEN: return this.getPotentialQueenMoves([x, y]);
- case V.KING: return this.getPotentialKingMoves([x, y]);
+ getPotentialMovesFrom(sq) {
+ switch (this.getPiece(sq[0], sq[1])) {
+ case V.PAWN: return this.getPotentialPawnMoves(sq);
+ case V.ROOK: return this.getPotentialRookMoves(sq);
+ case V.KNIGHT: return this.getPotentialKnightMoves(sq);
+ case V.BISHOP: return this.getPotentialBishopMoves(sq);
+ case V.QUEEN: return this.getPotentialQueenMoves(sq);
+ case V.KING: return this.getPotentialKingMoves(sq);
}
return []; //never reached
}
new PiPo({
x: ex,
y: ey,
- c: tr ? tr.c : initColor,
- p: tr ? tr.p : initPiece
+ c: !!tr ? tr.c : initColor,
+ p: !!tr ? tr.p : initPiece
})
],
vanish: [
// 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)) ||
}
if (
V.OnBoard(rx, ry) &&
+ this.board[rx][ry] != V.EMPTY &&
this.getPiece(rx, ry) == piece &&
- this.getColor(rx, ry) == color
+ this.getColor(rx, ry) == color &&
+ 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