stellar

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

knight.hpp (1233B)


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