-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_to_skynet.cpp
106 lines (81 loc) · 1.65 KB
/
convert_to_skynet.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
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::ios;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <string>
using std::string;
using std::getline;
#include <vector>
using std::vector;
#include <regex>
using std::regex;
using std::regex_replace;
void replace_all(vector<string> & data, const string & old_str, const string & new_str)
{
for (auto & datum : data)
{
datum = regex_replace(datum, regex(old_str), new_str);
}
}
vector<string> process_in(const string & i_file)
{
string line;
vector<string> raw_data;
ifstream the_txt(i_file);
bool success = false;
if (the_txt.is_open())
{
success = true;
while (getline(the_txt, line))
{
raw_data.push_back(line);
}
}
else
{ cout << "UNABLE TO OPEN FILE: " << i_file << endl; }
if (success)
{
raw_data.pop_back();
replace_all(raw_data, "-1", "r");
replace_all(raw_data, "-2", "R");
replace_all(raw_data, "1", "b");
replace_all(raw_data, "2", "B");
replace_all(raw_data, "0", "_");
replace_all(raw_data, " ", "");
the_txt.close();
}
return raw_data;
}
void process_out(const string & i_file, const vector<string> & data)
{
ofstream the_txt(i_file, ios::out | ios::trunc);
if (the_txt.is_open())
{
for (auto & datum : data)
{
the_txt << datum << endl;
}
}
else
{
cout << "UNABLE TO OPEN FILE: " << i_file << endl;
}
the_txt.close();
}
int main()
{
string i_file = "0_20.txt";
vector<string> game_data = process_in(i_file);
for (auto & str : game_data)
{
cout << str << endl;
}
process_out(i_file, game_data);
cout << endl << endl << "PRESS ENTER TO QUIT";
while(cin.get() != '\n');
return 0;
}