stellar

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

slider.hpp (1023B)


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