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
34 lines (33 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateNorthAttacks = void 0;
var rays_1 = require("../rays");
/**
* Populates an array of 64 IRayAttacks objects with north attacks
* @param attacksList an IRayAttack array of directional attacks
* @returns attacksList populated with north attacks
*/
function generateNorthAttacks(attacksList) {
/**************
* 8 1....... *
* 7 1....... *
* 6 1....... *
* 5 1....... *
* 4 1....... *
* 3 1....... *
* 2 1....... *
* 1 x....... *
* ABCDEFGH
*************/
// A2_A8 north attack mask is used as a placeholder to be slid on each square
var northAttackMask = rays_1.RAYS.A2_A8;
// Loop through each square of the board a1, a2, ... h7, h8
// populate each attacksList square north property
// slide the mask to the right for the next iteration
for (var square = 0; square < 64; square++) {
attacksList[square].no = northAttackMask;
northAttackMask = northAttackMask.shiftLeft(1);
}
return attacksList;
}
exports.generateNorthAttacks = generateNorthAttacks;