stellar

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

pawn.hpp (1021B)


      1 #ifndef STELLAR_ATTACK_PAWN_H
      2 #define STELLAR_ATTACK_PAWN_H
      3 
      4 #include "bit.hpp"
      5 #include "bitboard.hpp"
      6 #include "utils.hpp"
      7 
      8 #include <array>
      9 
     10 namespace attack {
     11 namespace pawn {
     12 
     13 static constexpr U64 mask_white(const Square square) {
     14     U64 bitboard = C64(0);
     15 
     16     bit::set(bitboard, square);
     17     return bitboard::noWeOne(bitboard) | bitboard::noEaOne(bitboard);
     18 }
     19 
     20 static constexpr U64 mask_black(const Square square) {
     21     U64 bitboard = C64(0);
     22 
     23     bit::set(bitboard, square);
     24     return bitboard::soWeOne(bitboard) | bitboard::soEaOne(bitboard);
     25 }
     26 
     27 typedef std::array<std::array<U64, 64>, 2> attack_array;
     28 const auto attacks = []() {
     29     attack_array attacks;
     30 
     31     for (Square square = Square::a1; square <= Square::h8; ++square) {
     32         attacks[WHITE][square] = mask_white(square);
     33         attacks[BLACK][square] = mask_black(square);
     34     }
     35 
     36     return attacks;
     37 }();
     38 
     39 inline constexpr U64 attack(Color color, Square square) { return attacks[color][square]; }
     40 
     41 } // namespace pawn
     42 } // namespace attack
     43 
     44 #endif