stellar

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

slider.hpp (1021B)


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