Skip to content

Commit

Permalink
Merge pull request #90 from RuijieZ/insurance-fee-parsing
Browse files Browse the repository at this point in the history
Parse paying insurance fee as an action for GGPoker parser
  • Loading branch information
ItalyToast committed Dec 1, 2023
2 parents f903790 + b3fdf48 commit 34172cc
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 1 deletion.
2 changes: 2 additions & 0 deletions HandHistories.Objects/Actions/HandAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public static decimal GetAdjustedAmount(decimal amount, HandActionType type)
return 0.0M; // overwrite any $ talk in the chat
case HandActionType.JACKPOTCONTRIBUTION:
return 0.0M; // does not affect pot, as it goes to a jackpot
case HandActionType.PAYS_INSURANCE_FEE:
return amount * -1;
}

throw new ArgumentException("GetAdjustedAmount: Uknown action " + type + " to have amount " + amount);
Expand Down
1 change: 1 addition & 0 deletions HandHistories.Objects/Actions/HandActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public enum HandActionType
FEELING_CHANGE,
GAME_CANCELLED,
RABBIT,
PAYS_INSURANCE_FEE,
/// <summary>
/// this is primarily used by the parsers internally, Use HandAction.IsAllIn instead
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\MultiplePosts.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\PaysCashoutFee.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\PostMissingBlind.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public void ParseRegularActionLine_Bets_Works()
Assert.AreEqual(new HandAction("MS13ZEN", HandActionType.BET, 1.76m, Street.River), handAction);
}


[Test]
public void ParseRegularActionLine_PaysCashoutFee_Works()
{
HandAction handAction =
GetGGPokerFastParser().ParseRegularActionLine(@"MS13ZEN: Pays Cashout Risk ($22.68)", 7, Street.River);

Assert.AreEqual(new HandAction("MS13ZEN", HandActionType.PAYS_INSURANCE_FEE, 22.68m, Street.Showdown), handAction);
}


[Test]
public void ParsePostingActionLine_SmallBlind_Works()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private HandHistory TestHandHistory(HandHistory expectedHandHistory, string file
string handText = SampleHandHistoryRepository.GetHandExample(PokerFormat.CashGame, Site, "GeneralHands", fileName);

HandHistory handHistory = GetParser().ParseFullHandHistory(handText, true);

Assert.IsTrue(expectedHandHistory.CommunityCards == handHistory.CommunityCards);
Assert.IsTrue(expectedHandHistory.Players.Equals(handHistory.Players));
Assert.AreEqual(expectedHandHistory.Hero, handHistory.Hero);
Expand Down Expand Up @@ -707,5 +708,82 @@ public void ReceivesCashout()
TestFullHandHistorySummary(expectedSummary, "ReceivesCashout");
TestHandHistory(expectedHandHistory, "ReceivesCashout");
}

[Test]
public void PaysCashoutFee()
{
HandHistorySummary expectedSummary = new HandHistorySummary()
{
GameDescription = new GameDescriptor()
{
PokerFormat = PokerFormat.CashGame,
GameType = GameType.NoLimitHoldem,
Limit = Limit.FromSmallBlindBigBlind(1m, 2m, Currency.USD),
SeatType = SeatType.FromMaxPlayers(6),
Site = SiteName.GGPoker,
TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
},
DateOfHandUtc = new DateTime(2019, 1, 22, 19, 56, 3),
DealerButtonPosition = 4,
HandId = HandID.From(149101),
NumPlayersSeated = 6,
TableName = "NLHGold14",
TotalPot = 251.86m,
Rake = 6m,
Jackpot = 2m,
Bingo = 0
};

HandHistory expectedHandHistory = new HandHistory()
{
CommunityCards = BoardCards.FromCards("8d9h2cTsQh"),
Players = new PlayerList(new List<Player>
{
new Player("vda35fd1", 512.43m, 1),
new Player("fma3fca1", 52.19m, 2),
new Player("oiesfcv1", 146.39m, 3, HoleCards.FromCards("KdKc")),
new Player("Hero", 103m, 4, HoleCards.FromCards("Qs6h")),
new Player("tyx36123", 122.73m, 5, HoleCards.FromCards("3d3h")),
new Player("b6887901", 100.81m, 6),
}),
Hero = new Player("Hero", 103m, 4, HoleCards.FromCards("Qs6h")),
RunItMultipleTimes = new RunItTwice[]
{
new RunItTwice
{
Board = BoardCards.FromCards("8d9h2cTsQh"),
Actions = new List<HandAction> { },
Winners = new List<WinningsAction>
{
new WinningsAction("oiesfcv1", WinningsActionType.WINS, 243.86m, 0),
}
},
new RunItTwice {},
new RunItTwice {}
},
Winners = new List<WinningsAction>()
{
new WinningsAction("oiesfcv1", WinningsActionType.WINS, 243.86m, 0),
},
HandActions = new List<HandAction>() {
new HandAction("tyx36123", HandActionType.SMALL_BLIND, -1m, Street.Preflop),
new HandAction("b6887901", HandActionType.BIG_BLIND, -2m, Street.Preflop),
new HandAction("vda35fd1", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("fma3fca1", HandActionType.RAISE, 4.4m, Street.Preflop),
new HandAction("oiesfcv1", HandActionType.CALL, 4.4m, Street.Preflop),
new HandAction("Hero", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("tyx36123", HandActionType.RAISE, 121.73m, Street.Preflop, true),
new HandAction("b6887901", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("fma3fca1", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("oiesfcv1", HandActionType.CALL, 118.33m, Street.Preflop),
new HandAction("tyx36123", HandActionType.SHOW, 0m, Street.Showdown),
new HandAction("oiesfcv1", HandActionType.SHOW, 0m, Street.Showdown),
new HandAction("oiesfcv1", HandActionType.PAYS_INSURANCE_FEE, 22.68m, Street.Showdown),
},
};

TestFullHandHistorySummary(expectedSummary, "PaysCashoutFee");
TestHandHistory(expectedHandHistory, "PaysCashoutFee");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Poker Hand #HD149101: Hold'em No Limit ($1/$2) - 2019/01/22 19:56:03
Table 'NLHGold14' 6-max Seat #4 is the button
Seat 1: vda35fd1 ($512.43 in chips)
Seat 2: fma3fca1 ($52.19 in chips)
Seat 3: oiesfcv1 ($146.39 in chips)
Seat 4: Hero ($103 in chips)
Seat 5: tyx36123 ($122.73 in chips)
Seat 6: b6887901 ($100.81 in chips)
tyx36123: posts small blind $1
b6887901: posts big blind $2
*** HOLE CARDS ***
Dealt to vda35fd1
Dealt to fma3fca1
Dealt to oiesfcv1
Dealt to Hero [Qs 6h]
Dealt to tyx36123
Dealt to b6887901
vda35fd1: folds
fma3fca1: raises $2.4 to $4.4
oiesfcv1: calls $4.4
Hero: folds
tyx36123: raises $118.33 to $122.73 and is all-in
b6887901: folds
fma3fca1: folds
oiesfcv1: calls $118.33
tyx36123: shows [3d 3h]
oiesfcv1: shows [Kd Kc]
*** FLOP *** [8d 9h 2c]
oiesfcv1: Chooses to EV Cashout
*** TURN *** [8d 9h 2c] [Ts]
*** RIVER *** [8d 9h 2c Ts] [Qh]
oiesfcv1: Pays Cashout Risk ($22.68)
*** SHOWDOWN ***
oiesfcv1 collected $243.86 from pot
*** SUMMARY ***
Total pot $251.86 | Rake $6 | Jackpot $2 | Bingo $0
Board [8d 9h 2c Ts Qh]
Seat 1: vda35fd1 folded before Flop (didn't bet)
Seat 2: fma3fca1 folded before Flop
Seat 3: oiesfcv1 showed [Kd Kc] and won ($243.86) with Pair of Kings, Cashout Risk ($22.68)
Seat 4: Hero (button) folded before Flop (didn't bet)
Seat 5: tyx36123 (small blind) showed [3d 3h] and lost with Pair of Treys
Seat 6: b6887901 (big blind) folded before Flop
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ private bool ParseLine(string line, ref Street currentStreet, List<HandAction> h

// xyz: Receives Cashout ($9.98)
case ')':
if (line.Contains("Receives Cashout"))
if (line.Contains("Cashout"))
{
break;
}
Expand Down Expand Up @@ -775,6 +775,15 @@ public HandAction ParseRegularActionLine(string actionLine, int colonIndex, Stre
amount = actionLine.Substring(firstDigitIndex, actionLine.Length - firstDigitIndex).ParseAmount();
actionType = HandActionType.RAISE;
break;

//xyz: Pays Cashout Risk ($22.68)
case 'P':
firstDigitIndex = actionLine.LastIndexOf(' ') + 2;
amount = actionLine.Substring(firstDigitIndex, actionLine.Length - firstDigitIndex-1).ParseAmount();
actionType = HandActionType.PAYS_INSURANCE_FEE;
currentStreet = Street.Showdown;
break;

default:
throw new HandActionException(actionLine, "ParseRegularActionLine: Unrecognized line:" + actionLine);
}
Expand Down

0 comments on commit 34172cc

Please sign in to comment.