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-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+ Copyright (C) 2015-2019 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
extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard FileBB[FILE_NB];
extern Bitboard RankBB[RANK_NB];
-extern Bitboard AdjacentFilesBB[FILE_NB];
extern Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
inline Bitboard operator&(Bitboard b, Square s) {
+ assert(s >= SQ_A1 && s <= SQ_H8);
return b & SquareBB[s];
}
inline Bitboard operator|(Bitboard b, Square s) {
+ assert(s >= SQ_A1 && s <= SQ_H8);
return b | SquareBB[s];
}
inline Bitboard operator^(Bitboard b, Square s) {
+ assert(s >= SQ_A1 && s <= SQ_H8);
return b ^ SquareBB[s];
}
inline Bitboard& operator|=(Bitboard& b, Square s) {
+ assert(s >= SQ_A1 && s <= SQ_H8);
return b |= SquareBB[s];
}
inline Bitboard& operator^=(Bitboard& b, Square s) {
+ assert(s >= SQ_A1 && s <= SQ_H8);
return b ^= SquareBB[s];
}
return b & (b - 1);
}
+inline bool opposite_colors(Square s1, Square s2) {
+ return bool(DarkSquares & s1) != bool(DarkSquares & s2);
+}
+
/// rank_bb() and file_bb() return a bitboard representing all the squares on
/// the given file or rank.
}
-/// make_bitboard() returns a bitboard from a list of squares
-
-constexpr Bitboard make_bitboard() { return 0; }
-
-template<typename ...Squares>
-constexpr Bitboard make_bitboard(Square s, Squares... squares) {
- return (1ULL << s) | make_bitboard(squares...);
-}
-
-
/// shift() moves a bitboard one step along direction D (mainly for pawns)
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
+ : D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
+ : D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
+ : D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
: 0;
}
}
+/// double_pawn_attacks_bb() returns the pawn attacks for the given color
+/// from the squares in the given bitboard.
+
+template<Color C>
+constexpr Bitboard double_pawn_attacks_bb(Bitboard b) {
+ return C == WHITE ? shift<NORTH_WEST>(b) & shift<NORTH_EAST>(b)
+ : shift<SOUTH_WEST>(b) & shift<SOUTH_EAST>(b);
+}
+
+
/// adjacent_files_bb() returns a bitboard representing all the squares on the
/// adjacent files of the given one.
inline Bitboard adjacent_files_bb(File f) {
- return AdjacentFilesBB[f];
+ return shift<EAST>(FileBB[f]) | shift<WEST>(FileBB[f]);
}