-inline Bitboard squares_between(Square s1, Square s2) {
- return BetweenBB[s1][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]; }
+
+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)); }
+
+
+/// Magic holds all magic relevant data for a single square
+struct Magic {
+
+ Bitboard mask;
+ Bitboard magic;
+ Bitboard* attacks;
+ unsigned shift;
+};
+
+/// attacks_bb() returns a bitboard representing all the squares attacked by a
+/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
+/// looks up the index using the 'magic bitboards' approach.
+template<PieceType Pt>
+inline unsigned magic_index(Square s, Bitboard occupied) {
+
+ extern Magic RookMagics[SQUARE_NB];
+ extern Magic BishopMagics[SQUARE_NB];