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.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSouthEastAttacks = void 0;
var moveHelpers_1 = require("../../moveHelpers");
var rays_1 = require("../rays");
/**
* Populates an array of 64 IRayAttacks objects with south-east attacks
* @param attacksList an IRayAttack array of directional attacks
* @returns attacksList populated with south-east attacks
*/
function generateSouthEastAttacks(attacksList) {
/**************
* 8 x....... *
* 7 .1...... *
* 6 ..1..... *
* 5 ...1.... *
* 4 ....1... *
* 3 .....1.. *
* 2 ......1. *
* 1 .......1 * -- B7_H1
* ABCDEFGH *
*************/
// B7_H1 south-east attack mask is used as a placeholder to be slid on each square
var southEastAttackMask = rays_1.RAYS.B7_H1;
// Loop through each file of the board: H, G, ... B, A
// at the end of each loop, slide the mask up and remove the highest bit for the next iteration
for (var file = 7; file >= 0; file--) {
// Set temporary south-east mask to be used by the following for loop
var southEast = southEastAttackMask;
// Loop through each square (from top to bottom) on the current file
// at the end of each loop, slide down the mask for the next iteration
for (var square = 63; square >= 0; square -= 8) {
// populate each attacksList square south-east property
attacksList[square - file].soEa = southEast;
southEast = (0, moveHelpers_1.slideDown)(southEast);
}
southEastAttackMask = (0, moveHelpers_1.slideUp)(southEastAttackMask);
southEastAttackMask = (0, moveHelpers_1.removeHighestBit)(southEastAttackMask);
}
return attacksList;
}
exports.generateSouthEastAttacks = generateSouthEastAttacks;