stellar

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

king.hpp (1102B)


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