#pragma once

#include "types.h"

// rook/bishop relevant occupancy masks
extern u64 rookRelOcc[64];
extern u64 bishopRelOcc[64];
// rook/bishop magic shr
extern i8 rookShr[64];
extern i8 bishopShr[64];
// rook/bishop magic pointers
extern const u64 *rookPtr[64];
extern const u64 *bishopPtr[64];
// rook/bishop magic multipliers
extern const u64 rookMagic[64];
extern const u64 bishopMagic[64];

void bitMagicInit();

// mask: block mask
inline u64 rookAttm( u8 sq, const u64 &mask )
{
    return rookPtr[ sq ][ rookMagic[ sq ] * (mask & rookRelOcc[ sq ]) >> rookShr[ sq ] ];
}

// mask: block mask
inline u64 bishopAttm( u8 sq, const u64 &mask )
{
    return bishopPtr[ sq ][ bishopMagic[ sq ] * (mask & bishopRelOcc[ sq ]) >> bishopShr[ sq ] ];
}

// mask: block mask
inline u64 queenAttm( u8 sq, const u64 &mask )
{
    return rookAttm( sq, mask ) | bishopAttm( sq, mask );
}
