-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.cpp
68 lines (46 loc) · 1.45 KB
/
verify.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
#include "player.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <thread>
using std::cout;
using std::cin;
using std::endl;
using std::ifstream;
using std::string;
constexpr int MAX_ROUNDS = 1000;
int main(int argc, char **argv){
//create new verifier
Player v(1);
cout << "Running verifier" << endl;
string board_name = "board_1.txt";
v.init_board(board_name);
v.load_board(board_name);
int round = 2;
while(true){
board_name = "board_" + std::to_string(round) + ".txt";
ifstream infile(board_name);
if(infile.good()){
if(round >= MAX_ROUNDS){
cout << "Game over. Too many rounds. Both players lose." << endl;
exit(0);
}
int player_nr = round%2 == 0 ? 1 : 2;//player that created board_name
cout << "Verifying board " << board_name << " created by Player " << player_nr << endl;
infile.close();
std::this_thread::sleep_for (std::chrono::milliseconds(100));
v.load_board(board_name);
if(v.valid_move()){
if(v.wins(player_nr)){
cout << "Game over. Player " << player_nr << " wins." << endl;
exit(0);
}
round++;
}else{
//invalid move. End game and declare that player player_nr lost due to invalid move.
cout << "Game over: invalid move by Player " << player_nr << ". Player " << (player_nr==1?2:1) << " wins." << endl;
exit(0);
}
}
}
}