forked from yu4763/Connect6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCalculation.cpp
More file actions
178 lines (149 loc) · 3.67 KB
/
Copy pathtempCalculation.cpp
File metadata and controls
178 lines (149 loc) · 3.67 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
#include <function.h>
#include <stdio.h>
#include "monte_carlo_tree_search.h"
#include "monte_carlo_tree_search.cpp"
// ====================
// To get two positions
extern int best_pos1;
extern int best_pos2;
bool is_first = true;
// ====================
int wheretoPut( board *b ){
int i, k;
// ========================================
// Arbitrary playing
//
// for (i=0; i<stoneNum; i++){
// for(k=0; k<stoneNum; k++){
//
// if(b->stones[i][k]->state == 0){
// return i*stoneNum +k;
// }
// }
// }
// =======================================
// Using monte carlo search
if (is_first) {
MonteCarloTreeSearch();
is_first = false;
return best_pos1;
} else {
is_first = true;
return best_pos2;
}
}
/*
return value : reuslt
0 : not end
1 : end and win
2 : end and lose
*/
int checkEnd( stone *s[19][19], char state){
int i, k, j;
int cnt = 0;
/* check row */
for(i=0; i<stoneNum; i++){
j = -1;
for(k=0; k<stoneNum-5; k++){
if(k <= j){
continue;
}
cnt = 1;
if(s[i][k]->state==state){
for(j=k+1; j<k+6; j++){
if(s[i][j]->state != state){
break;
}
cnt++;
}
}
if(cnt == 6){
if (k != stoneNum-6){
if(s[i][k+6]->state == state){
return 2;
}
}
return 1;
}
}
}
/*check column*/
for(i=0; i<stoneNum; i++){
j = -1;
for(k=0; k<stoneNum-5; k++){
if(k <= j){
continue;
}
cnt = 1;
if(s[k][i]->state==state){
for(j=k+1; j<k+6; j++){
if(s[j][i]->state != state){
break;
}
cnt++;
}
}
if(cnt == 6){
if (k != stoneNum-6){
if(s[k+6][i]->state == state){
return 2;
}
}
return 1;
}
}
}
/*check diagonal*/
for(i=0; i<stoneNum-5; i++){
j = -1;
for(k=0; k<stoneNum-5; k++){
if(k <= j){
continue;
}
cnt = 1;
if(s[i][k]->state==state){
for(j=1; j<6; j++){
if(s[i+j][k+j]->state != state){
break;
}
cnt++;
}
}
if(cnt == 6){
if (i != stoneNum-6 && k!= stoneNum){
if(s[i+6][k+6]->state == state){
return 2;
}
}
return 1;
}
}
}
/*check diagonal*/
for(i=0; i<stoneNum-5; i++){
j = -1;
for(k=5; k<stoneNum; k++){
if(k <= j){
continue;
}
cnt = 1;
if(s[i][k]->state==state){
for(j=1; j<6; j++){
if(s[i+j][k-j]->state != state){
break;
}
cnt++;
}
}
if(cnt == 6){
if (i != stoneNum-6 && k!= 5){
if(s[i+6][k-6]->state == state){
return 2;
}
}
return 1;
}
}
}
return 0;
}