Make init_magic() piece agnostic

All the piece dependant data is passed now as
function arguments so that the code is exactly
the same for bishop and rook.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2012-01-15 08:24:50 +01:00
parent 20621ed3e3
commit dfd030b67a
2 changed files with 40 additions and 42 deletions

View File

@@ -140,33 +140,34 @@ inline Bitboard in_front_bb(Color c, Square s) {
#if defined(IS_64BIT)
FORCE_INLINE unsigned rook_index(Square s, Bitboard occ) {
FORCE_INLINE unsigned r_index(Square s, Bitboard occ) {
return unsigned(((occ & RMasks[s]) * RMagics[s]) >> RShifts[s]);
}
FORCE_INLINE unsigned bishop_index(Square s, Bitboard occ) {
FORCE_INLINE unsigned b_index(Square s, Bitboard occ) {
return unsigned(((occ & BMasks[s]) * BMagics[s]) >> BShifts[s]);
}
#else // if !defined(IS_64BIT)
FORCE_INLINE unsigned rook_index(Square s, Bitboard occ) {
FORCE_INLINE unsigned r_index(Square s, Bitboard occ) {
Bitboard b = occ & RMasks[s];
return unsigned(int(b) * int(RMagics[s]) ^ int(b >> 32) * int(RMagics[s] >> 32)) >> RShifts[s];
}
FORCE_INLINE unsigned bishop_index(Square s, Bitboard occ) {
FORCE_INLINE unsigned b_index(Square s, Bitboard occ) {
Bitboard b = occ & BMasks[s];
return unsigned(int(b) * int(BMagics[s]) ^ int(b >> 32) * int(BMagics[s] >> 32)) >> BShifts[s];
}
#endif
inline Bitboard rook_attacks_bb(Square s, Bitboard occ) {
return RAttacks[s][rook_index(s, occ)];
return RAttacks[s][r_index(s, occ)];
}
inline Bitboard bishop_attacks_bb(Square s, Bitboard occ) {
return BAttacks[s][bishop_index(s, occ)];
return BAttacks[s][b_index(s, occ)];
}