Repository navigation
Expand file tree
/
Copy pathHHConverter.cpp
More file actions
362 lines (294 loc) · 10.5 KB
/
Copy pathHHConverter.cpp
File metadata and controls
362 lines (294 loc) · 10.5 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// HHConverter.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <fstream>
#include <iostream>
#include <regex>
#include <ctime>
using namespace std;
int main() {
string lineHH = "", lineSum = "";
ifstream readHH, readSum, ini;
ofstream writeHH, writeSum;
smatch match;
streampos oldpos, currpos, fsize = 0;
double fprogress = 0.0;
clock_t start;
double duration;
int seconds, minutes, hours;
//// Manually set those values with your tourney format in Ini file
double BuyInFactor;
double FeePct;
string TourneySize;
string curr;
////////////////////////
double BuyIn, Fee;
int TourneyNumber = 0;
int TotalPlayer = 0;
int Hands = 0;
string finishPlace = "";
string totalPlace = "";
string Profit = "";
bool bWrite = false;
bool bNewTourney = false;
string SmallBlind, BigBlind;
string PlayerCard1 = "";
vector< string > ShowedHand[2];
vector< string > Collected[2];
string ButtonSeat = "";
string GameNumber = "";
//date var
string Day = "";
string Month = "";
string Year = "";
string Hour = "";
string Min = "";
string Sec = "";
ini.open("HHConverter.ini");
readHH.open("history.paradise.txt");
readSum.open("tournaments.csv", ios::in);
writeHH.open("history.888.txt");
writeSum.open("tournaments.888.txt");
readSum.seekg(0, ios::end);
fsize = readSum.tellg();
readSum.close();
readSum.open("tournaments.csv");
getline(readSum, lineSum);
getline(readSum, lineSum);
cout << "Converting...\n\n";
// check stream status
if (!readHH) cerr << "Can't open history.paradise.txt file!\n";
if (!readSum) cerr << "Can't open tournaments.csv file!\n";
start = clock(); // get current time
while (!ini.eof()) {
getline(ini, lineHH);
// get buy-in factor, fee%, tourney size (X-Max) and currency in Ini file
if (regex_search(lineHH, match, regex("BuyInFactor=([0-9.]+)"))) {
BuyInFactor = stod(match[1]);
continue;
}
if (regex_search(lineHH, match, regex("FeePct=([0-9.]+)"))) {
FeePct = stod(match[1]);
continue;
}
if (regex_search(lineHH, match, regex("TourneySize=([0-9]+)"))) {
TourneySize = match[1];
continue;
}
if (regex_search(lineHH, match, regex("Currency=(.+?)"))) {
curr = match[1];
if (curr == "â") curr = "€";
if (curr == "Â") curr = "€";
continue;
}
}
ini.close();
while (!readHH.eof()) {
getline(readHH, lineHH);
if (lineHH == "") { continue; }
// get game number
if (regex_search(lineHH, match, regex("Game #([0-9]+)"))) {
GameNumber = match[1];
// get blinds
regex_search(lineHH, match, regex("- ([0-9,]+)/([0-9,]+) No Limit"));
SmallBlind = match[1];
BigBlind = match[2];
// get date
regex_search(lineHH, match, regex("Hold'em - ([0-9]+)/([0-9]+)/([0-9]+)-([0-9]+):([0-9]+):([0-9]+)"));
Year = match[1];
Month = match[2];
Day = match[3];
Hour = match[4];
Min = match[5];
Sec = match[6];
writeHH << "#Game No : " << GameNumber << endl;
writeHH << "***** 888poker Hand History for Game " << GameNumber << " *****" << endl;
writeHH << SmallBlind << "/" << BigBlind << " Blinds No Limit Holdem - *** " << Day << " " << Month << " " << Year << " " << Hour << ":" << Min << ":" << Sec << endl;
continue;
}
// get tourney number
if (regex_search(lineHH, match, regex("Hand #([0-9]+)"))) {
if (match[1] == "1") {
bNewTourney = true;
++TourneyNumber;
if (!readSum.eof()) {
getline(readSum, lineSum);
if (regex_search(lineSum, match, regex("^([0-9]+)([a-z ]*)([0-9]+)(.+?):([0-9]+),\\$([0-9]+)(.+?)\\$([0-9\\(\\)]*)$"))) {
BuyIn = stod(match[6]) / BuyInFactor;
Fee = BuyIn * (FeePct/100);
BuyIn = BuyIn - Fee;
finishPlace = match[1];
totalPlace = match[3];
Profit = match[8];
Profit = regex_replace(Profit, regex("\\("), "-");
Profit = regex_replace(Profit, regex("\\)"), "");
writeSum << "***** Tournament Summary *****" << endl;
writeSum << "Tournament ID: " << TourneyNumber << endl;
writeSum << "Buy-In: " << curr << BuyIn << " + " << curr << Fee << endl;
}
}
}
else bNewTourney = false;
writeHH << "Tournament #" << TourneyNumber << " " << curr << BuyIn << " + " << curr << Fee << " - Table #0 " << TourneySize << " Max (Real Money)" << endl;
// get button seat
regex_search(lineHH, match, regex("Seat ([0-9]+)"));
ButtonSeat = match[1];
writeHH << "Seat " + ButtonSeat + " is the button" << endl;
oldpos = readHH.tellg();
continue;
}
// get seats
if (regex_search(lineHH, match, regex("^Seat( *)([0-9]+): ([a-zA-Z0-9.-_]+)(.+?)([0-9,]+)"))) {
++TotalPlayer;
if (bWrite) {
TotalPlayer = 0;
writeHH << "Seat " << match[2] << ": " << match[3] << " ( " << match[5] << " )" << endl;
}
continue;
}
// get total players
if (TotalPlayer > 0) {
readHH.seekg(oldpos);
writeHH << "Total number of players : " << TotalPlayer << endl;
bWrite = true;
continue;
} else bWrite = false;
// get antes
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Ante(.+?)([0-9,]+)"))) {
writeHH << match[1] << " posts ante [" << match[3] << "]" << endl;
continue;
}
// get small blind
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Post Small Blind(.+?)([0-9,]+)"))) {
writeHH << match[1] << " posts small blind [" << match[3] << "]" << endl;
continue;
}
// get big blind
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Post Big Blind(.+?)([0-9,]+)"))) {
writeHH << match[1] << " posts big blind [" << match[3] << "]" << endl;
continue;
}
// get preflop
if (lineHH == "Dealing...") {
writeHH << "** Dealing down cards **" << endl;
continue;
}
if (regex_search(lineHH, match, regex("^Dealt to ([a-zA-Z0-9.-_]+)(.+?)([a-zA-Z0-9]+)"))) {
if (PlayerCard1 != "") {
writeHH << "Dealt to " << match[1] << " [ " + PlayerCard1 + ", " << match[3] << " ]" << endl;
PlayerCard1 = "";
double profit = stod(Profit) / BuyInFactor;
if (bNewTourney) {
if (profit < 0) {
Profit = regex_replace(Profit, regex("-"), "");
writeSum << match[1] << " finished " << finishPlace << "/" << totalPlace << " and lost " << curr << fabs(profit) << endl << endl;
} else
writeSum << match[1] << " finished " << finishPlace << "/" << totalPlace << " and won " << curr << (profit + BuyIn + Fee) << endl << endl;
if (fprogress < 1.0) {
int barWidth = 70;
cout << "[";
int pos = barWidth * fprogress;
for (int i = 0; i < barWidth; ++i) {
if (i < pos) cout << "=";
else if (i == pos) cout << ">";
else cout << " ";
}
cout << "] " << int(fprogress * 100.0) << " %\r";
cout.flush();
currpos = readSum.tellg();
fprogress = double(currpos) / double(fsize);
}
}
continue;
}
PlayerCard1 = match[3];
continue;
}
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Raise(.+?)([0-9,]+)"))) {
writeHH << match[1] << " raises [" << match[3] << "]" << endl;
continue;
}
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Bet(.+?)([0-9,]+)"))) {
writeHH << match[1] << " bets [" << match[3] << "]" << endl;
continue;
}
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Call(.+?)([0-9,]+)"))) {
writeHH << match[1] << " calls [" << match[3] << "]" << endl;
continue;
}
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Check"))) {
writeHH << match[1] << " checks" << endl;
continue;
}
if (regex_search(lineHH, match, regex("^([a-zA-Z0-9.-_]+): Fold"))) {
writeHH << match[1] << " folds" << endl;
continue;
}
// get flop
if (regex_search(lineHH, match, regex("^\\*\\*\\* FLOP \\*\\*\\* : \\[ ([a-zA-Z0-9 ]+) \\]"))) {
writeHH << "** Dealing flop ** [ " << regex_replace(string(match[1]), regex(" "), ", ") << " ]" << endl;
continue;
}
// get turn
if (regex_search(lineHH, match, regex("^\\*\\*\\* TURN \\*\\*\\* : \\[([a-zA-Z0-9 ]+)\\] \\[([a-zA-Z0-9 ]+)"))) {
writeHH << "** Dealing turn ** [" << match[2] << "]" << endl;
continue;
}
// get river
if (regex_search(lineHH, match, regex("^\\*\\*\\* RIVER \\*\\*\\* : \\[([a-zA-Z0-9 ]+)\\] \\[([a-zA-Z0-9 ]+)"))) {
writeHH << "** Dealing river ** [" << match[2] << "]" << endl;
continue;
}
// get summary
if (lineHH == "*** SUMMARY ***") {
writeHH << "** Summary **" << endl;
continue;
}
lineHH = regex_replace(lineHH, regex("Pot: ([0-9,]+)"), "");
if (regex_search(lineHH, match, regex("([a-zA-Z0-9.-_]+)(.+?)collected ([0-9,]+),(.+?)\\(showed hand\\) \\[ ([a-zA-Z0-9 ]+) \\]"))) {
Collected[0].push_back(match[1]);
Collected[1].push_back(match[3]);
ShowedHand[0].push_back(match[1]);
ShowedHand[1].push_back(match[5]);
continue;
}
if (regex_search(lineHH, match, regex("([a-zA-Z0-9.-_]+)(.+?)collected ([0-9,]+),"))) {
Collected[0].push_back(match[1]);
Collected[1].push_back(match[3]);
continue;
}
if (regex_search(lineHH, match, regex("([a-zA-Z0-9.-_]+)(.+?)\\(showed hand\\) \\[ ([a-zA-Z0-9 ]+) \\]"))) {
ShowedHand[0].push_back(match[1]);
ShowedHand[1].push_back(match[3]);
continue;
}
// writeHH summary
if (lineHH == "-----------------------------------------------------") {
for (int i = 0; i < ShowedHand[0].size(); i++) {
writeHH << ShowedHand[0][i] << " shows [ " << regex_replace(ShowedHand[1][i], regex(" "), ", ") << " ]" << endl;
}
for (int i = 0; i < Collected[0].size(); i++) {
writeHH << Collected[0][i] << " collected [ " << Collected[1][i] << " ]" << endl;
}
writeHH << endl << endl << endl;
memset(ShowedHand, 0x00, sizeof(ShowedHand[0]) * 2);
memset(Collected, 0x00, sizeof(Collected[0]) * 2);
++Hands;
continue;
}
}
cout << "[======================================================================] 100 %\r" << endl << endl;
cout.flush();
duration = (clock() - start) / (double)CLOCKS_PER_SEC;
seconds = (int)duration;
minutes = seconds / 60;
hours = minutes / 60;
cout << "Finished in " << int(hours) << " hours " << int(minutes % 60) << " minutes " << int(seconds % 60) << " seconds ! \nHands Converted: " << Hands << " \nTournaments Converted: " << TourneyNumber << endl;
readHH.close();
writeHH.close();
readSum.close();
writeSum.close();
cout << "Press Enter to Exit.\n";
cin.ignore();
}