stellar

UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE |

slider.hpp (1023B)


1 #ifndef STELLAR_ATTAKC_SLIDER_H 2 #define STELLAR_ATTAKC_SLIDER_H 3 4 #include "square.hpp" 5 #include "utils.hpp" 6 7 namespace attack { 8 namespace slider { 9 10 inline constexpr U64 occupancy(U64 index, uint8_t bits_in_mask, U64 attack_mask) { 11 U64 occupancy = C64(0); 12 13 for (uint8_t count = 0; count < bits_in_mask; count++) { 14 uint8_t square = bit::lsb_index(attack_mask); 15 bit::lsb_pop(attack_mask); 16 17 if (bit::get(index, count)) bit::set(occupancy, square); 18 } 19 20 return occupancy; 21 } 22 23 inline constexpr U64 mask(const square::Square square, U64 block, const bitboard::direction_f dir[4], 24 const int len[4]) { 25 U64 bitboard = C64(0), attacks = C64(0); 26 bit::set(bitboard, to_underlying(square)); 27 for (int i = 0; i < 4; i++) { 28 U64 tmp = bitboard; 29 for (int j = 0; j < len[i]; j++) { 30 attacks |= tmp = (dir[i])(tmp); 31 if (tmp & block) break; 32 } 33 } 34 return attacks; 35 } 36 37 } // namespace slider 38 } // namespace attack 39 #endif