stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE |
slider.hpp (1021B)
0 #ifndef STELLAR_ATTAKC_SLIDER_H
1 #define STELLAR_ATTAKC_SLIDER_H
3 #include "bit.hpp"
4 #include "bitboard.hpp"
5 #include "utils.hpp"
7 namespace attack {
8 namespace slider {
10 inline constexpr U64 occupancy(U64 index, uint8_t bits_in_mask, U64 attack_mask) {
11 U64 occupancy = C64(0);
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);
17 if (bit::get(index, count)) bit::set(occupancy, square);
18 }
20 return occupancy;
21 }
23 inline constexpr U64 mask(const 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, 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 }
37 } // namespace slider
38 } // namespace attack
39 #endif