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
3 #include "bit.hpp"
4 #include "bitboard.hpp"
5 #include "utils.hpp"
7 #include <array>
9 namespace attack {
10 namespace king {
12 static constexpr U64 mask(const Square square) {
13 U64 bitboard = C64(0), attacks = C64(0);
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);
22 return attacks;
23 }
25 typedef std::array<U64, 64> attack_array;
26 const attack_array attacks = []() -> attack_array {
27 std::array<U64, 64> attacks;
29 for (Square square = Square::a1; square <= Square::h8; ++square) {
30 attacks[square] = mask(square);
31 }
33 return attacks;
34 }();
36 inline constexpr U64 attack(const Square square) { return attacks[square]; }
38 } // namespace king
39 } // namespace attack
41 #endif