-
Notifications
You must be signed in to change notification settings - Fork 0
/
magic.h
67 lines (51 loc) · 1.81 KB
/
magic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef MAGIC_H_
#define MAGIC_H_
#include "board.h"
typedef unsigned long long ull;
// pregenerated line/ column bitboards
extern const ull lbb[8], cbb[8];
// magic bitboards
extern ull magicmovesndb[64];
extern ull magicmoveskdb[64];
extern const ull magicmoves_r_magics[64];
extern const ull magicmoves_r_mask[64];
extern const ull magicmoves_b_magics[64];
extern const ull magicmoves_b_mask[64];
#define MINIMAL_B_BITS_SHIFT 55
#define MINIMAL_R_BITS_SHIFT 52
extern ull magicmovesbdb[64][1<<9];
extern ull magicmovesrdb[64][1<<12];
inline ull Nmagic(const unsigned int square)
{
return magicmovesndb[square];
}
inline ull Kmagic(const unsigned int square)
{
return magicmoveskdb[square];
}
inline ull Bmagic(const unsigned int square, const ull occupancy)
{
return magicmovesbdb[square][((occupancy & magicmoves_b_mask[square]) * magicmoves_b_magics[square]) >> MINIMAL_B_BITS_SHIFT];
}
inline ull BmagicNOMASK(const unsigned int square, const ull occupancy)
{
return magicmovesbdb[square][(occupancy * magicmoves_b_magics[square]) >> MINIMAL_B_BITS_SHIFT];
}
inline ull Rmagic(const unsigned int square, const ull occupancy)
{
return magicmovesrdb[square][((occupancy & magicmoves_r_mask[square]) * magicmoves_r_magics[square]) >> MINIMAL_R_BITS_SHIFT];
}
inline ull RmagicNOMASK(const unsigned int square, const ull occupancy)
{
return magicmovesrdb[square][(occupancy * magicmoves_r_magics[square]) >> MINIMAL_R_BITS_SHIFT];
}
inline ull Qmagic(const unsigned int square, const ull occupancy)
{
return Bmagic(square, occupancy) | Rmagic(square, occupancy);
}
inline ull QmagicNOMASK(const unsigned int square, const ull occupancy)
{
return BmagicNOMASK(square, occupancy) | RmagicNOMASK(square, occupancy);
}
void initmagicmoves(void);
#endif // MAGIC_H_