UNPKG

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