-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitboards.c
49 lines (40 loc) · 1.01 KB
/
bitboards.c
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
#include "stdio.h"
#include "defs.h"
const int BitTable[64] = {
63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
58, 20, 37, 17, 36, 8
};
int PopBit(U64 *bb) {
U64 b = *bb ^ (*bb - 1);
unsigned int fold = (unsigned) ((b & 0xffffffff) ^ (b >> 32));
*bb &= (*bb - 1);
return BitTable[(fold * 0x783a9b23) >> 26];
}
int CountBits(U64 b) {
int r;
for(r = 0; b; r++, b &= b - 1);
return r;
}
void printBitBoard (U64 bb) {
U64 shiftMe = ONE64;
int rank = 0;
int file = 0;
int sq = 0;
int sq64 = 0;
printf("\n");
//printing bitboard starting backwards, so to make white at bottom
for(rank = RANK_8; rank >= RANK_1; --rank) {
for(file = FILE_A; file <= FILE_H; ++file) {
sq = FRtoSQ(file,rank);
sq64 = SQ64(sq);
if((shiftMe << sq64) & bb)
printf("X");
else
printf("-");
}
printf("\n");
}
printf("\n\n");
}