stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE | |
knight.hpp (1322B)
1 #ifndef STELLAR_ATTACK_KNIGHT_H 2 #define STELLAR_ATTACK_KNIGHT_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 knight { 13 14 static constexpr U64 mask(const square::Square square) { 15 U64 bitboard = C64(0), attacks = C64(0), tmp; 16 17 bit::set(bitboard, to_underlying(square)); 18 tmp = bitboard::nortOne(bitboard::nortOne(bitboard)); 19 attacks |= bitboard::westOne(tmp) | bitboard::eastOne(tmp); 20 tmp = bitboard::soutOne(bitboard::soutOne(bitboard)); 21 attacks |= bitboard::westOne(tmp) | bitboard::eastOne(tmp); 22 tmp = bitboard::westOne(bitboard::westOne(bitboard)); 23 attacks |= bitboard::soutOne(tmp) | bitboard::nortOne(tmp); 24 tmp = bitboard::eastOne(bitboard::eastOne(bitboard)); 25 attacks |= bitboard::soutOne(tmp) | bitboard::nortOne(tmp); 26 27 return attacks; 28 } 29 30 typedef std::array<U64, 64> attack_array; 31 const attack_array attacks = []() -> attack_array { 32 std::array<U64, 64> attacks; 33 for (uint8_t square = 0; square < 64; square++) 34 attacks[square] = mask(static_cast<square::Square>(square)); 35 return attacks; 36 }(); 37 38 inline constexpr U64 attack(const square::Square square, U64 occupancy) { 39 return attacks[to_underlying(square)]; 40 } 41 42 } // namespace knight 43 } // namespace attack 44 45 #endif