Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Loger.h
- #pragma once
- #include <string>
- #include <fstream>
- #include <vector>
- #include <ctime>
- #include "Windows.h"
- class Loger {
- public:
- Loger();
- void Clear();
- bool is_enable;
- bool temporaly_ignore_flag;
- bool write_each_action_on_disk_flag;
- void AddLog(std::string log_str);
- void AddMultyLineLog(std::string log_str);
- static std::string GetTimeStampHMS();
- static std::string GetTimeStampYMD();
- void WriteToFile();
- void ClearFile();
- void CreateFileIfNotExist();
- std::string filename;
- std::string tab_str;
- int tabs;
- private:
- std::vector<std::string> Logs;
- };
- //Loger.cpp
- #include "Loger.h"
- Loger::Loger() {
- Clear();
- return;
- }
- void Loger::Clear() {
- Logs.clear();
- is_enable = false;
- filename = "";
- temporaly_ignore_flag = false;
- tabs = 0;
- tab_str = " ";
- write_each_action_on_disk_flag = false;
- return;
- }
- void Loger::AddLog(std::string log_str) {
- if (is_enable == false) return;
- if (temporaly_ignore_flag == true) return;
- std::string str;
- for (int i = 0; i < tabs; i++) str += tab_str;
- str += log_str;
- Logs.push_back(str);
- if (write_each_action_on_disk_flag == true) {
- WriteToFile();
- }
- return;
- }
- void Loger::WriteToFile() {
- if (is_enable == false) return;
- if (Logs.size() == 0) return;
- std::ofstream file(filename, std::ios::app);
- for (int i = 0; i < Logs.size(); i++) {
- file << Logs[i] << "\n";
- }
- file.close();
- Logs.clear();
- return;
- }
- std::string Loger::GetTimeStampHMS() {
- std::string ts = "";
- SYSTEMTIME st;
- GetLocalTime(&st);
- ts += std::to_string(st.wHour) + "h";
- ts += std::to_string(st.wMinute) + "m";
- ts += std::to_string(st.wSecond) + "s";
- return ts;
- }
- std::string Loger::GetTimeStampYMD() {
- std::string ts = "";
- SYSTEMTIME st;
- GetLocalTime(&st);
- ts += std::to_string(st.wYear) + "-";
- ts += std::to_string(st.wMonth) + "-";
- ts += std::to_string(st.wDay);
- return ts;
- }
- void Loger::ClearFile() {
- std::ofstream file(filename);
- file.close();
- return;
- }
- void Loger::CreateFileIfNotExist() {
- std::ifstream in_file(filename);
- if (in_file.is_open() == false) {
- std::ofstream out_file(filename);
- out_file.close();
- }
- in_file.close();
- return;
- }
- void Loger::AddMultyLineLog(std::string log_str) {
- while (true) {
- int pos = log_str.find("\n");
- if (pos == std::string::npos) {
- AddLog(log_str);
- return;
- }
- std::string line = log_str.substr(0, pos);
- AddLog(line);
- log_str = log_str.substr(pos + 1);
- }
- return;
- }
- //Example of usage:
- //Lets Take only frames where we 100% know whose move now
- if (ti->whose_move < 0) {
- LG->AddLog("Dont know whose move.");
- return false;
- }
- LG->AddLog("Whose move detected: " + std::to_string(ti->whose_move));
- //Dealler
- if (ti->dealler_pos < 0) {
- LG->AddLog("Dont know dealler pos.");
- return false;
- }
- LG->AddLog("Dealler pos detected: " + std::to_string(ti->dealler_pos));
- //What about StartStacks?
- LG->AddLog("Constructing hand ...");
- int ante = 0;
- int StartStacks[SEATS] = { 0 }; //May be start stacks (base view)
- //Usualy StartStack = preflop Bet + Stack (+ ante??)
- int players_in_game = 0;
- for (int seat = 0; seat < SEATS; seat++) {
- StartStacks[seat] = ti->Stacks[seat] + ti->Bets[seat] + ante;
- if (StartStacks[seat] > 0) players_in_game++;
- LG->AddLog("StartStack[" + std::to_string(seat) + "]: " + std::to_string(StartStacks[seat]));
- }
- if (players_in_game < 2) {
- LG->AddLog("Error. Not enought players in game.");
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement