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
41 lines (40 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function generateMSBTable(max) {
var res = [];
var int;
for (int = 1; int <= max; int++) {
res[int] = Math.floor(Math.log2(int));
}
return res;
}
var mostSigBitTable = generateMSBTable(255);
function popCount32(int) {
int -= (int >>> 1) & 0x55555555;
int = (int & 0x33333333) + ((int >>> 2) & 0x33333333);
return (((int + (int >>> 4)) & 0xf0f0f0f) * 0x1010101) >>> 24;
}
function bitScanForward32(int) {
return popCount32((int & -int) - 1);
}
function bitScanReverse32(int) {
var res = 0;
if (int > 0xffff) {
int >>>= 16;
res += 16;
}
if (int > 0xff) {
int >>>= 8;
res += 8;
}
return res + mostSigBitTable[int];
}
function clearLeastSigBit32(int) {
return int & (int - 1);
}
exports.default = {
popCount32: popCount32,
bitScanForward32: bitScanForward32,
bitScanReverse32: bitScanReverse32,
clearLeastSigBit32: clearLeastSigBit32,
};