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.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateEastAttacks = void 0;
var moveHelpers_1 = require("../../moveHelpers");
var rays_1 = require("../rays");
/**
* Populates an array of 64 IRayAttacks objects with east attacks
* @param attacksList an IRayAttack array of directional attacks
* @returns attacksList populated with east attacks
*/
function generateEastAttacks(attacksList) {
/**************
* 8 ........ *
* 7 ........ *
* 6 ........ *
* 5 ........ *
* 4 ........ *
* 3 ........ *
* 2 ........ *
* 1 x1111111 * -- B1_H1
* ABCDEFGH
*************/
// B1_H1 east attack mask is used as a placeholder to be slid on each square
var eastAttackMask = rays_1.RAYS.B1_H1;
// Loop through each file of the board: A, B, ... G, H
// at the end of each loop, slide the mask to the right for the next iteration
for (var file = 0; file < 8; file++) {
// Set temporary east mask to be used by the following for loop
var east = eastAttackMask;
// 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 east property
attacksList[square + file].ea = east;
east = (0, moveHelpers_1.slideUp)(east);
}
eastAttackMask = (0, moveHelpers_1.removeLowestBit)(eastAttackMask);
}
return attacksList;
}
exports.generateEastAttacks = generateEastAttacks;