stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE |
king.hpp (1191B)
0 #ifndef STELLAR_ATTACK_KING_H
1 #define STELLAR_ATTACK_KING_H
3 #include "bit.hpp"
4 #include "bitboard.hpp"
5 #include "square.hpp"
6 #include "utils.hpp"
8 #include <array>
10 namespace attack {
11 namespace king {
13 static constexpr U64 mask(const square::Square square) {
14 U64 bitboard = C64(0), attacks = C64(0);
16 bit::set(bitboard, to_underlying(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);
23 return attacks;
24 }
26 typedef std::array<U64, 64> attack_array;
27 const attack_array attacks = []() -> attack_array {
28 std::array<U64, 64> attacks;
29 for (uint8_t square = 0; square < 64; square++)
30 attacks[square] = mask(static_cast<square::Square>(square));
31 return attacks;
32 }();
34 inline constexpr U64 attack(const square::Square square, U64 occupancy) {
35 return attacks[to_underlying(square)];
36 }
38 } // namespace king
39 } // namespace attack
41 #endif