-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitboards.c
More file actions
47 lines (40 loc) · 1.13 KB
/
bitboards.c
File metadata and controls
47 lines (40 loc) · 1.13 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
46
47
#include "bitboards.h"
#include <stdio.h>
//magic pawn
const int pawnMagics[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(uint64_t *bb) {
uint64_t b = *bb ^ (*bb - 1);
unsigned int fold = (unsigned) ((b & 0xffffffff) ^ (b >> 32));
*bb &= (*bb - 1);
return pawnMagics[(fold * 0x783a9b23) >> 26];
}
int countBits(uint64_t b) {
int r;
for(r = 0; b; r++, b &= b - 1);
return r;
}
void printBitboard(uint64_t bb) {
uint64_t shiftMe = 1ULL;
int rank = 0;
int file = 0;
int sq = 0;
int sq64 = 0;
printf("\n");
for(rank= RANK_8; rank >= RANK_1; rank--) {
for(file = FILE_A; file <= FILE_H; file++) {
sq = FR2SQ(file,rank);
sq64 = SQ64(sq);
if((shiftMe << sq64) & bb)
printf("X");
else
printf("-");
}
printf("\n");
}
printf("\n\n");
}