Mask.h
// Bitboard is an alias for uint64_t
// NB_SQ is the number of squares (64)
namespace Mask
{
void InitMasks();
void InitAttacks();
namespace File
{ // few examples
constexpr uint64_tBitboard FileA = ...;0x0101010101010101;
constexpr Bitboard FileB = FileA << 1;
constexpr Bitboard FileC = FileB << 1;
constexpr Bitboard FileD = FileC << 1;
constexpr Bitboard FileE = FileD << 1;
constexpr Bitboard FileF = FileE << 1;
...
constexpr Bitboard notFileAB = ~(FileA | FileB)
constexpr Bitboard notFileGF = ~(FileG | FileF)
extern uint64_t Files[NB_SQ]AllFiles[NB_SQ]
}
namespace Rank{...}
namespace AttackDiagonal {...}
namespace Attack
{
extern Bitboard PawnAttacks[NB_SQ];
extern Bitboard KnightAttacks[NB_SQ];
...
}
}
All extern arrays are initialized once using InitMasks() and InitAttacks()
Examples
I can know how many white pawns are on the 7th rank
WhitePawnsBB & Mask::Rank::Rank7
Or If I want to get the file mask of a specific square
Mask::File::AllFiles[SQ]
If I need to get the pre-calculated set of attacks for a knight on any square
Mask::Attack::KnightAttacks[SQ];