-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.cpp
147 lines (127 loc) · 2.77 KB
/
init.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#define FROM(move) ((move) & (0x3f))
#define TO(move) ((move>>6) & (0x3f))
#define KILLED(move) ((move >> 12) & (0xf))
#define KING(move) ((move >> 16) & (1))
void BOARD::init()
{
bitboard[WHITE] = 0;
for (int i = 0; i <= 63; i++)
board[i] = EMPTY;
for (int i = 0; i <= 6; i+=2) {
bitboard[WHITE] |= (1 << i);
board[i] = WHITE;
}
for (int i = 9; i <= 15; i+=2) {
bitboard[WHITE] |= (1 << i);
board[i] = WHITE;
}
for (int i = 16; i <= 22; i+=2) {
bitboard[WHITE] |= (1 << i);
board[i] = WHITE;
}
bitboard[BLACK] = 0;
for (int i = 57; i <= 63; i+=2) {
bitboard[BLACK] |= ((bb)1 << i);
board[i] = BLACK;
}
for (int i = 48; i <= 54; i+=2) {
bitboard[BLACK] |= ((bb)1 << i);
board[i] = BLACK;
}
for (int i = 41; i <= 47; i+=2) {
bitboard[BLACK] |= ((bb)1 << i);
board[i] = BLACK;
}
ply = 0;
side = WHITE;
power[0]=1;
for(int i=1;i<64;i++)
power[i]=power[i-1]<<1;
bitboard[WHITE_KING]=0;
bitboard[BLACK_KING]=0;
}
void BOARD::printBoard() {
for (int k = 7; k >= 0; k--) {
for (int j = 0; j < 8; j++) {
int i = k * 8 + j;
if (board[i] == WHITE)
printf("W ");
else if (board[i] == BLACK)
printf("B ");
else if (board[i] == EMPTY)
printf(". ");
else if (board[i] == WHITE_KING)
printf("K ");
else if (board[i] == BLACK_KING)
printf("k ");
}
printf("\n");
}
printf("Side = %d\n",side);
}
void BOARD::printMove(int move) {
printf("from %d to %d killed %d\n", FROM(move), TO(move), KILLED(move));
}
void BOARD::printMoveList(vector<MOVE> &moveList) {
for (int i = 0; i < moveList.size(); i++) {
int move = moveList[i].move;
printMove(move);
}
}
void BOARD::printBitboard(bb a) {
for (int k = 7; k >= 0; k--) {
for (int j = 0; j < 8; j++) {
int i = k * 8 + j;
int bit = (a >> i) & 1;
printf("%d ", bit);
}
printf("\n");
}
}
void BOARD::checkState() {
printf("ply = %d\n", ply);
for (int i = 0; i < TOTAL_BITBOARD; i++) {
printf("bitboard #%d:\n", i);
printBitboard(bitboard[i]);
}
printf("side = %d\n", side);
}
void BOARD::parseFEN(char *s)
{
int pos=0;
int row=7;
for(int i=0;i<64;i++)
board[i]=EMPTY;
bitboard[WHITE]=bitboard[BLACK]=0;
for(int i=0;i<strlen(s);i++)
{
switch(s[i])
{
case 'D':board[row*8+pos]=WHITE;
bitboard[WHITE] |=((bb)1 << (row*8+pos));
pos++;
break;
case 'd':board[row*8+pos]=BLACK;
bitboard[BLACK] |=((bb)1 << (row*8+pos));
pos++;
break;
case ' ':break;
case 'W':side=WHITE;
break;
case 'B':side=BLACK;
break;
case 'K':board[row*8+pos] = WHITE_KING;
bitboard[WHITE_KING] |= ((bb)1 << (row*8+pos));
pos++;
break;
case 'k':board[row*8+pos] = BLACK_KING;
bitboard[BLACK_KING] |= ((bb)1 << (row*8+pos));
pos++;
break;
case '/':row--;
pos=0;
break;
default: pos+=s[i]-'0';
}
}
}