-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
46 lines (39 loc) · 1002 Bytes
/
log.cpp
File metadata and controls
46 lines (39 loc) · 1002 Bytes
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
#include <vector>
#include <fstream>
#include "board.hpp"
#include "config.hpp"
#include "log.hpp"
namespace roadagain
{
void log_records(const std::vector<Cell>& logs, const CellColor& winner)
{
Config& config = Config::instance();
if (config.log_file_name().empty()){
return;
}
int size = logs.size();
std::ofstream log_file(config.log_file_name().c_str());
for (int i = 0; i < size; i++){
if (logs[i].color == CellColor::BLACK){
log_file << 'B';
}
else {
log_file << 'W';
}
log_file << ' ' << static_cast<char>('a' + logs[i].point.x);
log_file << ' ' << logs[i].point.y;
log_file << '\n';
}
if (winner == CellColor::BLACK){
log_file << "Winner is Black";
}
else if (winner == CellColor::WHITE){
log_file << "Winner is White";
}
else {
log_file << "Draw";
}
log_file << '\n';
log_file.close();
}
} // namespace roadagain