Simplify rider type assertions
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 20:23:01 +0000 (22:23 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 20:23:01 +0000 (22:23 +0200)
No functional change.

src/bitboard.h
src/types.h

index 15ebc79..2ac5f5a 100644 (file)
@@ -386,9 +386,7 @@ inline int edge_distance(Rank r, Rank maxRank = RANK_8) { return std::min(r, Ran
 template<RiderType R>
 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)];
 }
index a3ae1fd..a2ea3b9 100644 (file)
@@ -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); }