-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
187 lines (162 loc) · 5.25 KB
/
main.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
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
#include <bits/stdc++.h>
#include "communications.h"
#include "init_game.h"
#include "pieces.h"
#include "matrix_transformation.h"
#include "constants.h"
#include "game.h"
using namespace std;
int main() {
cout.setf(ios::unitbuf);
Log log;
char wb = BLACK, force = 0, x_s = 0, y_s = 0, x_d = 0, y_d = 0; // engine default is black
int primit_culoare = 0;
Game g(wb);
std::vector<std::vector<char>> chess_board = g.m_board;
std::vector<std::vector<char>> positions = g.m_pieces;
protocol_begin(log); // we try to make the configuratinos here
int passes = 0;
int idx_move = 0;
while(true){
log.write("\npasses: ");
log.write(std::to_string(passes));
log.write("\n");
std::string s;
std::cin>>s;
log.write(s);
log.write("\n");
if (s.compare("xboard") == 0) {
std::cout<<"\n";
log.write("\n");
} else if (s.compare("protover") == 0) {
std::cin>>s; // reading N
log.write(s);
std::cout<<"feature done=1 sigterm=0 san=0"<<std::endl;
log.write("feature done=1 sigterm=0 san=0");
} else if (s.compare("new") == 0) {
wb = 1;
force = 0;
g.remake_print_board(wb);
} else if (s.compare("force") == 0) {
//force = 1;
//g.remake_print_board(wb);
} else if (s.compare("go") == 0) {
force = 0;
// if (idx_move % 2 == 1) {
// goto black_engine;
// } else {
// goto white_engine;
// }
} else if (s.compare("white") == 0 && primit_culoare == 0) {
black_engine:
wb = 1;
g.remake_print_board(wb);
primit_culoare = 1;
} else if (s.compare("black") == 0 && primit_culoare == 0 && idx_move == 0) {
// white_engine:
primit_culoare = 1;
wb = 0;
g.remake_print_board(wb);
// if (wb == 0 && move == 0 && force == 0) {
// std::cout<<white_moves[move]<<std::endl;
// move++;
// continue;
// }
std::vector<char> mymove;
mymove = g.find_next_move();
if (mymove.size() != 0) {
std::vector<char> mymove_chr2;
mymove_chr2.push_back(mymove[0]);
mymove_chr2.push_back(mymove[1]);
mymove_chr2.push_back(mymove[2]);
mymove_chr2.push_back(mymove[3]);
g.apply_move_m(mymove_chr2);
std::string mymove_str = get_chess_coordonates(mymove[0], mymove[1], g) + get_chess_coordonates(mymove[2], mymove[3], g);
std::string mymove_command = "move " + mymove_str;
std::cout<<mymove_command<<std::endl;
++idx_move;
} else {
log.write("resign\n");
std::cout<<"resign\n";
break;
}
} else if (s.compare("quit") == 0) {
break;
} else if (s.compare("resign") == 0) {
break;
} else if (force == 1 && !isdigit(s[0]) && isdigit(s[1])) {
//std::cin >> s;
get_matrix_coordonates(s, x_s, y_s, g); // now we have in x_s and y_s the coordonates of the source of the moved piece
s = s.substr(2, 2); // we take the chess destinations on the board
get_matrix_coordonates(s, x_d, y_d, g); // now we have in x_d and y_d the coordonates of the destination of the moved piece
idx_move++;
} else if (s.compare("time") == 0 && force == 0) {
std::cin >> s;
log.write(s);
log.write(" ");
std::cin >> s;
log.write(s);
log.write(" ");
std::cin >> s; // we finished with reading the time and now we will read the value for the matrix
log.write(s);
log.write(" ");
std::cin >> s; // we read the opponent's move
if (s.compare("white") == 0){
// goto white_engine;
std::cin >> s;
std::cin >> s;
std::cin >> s;
//goto citit;
std::cin >> s;
std::cin >> s;
std::cin >> s;
}
if (s.compare("black") == 0){
goto black_engine;
// std::cin >> s;
// std::cin >> s;
// std::cin >> s;
// //goto citit;
// std::cin >> s;
// std::cin >> s;
// std::cin >> s;
}
log.write("Received: we got the move ");
log.write(s);
log.write("\nmove ");
get_matrix_coordonates(s, x_s, y_s, g); // now we have in x_s and y_s the coordonates of the source of the moved piece
s = s.substr(2, 2); // we take the chess destinations on the board
get_matrix_coordonates(s, x_d, y_d, g); // now we have in x_d and y_d the coordonates of the destination of the moved piece
++idx_move;
std::vector<char> mymove_chr;
mymove_chr.push_back(x_s);
mymove_chr.push_back(y_s);
mymove_chr.push_back(x_d);
mymove_chr.push_back(y_d);
g.apply_move_e(mymove_chr);
std::vector<char> mymove;
mymove = g.find_next_move();
if (mymove.size() != 0) {
std::vector<char> mymove_chr2;
mymove_chr2.push_back(mymove[0]);
mymove_chr2.push_back(mymove[1]);
mymove_chr2.push_back(mymove[2]);
mymove_chr2.push_back(mymove[3]);
g.apply_move_m(mymove_chr2);
std::string mymove_str = get_chess_coordonates(mymove[0], mymove[1], g) + get_chess_coordonates(mymove[2], mymove[3], g);
std::string mymove_command = "move " + mymove_str;
std::cout<<mymove_command<<std::endl;
++idx_move;
} else {
log.write("resign\n");
std::cout<<"resign\n";
break;
}
}
log.write("\npasses: ");
log.write(std::to_string(passes));
log.write("\n");
++passes;
}
return 0;
}