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