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