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
42 lines (41 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateWestAttacks = void 0;
var moveHelpers_1 = require("../../moveHelpers");
var rays_1 = require("../rays");
/**
* Populates an array of 64 IRayAttacks objects with west attacks
* @param attacksList an IRayAttack array of directional attacks
* @returns attacksList populated with west attacks
*/
function generateWestAttacks(attacksList) {
/**************
* 8 ........ *
* 7 ........ *
* 6 ........ *
* 5 ........ *
* 4 ........ *
* 3 ........ *
* 2 ........ *
* 1 1111111x * -- G1_A1
* ABCDEFGH
*************/
// G1_A1 west attack mask is used as a placeholder to be slid on each square
var westAttackMask = rays_1.RAYS.G1_A1;
// Loop through each file of the board: H, G, ... B, A
// at the end of each loop, slide the mask to the left for the next iteration
for (var file = 7; file >= 0; file--) {
// Set temporary west mask to be used by the following for loop
var west = westAttackMask;
// Loop through each square (from bottom to top) on the current file
// at the end of each loop, slide the mask to the top for the next iteration
for (var square = 0; square < 8 * 8; square += 8) {
// populate each attacksList square west property
attacksList[square + file].we = west;
west = (0, moveHelpers_1.slideUp)(west);
}
westAttackMask = (0, moveHelpers_1.removeHighestBit)(westAttackMask);
}
return attacksList;
}
exports.generateWestAttacks = generateWestAttacks;