chess-legal-moves
Version:
Analyses a given chess game position in Fen notation to return legal moves and provides the next game position after a given move
43 lines (42 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateAvailableCastlings = exports.toggleHasToPlay = exports.incrementHalfMoveClock = exports.incrementFullMoveClock = exports.updateFenBoard = exports.isCapture = exports.isPawn = void 0;
function isPawn(piece) {
return ['p', 'P'].includes(piece);
}
exports.isPawn = isPawn;
function isCapture(piece, destination) {
if (destination === '.')
return false;
var isMoveColorWhite = piece === piece.toUpperCase();
var isDestinationColorWhite = destination === destination.toUpperCase();
return isMoveColorWhite !== isDestinationColorWhite;
}
exports.isCapture = isCapture;
function updateFenBoard(fenBoard) {
return fenBoard;
}
exports.updateFenBoard = updateFenBoard;
function incrementFullMoveClock(fullMoveClock) {
return fullMoveClock + 1;
}
exports.incrementFullMoveClock = incrementFullMoveClock;
function incrementHalfMoveClock(halfMoveClock) {
return halfMoveClock + 1;
}
exports.incrementHalfMoveClock = incrementHalfMoveClock;
function toggleHasToPlay(hasToPlay) {
return hasToPlay === 'w' ? 'b' : 'w';
}
exports.toggleHasToPlay = toggleHasToPlay;
function updateAvailableCastlings(availableCastlings, castlingLetter) {
var isWhiteCastling = castlingLetter.toUpperCase() === castlingLetter;
if (isWhiteCastling)
availableCastlings = availableCastlings.replace('KQ', '');
else
availableCastlings = availableCastlings.replace('kq', '');
if (availableCastlings.length === 0)
availableCastlings = '-';
return availableCastlings;
}
exports.updateAvailableCastlings = updateAvailableCastlings;