Skip to content

Commit

Permalink
Merge pull request #89 from RuijieZ/cashout
Browse files Browse the repository at this point in the history
Add "Receives Cashout" parsing to GGPoker parser.
  • Loading branch information
ItalyToast authored Nov 30, 2023
2 parents ce6e9d0 + 81cc16f commit f903790
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 11 deletions.
1 change: 1 addition & 0 deletions HandHistories.Objects/Actions/WinningsActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public enum WinningsActionType
WINS_SIDE_POT,
TIES,
TIES_SIDE_POT,
INSURANCE,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\PostMissingBlind.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\ReceivesCashout.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\Regular.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ public void ParseWinnings_WithColon_Works()
Assert.AreEqual(new WinningsAction("wo_olly:D", WinningsActionType.WINS, 0.57m, 0), handAction);
}

[Test]
public void ParseWinnings_ReceivesCashOut_Works()
{
WinningsAction handAction =
GetGGPokerFastParser().ParseWinnings(@"wo_olly:D: Receives Cashout ($9.98)");

Assert.AreEqual(new WinningsAction("wo_olly:D", WinningsActionType.INSURANCE, 9.98m, 0), handAction);
}

[Test]
public void ParseMiscShowdownLine_Shows_Works()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ public void RunThreeTimes()
TestFullHandHistorySummary(expectedSummary, "RunThreeTimes");
TestHandHistory(expectedHandHistory, "RunThreeTimes");
}

[Test]
public void PostingMissingBlind()
{
Expand Down Expand Up @@ -630,5 +629,83 @@ public void PostingMissingBlind()
TestFullHandHistorySummary(expectedSummary, "PostMissingBlind");
TestHandHistory(expectedHandHistory, "PostMissingBlind");
}

[Test]
public void ReceivesCashout()
{
HandHistorySummary expectedSummary = new HandHistorySummary()
{
GameDescription = new GameDescriptor()
{
PokerFormat = PokerFormat.CashGame,
GameType = GameType.NoLimitHoldem,
Limit = Limit.FromSmallBlindBigBlind(0.25m, 0.5m, Currency.USD),
SeatType = SeatType.FromMaxPlayers(6),
Site = SiteName.GGPoker,
TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
},
DateOfHandUtc = new DateTime(2019, 1, 11, 9, 15, 6),
DealerButtonPosition = 1,
HandId = HandID.From(2281523),
NumPlayersSeated = 6,
TableName = "NLHBronze21",
TotalPot = 16.07m,
Rake = 0.77m,
Jackpot = 0.5m,
Bingo = 0
};
HandHistory expectedHandHistory = new HandHistory()
{
CommunityCards = BoardCards.FromCards("TsQc4d9hAc"),
Players = new PlayerList(new List<Player>
{
new Player("c12290be", 22, 1),
new Player("1xfd8bbx", 123.61m, 2),
new Player("88989dfa", 116.2m, 3, HoleCards.FromCards("6s6d")),
new Player("fdfa4dax", 7, 4, HoleCards.FromCards("Ah5h")),
new Player("fdac21ts", 52.5m, 5),
new Player("Hero", 95.82m, 6, HoleCards.FromCards("2h8h")),
}),
Hero = new Player("Hero",95.82m, 6, HoleCards.FromCards("2h8h")),
RunItMultipleTimes = new RunItTwice[]
{
new RunItTwice
{
Board = BoardCards.FromCards("TsQc4d9hAc"),
Actions = new List<HandAction> { },
Winners = new List<WinningsAction>
{
new WinningsAction("88989dfa", WinningsActionType.INSURANCE, 9.98m, 0),
new WinningsAction("fdfa4dax", WinningsActionType.WINS, 14.8m, 0),
}
},
new RunItTwice {},
new RunItTwice {}
},
Winners = new List<WinningsAction>()
{
new WinningsAction("88989dfa", WinningsActionType.INSURANCE, 9.98m, 0),
new WinningsAction("fdfa4dax", WinningsActionType.WINS, 14.8m, 0)
},
HandActions = new List<HandAction>() {
new HandAction("1xfd8bbx", HandActionType.SMALL_BLIND, -0.25m, Street.Preflop),
new HandAction("88989dfa", HandActionType.BIG_BLIND, -0.5m, Street.Preflop),
new HandAction("fdfa4dax", HandActionType.CALL, 0.5m, Street.Preflop),
new HandAction("fdac21ts", HandActionType.RAISE, 1.82m, Street.Preflop),
new HandAction("Hero", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("c12290be", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("1xfd8bbx", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("88989dfa", HandActionType.CALL, 1.32m, Street.Preflop),
new HandAction("fdfa4dax", HandActionType.RAISE, 6.5m, Street.Preflop, true),
new HandAction("fdac21ts", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("88989dfa", HandActionType.CALL, 5.18m, Street.Preflop),
new HandAction("fdfa4dax", HandActionType.SHOW, Street.Showdown),
new HandAction("88989dfa", HandActionType.SHOW, Street.Showdown),
}
};

TestFullHandHistorySummary(expectedSummary, "ReceivesCashout");
TestHandHistory(expectedHandHistory, "ReceivesCashout");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Poker Hand #HD2281523: Hold'em No Limit ($0.25/$0.5) - 2019/01/11 09:15:06
Table 'NLHBronze21' 6-max Seat #1 is the button
Seat 1: c12290be ($22 in chips)
Seat 2: 1xfd8bbx ($123.61 in chips)
Seat 3: 88989dfa ($116.2 in chips)
Seat 4: fdfa4dax ($7 in chips)
Seat 5: fdac21ts ($52.5 in chips)
Seat 6: Hero ($95.82 in chips)
1xfd8bbx: posts small blind $0.25
88989dfa: posts big blind $0.5
*** HOLE CARDS ***
Dealt to c12290be
Dealt to 1xfd8bbx
Dealt to 88989dfa
Dealt to fdfa4dax
Dealt to fdac21ts
Dealt to Hero [2h 8h]
fdfa4dax: calls $0.5
fdac21ts: raises $1.32 to $1.82
Hero: folds
c12290be: folds
1xfd8bbx: folds
88989dfa: calls $1.32
fdfa4dax: raises $5.18 to $7 and is all-in
fdac21ts: folds
88989dfa: calls $5.18
fdfa4dax: shows [Ah 5h]
88989dfa: shows [6s 6d]
*** FLOP *** [Ts Qc 4d]
*** TURN *** [Ts Qc 4d] [9h]
*** RIVER *** [Ts Qc 4d 9h] [Ac]
88989dfa: Receives Cashout ($9.98)
*** SHOWDOWN ***
fdfa4dax collected $14.8 from pot
*** SUMMARY ***
Total pot $16.07 | Rake $0.77 | Jackpot $0.5 | Bingo $0
Board [Ts Qc 4d 9h Ac]
Seat 1: c12290be (button) folded before Flop (didn't bet)
Seat 2: 1xfd8bbx (small blind) folded before Flop
Seat 3: 88989dfa (big blind) showed [6s 6d] and lost with Pair of Sixes, EV Cashout ($9.98)
Seat 4: fdfa4dax showed [Ah 5h] and won ($14.8) with Pair of Aces
Seat 5: fdac21ts folded before Flop
Seat 6: Hero folded before Flop (didn't bet)
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ public override RunItTwice[] ParseMultipleRuns(string[] handLines)
multipleRuns[currentBoard].Winners.Add(ParseWinnings(line));
}

// expect to look like this:
// xyz: Receives Cashout ($9.98)
//
// Player who chooses to cashout will not have multiple runs.
// Store the info on the first board.
if (line.Contains("Receives Cashout"))
{
line = handLines[i];
multipleRuns[0].Winners.Add(ParseWinnings(line));
}

// *** SHOWDOWN ***
// *** FIRST SHOWDOWN ***
// *** SECOND SHOWDOWN ***
Expand Down Expand Up @@ -671,7 +682,15 @@ private bool ParseLine(string line, ref Street currentStreet, List<HandAction> h
case 's':
if (line.EndsWithFast(" folds") || line.EndsWithFast(" checks")) { break; }
goto default;


// xyz: Receives Cashout ($9.98)
case ')':
if (line.Contains("Receives Cashout"))
{
break;
}
goto default;

default:
return false;
}
Expand All @@ -685,7 +704,7 @@ private bool ParseLine(string line, ref Street currentStreet, List<HandAction> h
throw new HandActionException("", "Invalid State: Street");

default:
if (colonIndex > -1 && line[line.Length - 1] != 't')
if (colonIndex > -1 && !line.Contains("Receives Cashout"))
{
handActions.Add(ParseRegularActionLine(line, colonIndex, currentStreet));
}
Expand Down Expand Up @@ -865,16 +884,34 @@ private BoardCards ParseBoard(string line, BoardCards baseBoard)

public WinningsAction ParseWinnings(string line)
{
// 12b64606 collected $2.5 from pot
int firstSpaceIndex = line.IndexOf(" collected");
int dollarSignIndex = line.LastIndexOf('$');
int amountEndingIndex = line.Length - 8;
if (line.Contains("collected"))
{
// 12b64606 collected $2.5 from pot
int firstSpaceIndex = line.IndexOf(" collected");
int dollarSignIndex = line.LastIndexOf('$');
int amountEndingIndex = line.Length - 8;

string playerName = line.Substring(0, firstSpaceIndex);
string amount = line.Substring(dollarSignIndex, amountEndingIndex - dollarSignIndex - 1);

// 0 for main pot. In gg hand history, it does not show side pot information.
return new WinningsAction(playerName, WinningsActionType.WINS, amount.ParseAmount(), 0);
}
else if (line.Contains("Receives Cashout"))
{
// xyz: Receives Cashout ($9.98)
int lastOpenBracketIndex = line.LastIndexOf('(');
int colonIndex = line.LastIndexOf(":");

string playerName = line.Substring(0, firstSpaceIndex);
string amount = line.Substring(dollarSignIndex, amountEndingIndex - dollarSignIndex - 1);
string playerName = line.Substring(0, colonIndex);
string amount = line.Substring(lastOpenBracketIndex + 1, line.Length - lastOpenBracketIndex - 2);

// 0 for main pot. In gg hand history, it does not show side pot information.
return new WinningsAction(playerName, WinningsActionType.WINS, amount.ParseAmount(), 0);
return new WinningsAction(playerName, WinningsActionType.INSURANCE, amount.ParseAmount(), 0);
}
else
{
throw new Exception("Unknown winning line: " + line);
}
}

private Currency ParseCurrency(string handLine, char currencySymbol)
Expand Down

0 comments on commit f903790

Please sign in to comment.