From: Fabian Fichter Date: Sat, 1 May 2021 20:23:01 +0000 (+0200) Subject: Simplify rider type assertions X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=a9f51cdda59245afa0fb29a8f6ee898cfa80d0b7;p=fairystockfish.git Simplify rider type assertions No functional change. --- diff --git a/src/bitboard.h b/src/bitboard.h index 15ebc79..2ac5f5a 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -386,9 +386,7 @@ inline int edge_distance(Rank r, Rank maxRank = RANK_8) { return std::min(r, Ran template inline Bitboard rider_attacks_bb(Square s, Bitboard occupied) { - assert(R == RIDER_BISHOP || R == RIDER_ROOK_H || R == RIDER_ROOK_V || R == RIDER_CANNON_H || R == RIDER_CANNON_V - || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER - || R == RIDER_GRASSHOPPER_H || R == RIDER_GRASSHOPPER_V || R == RIDER_GRASSHOPPER_D); + static_assert(R != NO_RIDER && !(R & (R - 1))); // exactly one bit const Magic& m = R == RIDER_ROOK_H ? RookMagicsH[s] : R == RIDER_ROOK_V ? RookMagicsV[s] : R == RIDER_CANNON_H ? CannonMagicsH[s] @@ -409,9 +407,7 @@ inline Square lsb(Bitboard b); inline Bitboard rider_attacks_bb(RiderType R, Square s, Bitboard occupied) { - assert(R == RIDER_BISHOP || R == RIDER_ROOK_H || R == RIDER_ROOK_V || R == RIDER_CANNON_H || R == RIDER_CANNON_V - || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER - || R == RIDER_GRASSHOPPER_H || R == RIDER_GRASSHOPPER_V || R == RIDER_GRASSHOPPER_D); + assert(R != NO_RIDER && !(R & (R - 1))); // exactly one bit const Magic& m = magics[lsb(R)][s]; // re-use Bitboard lsb for riders return m.attacks[m.index(occupied)]; } diff --git a/src/types.h b/src/types.h index a3ae1fd..a2ea3b9 100644 --- a/src/types.h +++ b/src/types.h @@ -564,11 +564,11 @@ inline Value mg_value(Score s) { return Value(mg.s); } -#define ENABLE_BIT_OPERATORS_ON(T) \ -inline T operator~ (T d) { return (T)~(int)d; } \ -inline T operator| (T d1, T d2) { return (T)((int)d1 | (int)d2); } \ -inline T operator& (T d1, T d2) { return (T)((int)d1 & (int)d2); } \ -inline T operator^ (T d1, T d2) { return (T)((int)d1 ^ (int)d2); } \ +#define ENABLE_BIT_OPERATORS_ON(T) \ +constexpr T operator~ (T d) { return (T)~(int)d; } \ +constexpr T operator| (T d1, T d2) { return (T)((int)d1 | (int)d2); } \ +constexpr T operator& (T d1, T d2) { return (T)((int)d1 & (int)d2); } \ +constexpr T operator^ (T d1, T d2) { return (T)((int)d1 ^ (int)d2); } \ inline T& operator|= (T& d1, T d2) { return (T&)((int&)d1 |= (int)d2); } \ inline T& operator&= (T& d1, T d2) { return (T&)((int&)d1 &= (int)d2); } \ inline T& operator^= (T& d1, T d2) { return (T&)((int&)d1 ^= (int)d2); }