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.generateNorthWestAttacks = void 0;
var moveHelpers_1 = require("../../moveHelpers");
var rays_1 = require("../rays");
/**
* Populates an array of 64 IRayAttacks objects with north-west attacks
* @param attacksList an IRayAttack array of directional attacks
* @returns attacksList populated with north-west attacks
*/
function generateNorthWestAttacks(attacksList) {
/**************
* 8 1....... *
* 7 .1...... *
* 6 ..1..... *
* 5 ...1.... *
* 4 ....1... *
* 3 .....1.. *
* 2 ......1. *
* 1 .......x * -- G2_A8
* ABCDEFGH
*************/
// G2_A8 north-west attack mask is used as a placeholder to be slid on each square
var northWestAttackMask = rays_1.RAYS.G2_A8;
// Loop through each file of the board: H, G, ... B, A
// at the end of each loop, slide the mask down and remove the lowest bit for the next iteration
for (var file = 7; file >= 0; file--) {
// Set temporary north-west mask to be used by the following for loop
var northWest = northWestAttackMask;
// Loop through each square (from bottom to top) on the current file
// at the end of each loop, slide up the mask for the next iteration
for (var square = 0; square < 8 * 8; square += 8) {
// populate each attacksList square north-west property
attacksList[square + file].noWe = northWest;
northWest = (0, moveHelpers_1.slideUp)(northWest);
}
northWestAttackMask = (0, moveHelpers_1.slideDown)(northWestAttackMask);
northWestAttackMask = (0, moveHelpers_1.removeLowestBit)(northWestAttackMask);
}
return attacksList;
}
exports.generateNorthWestAttacks = generateNorthWestAttacks;