forked from RickSrick/ChessPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplay.cpp
More file actions
101 lines (85 loc) · 2.07 KB
/
replay.cpp
File metadata and controls
101 lines (85 loc) · 2.07 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
#include"include/player.h"
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
/**
*
* @author Kabir Bertan (kabir.bertan@studenti.unipd.it)
*
* @brief Create replay of matches using log file
*
* @version 0.4
* @date 2022-01-15
*
*/
int main(int argc, char *argv[]) {
std::cout << R"(
____ __
/ __ \___ ____ / /___ ___ __
/ /_/ / _ \/ __ \/ / __ `/ / / /
/ _, _/ __/ /_/ / / /_/ / /_/ /
/_/ |_|\___/ .___/_/\__,_/\__, /
/_/ /____/
created by Riccardo Modolo, Matteo Zanella, Kabir Bertan)"<<"\n\n";
std::ifstream in_file;
std::fstream out_file;
replayer* players[2];
chessboard board;
std::string name;
int turn_decider = 0;
if(argc <3){
std::cout<<"invalid number argument";
return -1;
}
std::string mode = argv[1];
for(int i = 0; i < mode.size(); i++){
mode[i] = std::toupper(mode[i]);
}
bool read = false;
if(mode=="V"){
in_file.open(argv[2]);
read = true;
}
else if(mode=="F"){
if(argc < 4) return -1;
in_file.open(argv[2]);
out_file.open(argv[3],std::ios::out);
out_file << board;
}
else {
std::cout<<"Invalid Mode";
return -1;
}
if(!in_file.is_open()){
std::cout << "File not found";
return -1;
}
std::getline (in_file,name);
players[0] = new replayer(&board,set::White,name);
std::getline (in_file,name);
players[1] = new replayer(&board,set::Black,name);
while(in_file){
std::string instruction;
std::getline (in_file,instruction);
if (instruction.compare("END") == 0)
break;
players[turn_decider]->move(instruction);
if(read){
std::cout << players[turn_decider]->print_move();
std::cout << board;
std::this_thread::sleep_for(std::chrono::milliseconds(700));
}
else {
out_file << players[turn_decider]->print_move();
out_file << board;
}
if(instruction[0] == 'P') turn_decider--;
turn_decider = (turn_decider + 1)%2;
}
std::cout << "\nFine Replay\n";
out_file << "Fine Replay";
in_file.close();
out_file.close();
return 0;
}