-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathboard.h
341 lines (331 loc) · 8.51 KB
/
board.h
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#ifndef BOARDH
#define BOARDH
#include"bitboard.h"
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<stdio.h>
#include<string>
#include<stdlib.h>
//#include<Windows.h>
#include"boardcn.h"
#include<math.h>
#define BLACK 0
#define WHITE 1
#define SEARCH 0
#define search 0
using namespace std;
class board
{
public:
/*
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
*/
bitboard ban[2];
bitboard notsafe[2];
const static boardcn nb;// neighbor
#if SEARCH == 1
static zhashtable ztable;
unsigned long long zValue;
#endif
static char bpath[BOARDSSIZE+10];
static int bpsize;
static char wpath[BOARDSSIZE+10];
static int wpsize;
bitboard bitb[2];
char parent[BOARDCUL*BOARDCUL];
bitboard air[BOARDCUL*BOARDCUL];
char countair[BOARDSSIZE];
int findParent(int i);
void unite(int x,int y);
void getallair();
bool check_is_end();
void add(int i,bool j);
bool check(int i,bool j);
void showboard();
void showParent();
void showAir();
board();
board(bitboard bb,bitboard ww);
void Initboard(bitboard bb = bitboard(),bitboard ww = bitboard());
inline bool get(int i,bool j);
bool just_play_color();
void getv(int bone[BOARDSSIZE],int wone[BOARDSSIZE],int two[BOARDSSIZE] ,int &bsize,int &wsize ,int &tsize);
void getvec(vector<char> &bone,vector<char> &wone ,vector<char> &two );
void setdata();
void clear();
string inttostring(int i);
double simulate(bool j,int bone[BOARDSSIZE],int wone[BOARDSSIZE],int two[BOARDSSIZE] ,int bsize,int wsize ,int tsize );
bool isempty();
inline void addbp(int k)
{
bpath[bpsize] = k;
bpsize++;
}
inline void addwp(int k)
{
wpath[wpsize] = k;
wpsize++;
}
#if search == 2
void getnogo()
{
nogo.clear();
for(int i=0; i < BOARDSSIZE; i++)
{
if(!bitb[0].get(i) && !bitb[1].get(i) && !check(i,0) && !check(i,1) )
{
nogo.push_back(i);
}
}
}
void getConnectNogo()
{
getnogo();
vector<char> bstack,wstack;
bstack=wstack=nogo;
int i,j,k,x,y;
while(bstack.size() != 0)
{
i=bstack[bstack.size()-1];
bstack.pop_back();
if(CN[0].get(i))
{
continue;
}
CN[0].add(i);
x=i/BOARDCUL; // ROW
y=i%BOARDCUL; // CUL
if( x != 0)
{
k=i-BOARDCUL;
if(bitb[0].get(k) == true)
{
bstack.push_back(k);
}
else if( check(k,0) && !check(k,1) ) // no go
{
bstack.push_back(k);
}
}
if( x != BOARDCUL - 1)
{
k=i+BOARDCUL;
if(bitb[0].get(k) == true)
{
bstack.push_back(k);
}
else if( check(k,0) && !check(k,1) ) // no go
{
bstack.push_back(k);
}
}
if( y != 0)
{
k=i-1;
if(bitb[0].get(k) == true)
{
bstack.push_back(k);
}
else if( check(k,0) && !check(k,1) ) // no go
{
bstack.push_back(k);
}
}
if(y != BOARDCUL - 1)
{
k=i+1;
if(bitb[0].get(k) == true)
{
bstack.push_back(k);
}
else if( check(k,0) && !check(k,1) ) // no go
{
bstack.push_back(k);
}
}
}
while(wstack.size() != 0)
{
i=wstack[wstack.size()-1];
wstack.pop_back();
if(CN[1].get(i))
{
continue;
}
CN[1].add(i);
x=i/BOARDCUL; // ROW
y=i%BOARDCUL; // CUL
if( x != 0)
{
k=i-BOARDCUL;
if(bitb[1].get(k) == true)
{
wstack.push_back(k);
}
else if( check(k,1) && !check(k,0) ) // no go
{
wstack.push_back(k);
}
}
if( x != BOARDCUL - 1)
{
k=i+BOARDCUL;
if(bitb[1].get(k) == true)
{
wstack.push_back(k);
}
else if( check(k,1) && !check(k,0) ) // no go
{
wstack.push_back(k);
}
}
if( y != 0)
{
k=i-1;
if(bitb[1].get(k) == true)
{
wstack.push_back(k);
}
else if( check(k,1) && !check(k,0) ) // no go
{
wstack.push_back(k);
}
}
if(y != BOARDCUL - 1)
{
k=i+1;
if(bitb[1].get(k) == true)
{
wstack.push_back(k);
}
else if( check(k,1) && !check(k,0) ) // no go
{
wstack.push_back(k);
}
}
}
for(i=0; i<BOARDSSIZE; i++)
{
if(bitb[0].get(i) || bitb[1].get(i))
{
continue;
}
bool bF,wF;
bF=wF=false;
x=i/BOARDCUL; // ROW
y=i%BOARDCUL; // CUL
if( x != 0 )
{
k=i-BOARDCUL;
if(CN[0].get(k)==true)bF=true;
if(CN[1].get(k)==true)wF=true;
}
if( x != BOARDCUL - 1)
{
k=i+BOARDCUL;
if(CN[0].get(k)==true)bF=true;
if(CN[1].get(k)==true)wF=true;
}
if( y != 0)
{
k=i-1;
if(CN[0].get(k)==true)bF=true;
if(CN[1].get(k)==true)wF=true;
}
if(y != BOARDCUL - 1)
{
k=i+1;
if(CN[0].get(k)==true)bF=true;
if(CN[1].get(k)==true)wF=true;
}
if(bF && wF)
{
twoCN.add(i);
}
}
}
bool checkStar(int i,bool j)
{
int x,y,k;
x=i/BOARDCUL; // ROW
y=i%BOARDCUL; // CUL
if(x != 0 )
{
k=i-BOARDCUL;
if(!CN[0].get(k) && !CN[1].get(k) && !twoCN.get(k) && !bitb[j].get(k))return false;
}
if(x != BOARDCUL -1 )
{
k=i+BOARDCUL;
if(!CN[0].get(k) && !CN[1].get(k) && !twoCN.get(k) && !bitb[j].get(k))return false;
}
if(y != 0 )
{
k=i-1;
if(!CN[0].get(k) && !CN[1].get(k) && !twoCN.get(k) && !bitb[j].get(k))return false;
}
if(y != BOARDCUL -1 )
{
k=i+1;
if(!CN[0].get(k) && !CN[1].get(k) && !twoCN.get(k) && !bitb[j].get(k))return false;
}
return true;
}
void getStar()
{
getConnectNogo();
for(int i=0; i<BOARDSSIZE; i++)
{
bool f;
int x,y,k;
if( check(i,0) && !check(i,1) && checkStar(i,0) )
{
Star[0].add(i);
}
if( check(i,1) && !check(i,0) && checkStar(i,1) )
{
Star[1].add(i);
}
}
}
void showNST()
{
for(int i=0; i<BOARDCUL; i++)
{
for(int j=0; j<BOARDCUL; j++)
{
int k=i*BOARDCUL+j;
if(bitb[0].get(k)) cout<<'@';
else if(bitb[1].get(k)) cout<<'O';
else if(Star[0].get(k))
{
if(CN[0].get(k)) cout<<'T';
else cout<<'S';
}
else if(Star[1].get(k))
{
if(CN[1].get(k)) cout<<'t';
else cout<<'s';
}
else cout<<'.';
}
cout<<endl;
}
}
bool checkTriangle(int i,int j)
{
if(Star[j].get(i) && CN[j].get(i))return true;
return false;
}
#endif
};
#if SEARCH == 1
zhashtable board :: ztable;
#endif
#endif