-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrays.cpp
More file actions
31 lines (27 loc) · 719 Bytes
/
rays.cpp
File metadata and controls
31 lines (27 loc) · 719 Bytes
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
#include "rays.h"
Bitboard Rays[8][64];
static bool inited = false;
static void buildRay(int dir, int sq, int dr, int df) {
int r = sq / 8, f = sq % 8;
Bitboard b = 0;
r += dr; f += df;
while (r >= 0 && r < 8 && f >= 0 && f < 8) {
b |= 1ULL << (r*8 + f);
r += dr; f += df;
}
Rays[dir][sq] = b;
}
void initRays() {
if (inited) return;
for (int sq = 0; sq < 64; ++sq) {
buildRay(N, sq, +1, 0);
buildRay(S, sq, -1, 0);
buildRay(E, sq, 0, +1);
buildRay(W, sq, 0, -1);
buildRay(NE, sq, +1, +1);
buildRay(NW, sq, +1, -1);
buildRay(SE, sq, -1, +1);
buildRay(SW, sq, -1, -1);
}
inited = true;
}