stellar

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

pawnw.hpp (856B)


      1 #ifndef STELLAR_ATTACK_PAWNW_H
      2 #define STELLAR_ATTACK_PAWNW_H
      3 
      4 #include "bit.hpp"
      5 #include "bitboard.hpp"
      6 #include "square.hpp"
      7 #include "utils.hpp"
      8 
      9 #include <array>
     10 
     11 namespace attack {
     12 namespace pawnw {
     13 
     14 static constexpr U64 mask(const square::Square square) {
     15     U64 bitboard = C64(0);
     16 
     17     bit::set(bitboard, to_underlying(square));
     18     return bitboard::noWeOne(bitboard) | bitboard::noEaOne(bitboard);
     19 }
     20 
     21 typedef std::array<U64, 64> attack_array;
     22 const attack_array attacks = []() -> attack_array {
     23     std::array<U64, 64> attacks;
     24     for (uint8_t square = 0; square < 64; square++)
     25         attacks[square] = mask(static_cast<square::Square>(square));
     26     return attacks;
     27 }();
     28 
     29 inline constexpr U64 attack(const square::Square square, U64 occupancy) {
     30     return attacks[to_underlying(square)];
     31 }
     32 
     33 } // namespace pawnw
     34 } // namespace attack
     35 
     36 #endif