Advertisement
nefton

Untitled

Oct 23rd, 2020
2,591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Loger.h
  2. #pragma once
  3.  
  4. #include <string>
  5. #include <fstream>
  6. #include <vector>
  7. #include <ctime>
  8. #include "Windows.h"
  9.  
  10. class Loger {
  11. public:
  12.     Loger();
  13.     void Clear();
  14.    
  15.     bool is_enable;
  16.     bool temporaly_ignore_flag;
  17.     bool write_each_action_on_disk_flag;
  18.  
  19.     void AddLog(std::string log_str);
  20.     void AddMultyLineLog(std::string log_str);
  21.  
  22.     static std::string GetTimeStampHMS();
  23.     static std::string GetTimeStampYMD();
  24.  
  25.     void WriteToFile();
  26.     void ClearFile();
  27.     void CreateFileIfNotExist();
  28.  
  29.     std::string filename;
  30.    
  31.     std::string tab_str;
  32.     int tabs;
  33.  
  34. private:
  35.     std::vector<std::string> Logs;
  36.  
  37. };
  38.  
  39. //Loger.cpp
  40. #include "Loger.h"
  41.  
  42.  
  43. Loger::Loger() {
  44.     Clear();
  45.     return;
  46. }
  47.  
  48. void Loger::Clear() {
  49.     Logs.clear();
  50.     is_enable = false;
  51.     filename = "";
  52.     temporaly_ignore_flag = false;
  53.     tabs = 0;
  54.     tab_str = "  ";
  55.     write_each_action_on_disk_flag = false;
  56.        
  57.     return;
  58. }
  59.  
  60. void Loger::AddLog(std::string log_str) {
  61.  
  62.     if (is_enable == false) return;
  63.     if (temporaly_ignore_flag == true) return;
  64.    
  65.     std::string str;
  66.     for (int i = 0; i < tabs; i++) str += tab_str;
  67.     str += log_str;
  68.     Logs.push_back(str);
  69.  
  70.     if (write_each_action_on_disk_flag == true) {
  71.         WriteToFile();
  72.     }
  73.  
  74.  
  75.     return;
  76. }
  77.  
  78. void Loger::WriteToFile() {
  79.     if (is_enable == false) return;
  80.     if (Logs.size() == 0) return;
  81.  
  82.     std::ofstream file(filename, std::ios::app);
  83.     for (int i = 0; i < Logs.size(); i++) {
  84.         file << Logs[i] << "\n";
  85.     }
  86.     file.close();
  87.     Logs.clear();
  88.  
  89.     return;
  90. }
  91.  
  92. std::string Loger::GetTimeStampHMS() {
  93.     std::string ts = "";
  94.     SYSTEMTIME st;
  95.     GetLocalTime(&st);
  96.     ts += std::to_string(st.wHour) + "h";
  97.     ts += std::to_string(st.wMinute) + "m";
  98.     ts += std::to_string(st.wSecond) + "s";
  99.     return ts;
  100. }
  101. std::string Loger::GetTimeStampYMD() {
  102.  
  103.     std::string ts = "";
  104.     SYSTEMTIME st;
  105.     GetLocalTime(&st);
  106.     ts += std::to_string(st.wYear) + "-";
  107.     ts += std::to_string(st.wMonth) + "-";
  108.     ts += std::to_string(st.wDay);
  109.     return ts;
  110. }
  111.  
  112. void Loger::ClearFile() {
  113.     std::ofstream file(filename);
  114.     file.close();
  115.     return;
  116. }
  117. void Loger::CreateFileIfNotExist() {
  118.     std::ifstream in_file(filename);
  119.     if (in_file.is_open() == false) {
  120.         std::ofstream out_file(filename);
  121.         out_file.close();
  122.     }
  123.     in_file.close();
  124.     return;
  125. }
  126.  
  127. void Loger::AddMultyLineLog(std::string log_str) {
  128.     while (true) {
  129.         int pos = log_str.find("\n");
  130.         if (pos == std::string::npos) {
  131.             AddLog(log_str);
  132.             return;
  133.         }
  134.         std::string line = log_str.substr(0, pos);
  135.         AddLog(line);
  136.         log_str = log_str.substr(pos + 1);
  137.     }
  138.     return;
  139. }
  140.  
  141. //Example of usage:
  142.     //Lets Take only frames where we 100% know whose move now
  143.     if (ti->whose_move < 0) {
  144.         LG->AddLog("Dont know whose move.");
  145.         return false;
  146.     }
  147.     LG->AddLog("Whose move detected: " + std::to_string(ti->whose_move));
  148.    
  149.     //Dealler
  150.     if (ti->dealler_pos < 0) {
  151.         LG->AddLog("Dont know dealler pos.");
  152.         return false;
  153.     }
  154.     LG->AddLog("Dealler pos detected: " + std::to_string(ti->dealler_pos));
  155.  
  156.     //What about StartStacks?
  157.    
  158.     LG->AddLog("Constructing hand ...");
  159.     int ante = 0;
  160.     int StartStacks[SEATS] = { 0 }; //May be start stacks (base view)
  161.                                     //Usualy StartStack = preflop Bet + Stack (+ ante??)
  162.  
  163.     int players_in_game = 0;
  164.     for (int seat = 0; seat < SEATS; seat++) {
  165.         StartStacks[seat] = ti->Stacks[seat] + ti->Bets[seat] + ante;
  166.         if (StartStacks[seat] > 0) players_in_game++;
  167.         LG->AddLog("StartStack[" + std::to_string(seat) + "]: " + std::to_string(StartStacks[seat]));
  168.     }
  169.  
  170.     if (players_in_game < 2) {
  171.         LG->AddLog("Error. Not enought players in game.");
  172.         return false;
  173.     }
  174.  
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement