-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_main.cpp
executable file
·104 lines (80 loc) · 2.17 KB
/
server_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
#include "player.h"
#include "board.h"
#include <fstream>
#include <ctime>
using namespace std;
// ofstream Out("mainout.txt");
// Sample C++ Code
int main() {
// ofstream outputfile("out.txt");
int player_id, board_size, time_limit;
string move;
// Get input from server about game specifications
cin >> player_id >> board_size >> time_limit;
// if(player_id == 2) {
// // Get other player's move
// cin>>move;
// while(true) {
// cout<<"P 1 0"<<endl;
// cin>>move;
// }
// }
// else if(player_id == 1) {
// while(true) {
// cout<<"P 0 0"<<endl;
// cin>>move;
// }
// }
board b;
player p(player_id);
start = clock();
// Out<<"letsgo"<<endl;
if(player_id == 2) {
// Get other player's move
// cin>>move;
move.clear();
while(move.size() == 0)
getline(cin,move);
p.id = 1;
p.execute_move(1,move,b);
while(true) {
// cout<<"P 1 0"<<endl;
p.id = 2;
string str = p.generate_move(2,b);
// str = "P 0 0";
char a = str[str.length()-1];
if(isblank(a))
str = str.substr(0,str.length()-1);
// Out<<str<<"mmmm"<<endl;
cout<<str<<endl;
p.execute_move(2,str,b);
// cin>>move;
move.clear();
while(move.size() == 0)
getline(cin,move);
// Out<<move<<"move"<<endl;
p.id = 1;
p.execute_move(1,move,b);
}
}
else if(player_id == 1) {
while(true) {
// cout<<"P 0 0"<<endl;
// cin>>move;
p.id = 1;
string str = p.generate_move(1,b);
// str = "P 1 1";
// Out<<str<<endl;
cout<<str<<endl;
p.execute_move(1,str,b);
// cin>>move;
move.clear();
while(move.size() == 0)
getline(cin,move);
// Out<<"move:"<<move<<endl;
p.id = 2;
p.execute_move(2,move,b);
}
}
return 0;
}