-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbb.java
More file actions
296 lines (268 loc) · 5.77 KB
/
Copy pathbb.java
File metadata and controls
296 lines (268 loc) · 5.77 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* Bitboards:
* Bitboards are represented arrays of 64 booleans
* since Java doesn't support 64-bit unsigned longs
* We can preform bitwise operations on these boards
* by cycling through the 64 indices
*/
public class BB {
// MOVES: Also covers own pieces that are protected
public static boolean[] pTakesW = new boolean[64];
public static boolean[] pTakesB = new boolean[64];
public static boolean[] pMovesW = new boolean[64];
public static boolean[] pMovesB = new boolean[64];
public static boolean[] bMovesW = new boolean[64];
public static boolean[] bMovesB = new boolean[64];
public static boolean[] nMovesW = new boolean[64];
public static boolean[] nMovesB = new boolean[64];
public static boolean[] rMovesW = new boolean[64];
public static boolean[] rMovesB = new boolean[64];
public static boolean[] qMovesW = new boolean[64];
public static boolean[] qMovesB = new boolean[64];
public static boolean[] kMovesW = new boolean[64];
public static boolean[] kMovesB = new boolean[64];
// PIECES: Stored independent of colour for memory
public static boolean[] pawnsW = new boolean[64];
public static boolean[] pawnsB = new boolean[64];
public static boolean[] bishops = new boolean[64];
public static boolean[] knights = new boolean[64];
public static boolean[] rooks = new boolean[64];
public static boolean[] queens = new boolean[64];
public static boolean[] kings = new boolean[64];
public static boolean[] piecesW = new boolean[64];
public static boolean[] piecesB = new boolean[64];
// BOARD: Board properties for evaluation
public static boolean[] center()
{
boolean center[] = new boolean[64];
center[27] = true; center[28] = true;
center[35] = true; center[36] = true;
return center;
}
/*
public static boolean[] lightSq()
{
boolean ls[] = new boolean[64];
for (int i = 0; i < 32; i++)
ls[i*2] = true;
return ls;
}
public static boolean[] darkSq()
{
boolean ds[] = new boolean[64];
for (int i = 0; i < 32; i++)
ds[i*2 + 1] = true;
return ds;
}
*/
public static void getPieces()
{
for (int i=0; i<64; i++)
{
piecesW[i] = false;
piecesB[i] = false;
kings[i] = false;
queens[i] = false;
rooks[i] = false;
bishops[i] = false;
knights[i] = false;
pawnsW[i] = false;
pawnsB[i] = false;
switch (Board.chessBoard[i/8][i%8])
{
case "K":
kings[i] = true;
piecesW[i] = true;
break;
case "k":
kings[i] = true;
piecesB[i] = true;
break;
case "Q":
queens[i] = true;
piecesW[i] = true;
break;
case "q":
queens[i] = true;
piecesB[i] = true;
break;
case "R":
rooks[i] = true;
piecesW[i] = true;
break;
case "r":
rooks[i] = true;
piecesB[i] = true;
break;
case "B":
bishops[i] = true;
piecesW[i] = true;
break;
case "b":
bishops[i] = true;
piecesB[i] = true;
break;
case "N":
knights[i] = true;
piecesW[i] = true;
break;
case "n":
knights[i] = true;
piecesB[i] = true;
break;
case "P":
pawnsW[i] = true;
break;
case "p":
pawnsB[i] = true;
break;
}
}
}
public static boolean[] controlW()
{
boolean[] controlW = new boolean[64];
for (int i=0; i<64; i++)
controlW[i] = bMovesW[i]|nMovesW[i]|rMovesW[i]|qMovesW[i]|kMovesW[i]|pTakesW[i]|kMovesW[i];
return controlW;
}
public static boolean[] controlB()
{
boolean[] controlB = new boolean[64];
for (int i=0; i<64; i++)
controlB[i] = bMovesB[i]|nMovesB[i]|rMovesB[i]|qMovesB[i]|kMovesB[i]|pTakesB[i]|kMovesB[i];
return controlB;
}
/*
public static boolean[] fileOf(int i) // Files are columns
{
boolean[] file = new boolean [64];
for (int j = i%8; j<64; j+=8)
file[j] = true;
return file;
}
public static boolean[] rankOf(int i) // Ranks are rows
{
boolean[] rank = new boolean [64];
int k = (i/8)*8;
for (int j = k; j<k+8; j++)
rank[j] = true;
return rank;
}
*/
public static void clearBB() // Reset bitboards
{
for (int i = 0; i<64; i++)
{
pTakesW[i] = false;
pMovesW[i] = false;
bMovesW[i] = false;
nMovesW[i] = false;
rMovesW[i] = false;
qMovesW[i] = false;
kMovesW[i] = false;
pTakesB[i] = false;
pMovesB[i] = false;
bMovesB[i] = false;
nMovesB[i] = false;
rMovesB[i] = false;
qMovesB[i] = false;
kMovesB[i] = false;
}
}
public static void refreshMoves()
{
clearBB();
for (int i = 0; i < 64; i++) {
switch (Board.chessBoard[i / 8][i % 8])
{
case "K":
King.controlW(i);
break;
case "k":
King.controlB(i);
break;
case "Q":
Queen.controlW(i);
break;
case "q":
Queen.controlB(i);
break;
case "R":
Rook.controlW(i);
break;
case "r":
Rook.controlB(i);
break;
case "B":
Bishop.controlW(i);
break;
case "b":
Bishop.controlB(i);
break;
case "N":
Knight.controlW(i);
break;
case "n":
Knight.controlB(i);
break;
case "P":
Pawn.controlW(i);
break;
case "p":
Pawn.controlB(i);
break;
}
}
}
public static void print(boolean[] bb) // For testing purposes
{
System.out.println("");
for (int i = 0; i < 64; i++) {
if (bb[i] == true)
System.out.print(" X");
if (bb[i] == false)
System.out.print(" .");
if (i % 8 == 7)
System.out.println(" |"+(8-i/8));
}
System.out.println(" ________________\n a b c d e f g h ");
}
static int valueOf(int i)
{
int value = 0;
switch (Board.chessBoard[i/8][i%8])
{
case "Q":
value = 1100;
break;
case "q":
value = -1100;
break;
case "R":
value = 550;
break;
case "r":
value = -550;
break;
case "B":
value = 340;
break;
case "b":
value = -340;
break;
case "N":
value = 320;
break;
case "n":
value = -320;
break;
case "P":
value = 100;
break;
case "p":
value = -100;
break;
}
return value;
}
}