stellar

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

king.hpp (1191B)


1 #ifndef STELLAR_ATTACK_KING_H 2 #define STELLAR_ATTACK_KING_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 king { 13 14 static constexpr U64 mask(const square::Square square) { 15 U64 bitboard = C64(0), attacks = C64(0); 16 17 bit::set(bitboard, to_underlying(square)); 18 attacks |= bitboard::westOne(bitboard) | bitboard::eastOne(bitboard); 19 attacks |= bitboard::soutOne(bitboard) | bitboard::nortOne(bitboard); 20 attacks |= bitboard::soutOne(bitboard) | bitboard::nortOne(bitboard); 21 attacks |= bitboard::soEaOne(bitboard) | bitboard::noEaOne(bitboard); 22 attacks |= bitboard::soWeOne(bitboard) | bitboard::noWeOne(bitboard); 23 24 return attacks; 25 } 26 27 typedef std::array<U64, 64> attack_array; 28 const attack_array attacks = []() -> attack_array { 29 std::array<U64, 64> attacks; 30 for (uint8_t square = 0; square < 64; square++) 31 attacks[square] = mask(static_cast<square::Square>(square)); 32 return attacks; 33 }(); 34 35 inline constexpr U64 attack(const square::Square square, U64 occupancy) { 36 return attacks[to_underlying(square)]; 37 } 38 39 } // namespace king 40 } // namespace attack 41 42 #endif