]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.h
Introduce distance() and unify some API
[stockfish] / src / bitboard.h
index 7330a199e1fba11a416da7a37fe379f543eaa9de..7c4a55f00f4a98b9d864b5c924d3a837951d476c 100644 (file)
@@ -22,6 +22,7 @@
 #define BITBOARD_H_INCLUDED
 
 #include <string>
+
 #include "types.h"
 
 namespace Bitboards {
@@ -56,8 +57,6 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5);
 const Bitboard Rank7BB = Rank1BB << (8 * 6);
 const Bitboard Rank8BB = Rank1BB << (8 * 7);
 
-CACHE_LINE_ALIGNMENT
-
 extern Bitboard RMasks[SQUARE_NB];
 extern Bitboard RMagics[SQUARE_NB];
 extern Bitboard* RAttacks[SQUARE_NB];
@@ -113,17 +112,12 @@ inline bool more_than_one(Bitboard b) {
   return b & (b - 1);
 }
 
-inline int square_distance(Square s1, Square s2) {
-  return SquareDistance[s1][s2];
-}
-
-inline int file_distance(Square s1, Square s2) {
-  return abs(file_of(s1) - file_of(s2));
-}
+template<typename T> inline int distance(T x, T y) { return x < y ? y - x : x - y; }
+template<> inline int distance<Square>(Square x, Square y) { return SquareDistance[x][y]; }
 
-inline int rank_distance(Square s1, Square s2) {
-  return abs(rank_of(s1) - rank_of(s2));
-}
+template<typename T1, typename T2> inline int distance(T2 x, T2 y);
+template<> inline int distance<File>(Square x, Square y) { return distance(file_of(x), file_of(y)); }
+template<> inline int distance<Rank>(Square x, Square y) { return distance(rank_of(x), rank_of(y)); }
 
 
 /// shift_bb() moves bitboard one step along direction Delta. Mainly for pawns.