From: Chris Cain Date: Tue, 6 Mar 2018 00:32:16 +0000 (+0100) Subject: Introduce variadic make_bitboard() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=3192b09fe0258ec7654aa2c13bbc17b8417e6964 Introduce variadic make_bitboard() Adds a helper function to make a bitboard from a list of squares. No functional change --- diff --git a/src/bitboard.h b/src/bitboard.h index cf948afc..9fc53ee7 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -150,7 +150,17 @@ inline Bitboard file_bb(Square s) { } -/// shift() moves a bitboard one step along direction D. Mainly for pawns +/// make_bitboard() returns a bitboard from a list of squares + +constexpr Bitboard make_bitboard() { return 0; } + +template +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 constexpr Bitboard shift(Bitboard b) { diff --git a/src/pawns.cpp b/src/pawns.cpp index 42819e14..29a98751 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -236,11 +236,13 @@ Entry* probe(const Position& pos) { template Value Entry::shelter_storm(const Position& pos, Square ksq) { - const Color Them = (Us == WHITE ? BLACK : WHITE); - const Bitboard ShelterMask = (Us == WHITE ? 1ULL << SQ_A2 | 1ULL << SQ_B3 | 1ULL << SQ_C2 | 1ULL << SQ_F2 | 1ULL << SQ_G3 | 1ULL << SQ_H2 - : 1ULL << SQ_A7 | 1ULL << SQ_B6 | 1ULL << SQ_C7 | 1ULL << SQ_F7 | 1ULL << SQ_G6 | 1ULL << SQ_H7); - const Bitboard StormMask = (Us == WHITE ? 1ULL << SQ_A3 | 1ULL << SQ_C3 | 1ULL << SQ_F3 | 1ULL << SQ_H3 - : 1ULL << SQ_A6 | 1ULL << SQ_C6 | 1ULL << SQ_F6 | 1ULL << SQ_H6); + constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Bitboard ShelterMask = + Us == WHITE ? make_bitboard(SQ_A2, SQ_B3, SQ_C2, SQ_F2, SQ_G3, SQ_H2) + : make_bitboard(SQ_A7, SQ_B6, SQ_C7, SQ_F7, SQ_G6, SQ_H7); + constexpr Bitboard StormMask = + Us == WHITE ? make_bitboard(SQ_A3, SQ_C3, SQ_F3, SQ_H3) + : make_bitboard(SQ_A6, SQ_C6, SQ_F6, SQ_H6); enum { BlockedByKing, Unopposed, BlockedByPawn, Unblocked };