-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattacker_table.cpp
More file actions
45 lines (43 loc) · 2.07 KB
/
attacker_table.cpp
File metadata and controls
45 lines (43 loc) · 2.07 KB
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
enum attacker_pieces : int { ap = 0x1, aP = 0x2, aN = 0x4, aB = 0x8, aR = 0x10, aQ = 0x20, aK = 0x40 };
int piece_to_attacker[] = { 0, ap, aN, aB, aR, aQ, aK, aP, aN, aB, aR, aQ, aK };
int attack_table[240] {
// 0, 0, 0, 0, 0, 0, 0, 0,
0x28, 0, 0, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0, 0, 0x28, 0,
0, 0x28, 0, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0, 0x28, 0, 0,
0, 0, 0x28, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0x28, 0, 0, 0,
0, 0, 0, 0x28, 0, 0, 0, 0x30,
0, 0, 0, 0x28, 0, 0, 0, 0,
0, 0, 0, 0, 0x28, 0, 0, 0x30,
0, 0, 0x28, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0x28, 0x4, 0x30,
0x4, 0x28, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0x4, 0x69, 0x70,
0x69, 0x4, 0, 0, 0, 0, 0, 0,
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x70, 0,
0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0,
0, 0, 0, 0, 0, 0x4, 0x6A, 0x70,
0x6A, 0x4, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0x28, 0x4, 0x30,
0x4, 0x28, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0x28, 0, 0, 0x30,
0, 0, 0x28, 0, 0, 0, 0, 0,
0, 0, 0, 0x28, 0, 0, 0, 0x30,
0, 0, 0, 0x28, 0, 0, 0, 0,
0, 0, 0x28, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0x28, 0, 0, 0,
0, 0x28, 0, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0, 0x28, 0, 0,
0x28, 0, 0, 0, 0, 0, 0, 0x30,
0, 0, 0, 0, 0, 0, 0x28, 0,
};
// calculate difference of squares for attack table
inline int square_diff(int attacker_sq, int defender_sq) {
return attacker_sq - defender_sq + 0x77;
}
// is piece-type attacking (potentially) defender square from attacker square
inline int square_attacked_by(int piece, int attacker_sq, int defender_sq) {
return (piece_to_attacker[piece] & attack_table[square_diff(attacker_sq, defender_sq)]) != 0;
}