Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
- Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+ Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
+const Bitboard AllSquares = ~Bitboard(0);
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
const Bitboard FileABB = 0x0101010101010101ULL;
Bitboard* attacks;
unsigned shift;
- /// looks up the index using the 'magic bitboards' approach.
+ // Compute the attack's index using the 'magic bitboards' approach
unsigned index(Bitboard occupied) const {
- if (HasPext)
- return unsigned(pext(occupied, mask));
+ if (HasPext)
+ return unsigned(pext(occupied, mask));
- if (Is64Bit)
- return unsigned(((occupied & mask) * magic) >> shift);
+ if (Is64Bit)
+ return unsigned(((occupied & mask) * magic) >> shift);
- unsigned lo = unsigned(occupied) & unsigned(mask);
- unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
- return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
+ unsigned lo = unsigned(occupied) & unsigned(mask);
+ unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
+ return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
}
};
return b ^= SquareBB[s];
}
-inline bool more_than_one(Bitboard b) {
+constexpr bool more_than_one(Bitboard b) {
return b & (b - 1);
}
-
/// rank_bb() and file_bb() return a bitboard representing all the squares on
/// the given file or rank.
/// shift() moves a bitboard one step along direction D. Mainly for pawns
-template<Square D>
-inline Bitboard shift(Bitboard b) {
+template<Direction D>
+constexpr Bitboard shift(Bitboard b) {
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
template<PieceType Pt>
inline Bitboard attacks_bb(Square s, Bitboard occupied) {
- const Magic& M = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
- return M.attacks[M.index(occupied)];
+ const Magic& m = Pt == ROOK ? RookMagics[s] : BishopMagics[s];
+ return m.attacks[m.index(occupied)];
}
inline Bitboard attacks_bb(PieceType pt, Square s, Bitboard occupied) {