Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RuijieZ committed Nov 30, 2023
2 parents 955483c + ce6e9d0 commit cec8481
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 14 deletions.
125 changes: 125 additions & 0 deletions HandHistories.Objects.UnitTests/Cards/BoardCardsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,131 @@ public class BoardCardsTests
private static Card C5 = new Card("9", "s");
private static Card C6 = new Card("7", "s");


[Test]
public void BoardCardsTest_EqualityTest_WithDefaultComparison_CompareWithSelf_ReturnTrue()
{
BoardCards emptyBoard = BoardCards.FromCards(String.Empty);
BoardCards boardWithFlop = BoardCards.FromCards("AcQsTh");
BoardCards boardWithTurn = BoardCards.FromCards("AcQsTh2h");
BoardCards boardWithRiver = BoardCards.FromCards("AcQsTh2h3d");

Assert.IsTrue(emptyBoard.Equals(emptyBoard));
Assert.IsTrue(boardWithFlop.Equals(boardWithFlop));
Assert.IsTrue(boardWithTurn.Equals(boardWithTurn));
Assert.IsTrue(boardWithRiver.Equals(boardWithRiver));
}

[Test]
public void BoardCardsTest_EqualityTest_WithDefaultComparison_DifferentOrder_ReturnTrue()
{
BoardCards b1 = BoardCards.ForFlop(C1, C2, C3);
BoardCards b2 = BoardCards.ForFlop(C1, C3, C2);
BoardCards b3 = BoardCards.ForFlop(C2, C1, C3);
BoardCards b4 = BoardCards.ForFlop(C2, C3, C1);
BoardCards b5 = BoardCards.ForFlop(C3, C1, C2);
BoardCards b6 = BoardCards.ForFlop(C3, C2, C1);

Assert.IsTrue(b1.Equals(b2));
Assert.IsTrue(b1.Equals(b3));
Assert.IsTrue(b1.Equals(b4));
Assert.IsTrue(b1.Equals(b5));
Assert.IsTrue(b1.Equals(b6));

Assert.IsTrue(b2.Equals(b3));
Assert.IsTrue(b2.Equals(b4));
Assert.IsTrue(b2.Equals(b5));
Assert.IsTrue(b2.Equals(b6));

Assert.IsTrue(b3.Equals(b4));
Assert.IsTrue(b3.Equals(b5));
Assert.IsTrue(b3.Equals(b6));

Assert.IsTrue(b4.Equals(b5));
Assert.IsTrue(b4.Equals(b6));

Assert.IsTrue(b5.Equals(b6));
}

[Test]
public void BoardCardsTest_FlopEqualityTest_WithDefaultComparision_DifferentCards_ReturnsFalse()
{
BoardCards b1 = BoardCards.ForFlop(C1, C2, C3);
BoardCards b2 = BoardCards.ForFlop(C1, C2, C4);
BoardCards b3 = BoardCards.ForFlop(C1, C3, C4);
BoardCards b4 = BoardCards.ForFlop(C2, C3, C4);

Assert.IsFalse(b1.Equals(b2));
Assert.IsFalse(b1.Equals(b3));
Assert.IsFalse(b1.Equals(b4));
Assert.IsFalse(b2.Equals(b3));
Assert.IsFalse(b2.Equals(b4));
Assert.IsFalse(b3.Equals(b4));
}

[Test]
public void BoardCardsTest_TurnEqualityTest_WithDefaultComparision_ReturnsTrue()
{
BoardCards b1 = BoardCards.ForTurn(C1, C2, C3, C4);
BoardCards b2 = BoardCards.ForTurn(C1, C3, C2, C4);
BoardCards b3 = BoardCards.ForTurn(C3, C2, C1, C4);

Assert.IsTrue(b1.Equals(b2));
Assert.IsTrue(b2.Equals(b3));
Assert.IsTrue(b1.Equals(b3));
}

[Test]
public void BoardCardsTest_TurnEqualityTest_WithDefaultComparision_DifferentCards_ReturnsFalse()
{
BoardCards b1 = BoardCards.ForTurn(C1, C2, C3, C4);
BoardCards b2 = BoardCards.ForTurn(C1, C2, C3, C5);
BoardCards b3 = BoardCards.ForTurn(C1, C2, C5, C4);

Assert.IsFalse(b1.Equals(b2));
Assert.IsFalse(b1.Equals(b3));
Assert.IsFalse(b2.Equals(b3));
}


[Test]
public void BoardCardsTest_TurnEqualityTest_WithDefaultComparision_SameCardsWithDifferentOrder_ReturnsTrue()
{
BoardCards b1 = BoardCards.ForTurn(C1, C2, C3, C4);
BoardCards b2 = BoardCards.ForTurn(C4, C2, C3, C1);

Assert.IsTrue(b1.Equals(b2));
}

[Test]
public void BoardCardsTest_RiverEqualityTest_WithDefaultComparision_DifferentCards_ReturnsFalse()
{
BoardCards b1 = BoardCards.ForRiver(C1, C2, C3, C4, C5);
BoardCards b2 = BoardCards.ForRiver(C1, C2, C3, C4, C6);
BoardCards b3 = BoardCards.ForRiver(C1, C2, C3, C6, C5);

Assert.IsFalse(b1.Equals(b2));
Assert.IsFalse(b1.Equals(b3));
Assert.IsFalse(b2.Equals(b3));
}

[Test]
public void BoardCardsTest_RiverEqualityTestWith_SameCardsWithDifferentOrder_ReturnsTrue()
{
BoardCards b1 = BoardCards.ForRiver(C1, C2, C3, C4, C5);
BoardCards b2 = BoardCards.ForRiver(C4, C2, C3, C1, C5);
BoardCards b3 = BoardCards.ForRiver(C1, C2, C3, C5, C4);
BoardCards b4 = BoardCards.ForRiver(C1, C2, C5, C3, C4);

Assert.IsTrue(b1.Equals(b2));
Assert.IsTrue(b1.Equals(b3));
Assert.IsTrue(b1.Equals(b4));
Assert.IsFalse(b2.EqualsViaHoldemOmahaRule(b3));
Assert.IsFalse(b2.EqualsViaHoldemOmahaRule(b4));
Assert.IsFalse(b3.EqualsViaHoldemOmahaRule(b4));
}


[Test]
public void BoardCardsTest_EqualityTestWithHoldemOmahaRule_CompareWithSelf_ReturnTrue()
{
Expand Down
13 changes: 6 additions & 7 deletions HandHistories.Objects/Cards/CardGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,10 @@ public override string ToString()

public override bool Equals(object obj)
{
bool stringEquality = obj.ToString().Equals(ToString());
if (stringEquality) return true;

CardGroup cardGroup = obj as CardGroup;

if (cardGroup == null) return false;

if (cardGroup.Cards.Count != Cards.Count) return false;

return (cardGroup.Cards.All(c => Cards.Contains(c)));
return Cards.Count == cardGroup.Cards.Count && GetBitMask() == cardGroup.GetBitMask();
}


Expand Down Expand Up @@ -135,5 +129,10 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

private ulong GetBitMask()
{
return Cards.Aggregate(0ul, (mask, card) => mask | 1ul << card.CardIntValue);
}
}
}
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\PostMissingBlind.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SampleHandHistories\GGPoker\CashGame\GeneralHands\ReceivesCashout.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,48 @@ public void ParseRegularActionLine_Bets_Works()
[Test]
public void ParsePostingActionLine_SmallBlind_Works()
{
HandAction handAction = Parser.ParsePostingActionLine(@"1236460a: posts small blind $0.5", 8, false);
bool bigBlindPosted = false;
HandAction handAction = Parser.ParsePostingActionLine(@"1236460a: posts small blind $0.5", 8, ref bigBlindPosted);

Assert.AreEqual(new HandAction("1236460a", HandActionType.SMALL_BLIND, 0.5m, Street.Preflop), handAction);
}

[Test]
public void ParsePostingActionLine_BigBlind_Works()
{
HandAction handAction = Parser.ParsePostingActionLine(@"gaydaddy: posts big blind $1.23", 8, false);
bool bigBlindPosted = false;
HandAction handAction = Parser.ParsePostingActionLine(@"gaydaddy: posts big blind $1.23", 8, ref bigBlindPosted);

Assert.AreEqual(new HandAction("gaydaddy", HandActionType.BIG_BLIND, 1.23m, Street.Preflop), handAction);
}

[Test]
public void ParsePostingActionLine_PostsBigBlind_WithExistingBigBlind_Works()
{
bool bigBlindPosted = true;
HandAction handAction = Parser.ParsePostingActionLine(@"test1234: posts big blind $3", 8, ref bigBlindPosted);

Assert.AreEqual(new HandAction("test1234", HandActionType.POSTS, 3, Street.Preflop), handAction);
}

[Test]
public void ParsePostingActionLine_Straddle_Works()
{
HandAction handAction = Parser.ParsePostingActionLine(@"12365032: straddle $2", 8, false);
bool bigBlindPosted = false;
HandAction handAction = Parser.ParsePostingActionLine(@"12365032: straddle $2", 8, ref bigBlindPosted);

Assert.AreEqual(new HandAction("12365032", HandActionType.STRADDLE, 2.0m, Street.Preflop), handAction);
}

[Test]
public void ParsePostingActionLine_MissedBlind_Works()
{
bool bigBlindPosted = false;
HandAction handAction = Parser.ParsePostingActionLine(@"af3acs39: posts missed blind $0.5", 8, ref bigBlindPosted);

Assert.AreEqual(new HandAction("af3acs39", HandActionType.POSTS_DEAD, 0.5m, Street.Preflop), handAction);
}

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

[Test]
public void PostingMissingBlind()
{
HandHistorySummary expectedSummary = new HandHistorySummary()
{
GameDescription = new GameDescriptor()
{
PokerFormat = PokerFormat.CashGame,
GameType = GameType.NoLimitHoldem,
Limit = Limit.FromSmallBlindBigBlind(0.5m, 1m, Currency.USD),
SeatType = SeatType.FromMaxPlayers(6),
Site = SiteName.GGPoker,
TableType = TableType.FromTableTypeDescriptions(TableTypeDescription.Regular)
},
DateOfHandUtc = new DateTime(2018, 12, 28, 11, 00, 52),
DealerButtonPosition = 5,
HandId = HandID.From(54233001),
NumPlayersSeated = 6,
TableName = "NLHGold19",
TotalPot = 12,
Rake = 0.6m,
Jackpot = 0,
Bingo = 0
};
HandHistory expectedHandHistory = new HandHistory()
{
CommunityCards = BoardCards.FromCards("Kc4c2h"),
Players = new PlayerList(new List<Player>
{
new Player("343kk954", 60, 1),
new Player("Hero", 100.23m, 2, HoleCards.FromCards("ks2d")),
new Player("b4mnx231", 175.41m, 3),
new Player("15yfdsaa", 20, 4),
new Player("mkacefi1a", 22.84m, 5),
new Player("142dsaca", 98.5m, 6),
}),
Hero = new Player("Hero", 100.23m, 2, HoleCards.FromCards("ks2d")),
RunItMultipleTimes = new RunItTwice[]
{
new RunItTwice
{
Board = BoardCards.FromCards("Kc4c2h"),
Actions = new List<HandAction> { },
Winners = new List<WinningsAction>
{
new WinningsAction("15yfdsaa", WinningsActionType.WINS, 11.4m, 0)
}
},
new RunItTwice {},
new RunItTwice {}
},
Winners = new List<WinningsAction>() { new WinningsAction("15yfdsaa", WinningsActionType.WINS, 11.4m, 0) },
HandActions = new List<HandAction>() {
new HandAction("142dsaca", HandActionType.SMALL_BLIND, -0.5m, Street.Preflop),
new HandAction("343kk954", HandActionType.BIG_BLIND, -1, Street.Preflop),
new HandAction("15yfdsaa", HandActionType.POSTS_DEAD, -0.5m, Street.Preflop),
new HandAction("15yfdsaa", HandActionType.POSTS, -1, Street.Preflop),
new HandAction("Hero", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("b4mnx231", HandActionType.CALL, 1, Street.Preflop),
new HandAction("15yfdsaa", HandActionType.RAISE, 4m, Street.Preflop),
new HandAction("mkacefi1a", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("142dsaca", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("343kk954", HandActionType.FOLD, 0, Street.Preflop),
new HandAction("b4mnx231", HandActionType.CALL, 4, Street.Preflop),
new HandAction("b4mnx231", HandActionType.CHECK, 0, Street.Flop),
new HandAction("15yfdsaa", HandActionType.BET, 12, Street.Flop),
new HandAction("b4mnx231", HandActionType.FOLD, 0, Street.Flop),
new HandAction("15yfdsaa", HandActionType.UNCALLED_BET, 12, Street.Flop),
}
};
TestFullHandHistorySummary(expectedSummary, "PostMissingBlind");
TestHandHistory(expectedHandHistory, "PostMissingBlind");
}

[Test]
public void ReceivesCashout()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Poker Hand #HD54233001: Hold'em No Limit ($0.5/$1) - 2018/12/28 11:00:52
Table 'NLHGold19' 6-max Seat #5 is the button
Seat 1: 343kk954 ($60 in chips)
Seat 2: Hero ($100.23 in chips)
Seat 3: b4mnx231 ($175.41 in chips)
Seat 4: 15yfdsaa ($20 in chips)
Seat 5: mkacefi1a ($22.84 in chips)
Seat 6: 142dsaca ($98.5 in chips)
142dsaca: posts small blind $0.5
343kk954: posts big blind $1
15yfdsaa: posts missed blind $0.5
15yfdsaa: posts big blind $1
*** HOLE CARDS ***
Dealt to 343kk954
Dealt to Hero [ks 2d]
Dealt to b4mnx231
Dealt to 15yfdsaa
Dealt to mkacefi1a
Dealt to 142dsaca
Hero: folds
b4mnx231: calls $1
15yfdsaa: raises $4 to $5
mkacefi1a: folds
142dsaca: folds
343kk954: folds
b4mnx231: calls $4
*** FLOP *** [Kc 4c 2h]
b4mnx231: checks
15yfdsaa: bets $12
b4mnx231: folds
Uncalled bet ($12) returned to 15yfdsaa
*** SHOWDOWN ***
15yfdsaa collected $11.4 from pot
*** SUMMARY ***
Total pot $12 | Rake $0.6 | Jackpot $0 | Bingo $0
Board [Kc 4c 2h]
Seat 1: 343kk954 (big blind) folded before Flop
Seat 2: Hero folded before Flop (didn't bet)
Seat 3: b4mnx231 folded on the Flop
Seat 4: 15yfdsaa won ($11.4)
Seat 5: mkacefi1a (button) folded before Flop (didn't bet)
Seat 6: 142dsaca (small blind) folded before Flop
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ public int ParseBlindActions(string[] handLines, List<HandAction> handActions, i

if (colonIndex != -1)
{
var action = ParsePostingActionLine(line, colonIndex, bigBlind);
bigBlind = action.HandActionType == HandActionType.BIG_BLIND;
var action = ParsePostingActionLine(line, colonIndex, ref bigBlind);
handActions.Add(action);
}
}
throw new HandActionException(string.Join(Environment.NewLine, handLines), "No end of posting actions");
}

public static HandAction ParsePostingActionLine(string actionLine, int colonIndex, bool bigBlindPosted)
public static HandAction ParsePostingActionLine(string actionLine, int colonIndex, ref bool bigBlindPosted)
{
string playerName = actionLine.Substring(0, colonIndex);
bool isAllIn = false;
Expand Down Expand Up @@ -182,6 +181,7 @@ public static HandAction ParsePostingActionLine(string actionLine, int colonInde
case 'b':
firstDigitIndex = colonIndex + 18;
handActionType = bigBlindPosted ? HandActionType.POSTS : HandActionType.BIG_BLIND;
bigBlindPosted = true;
break;

// xyz: straddle $2
Expand All @@ -190,6 +190,12 @@ public static HandAction ParsePostingActionLine(string actionLine, int colonInde
handActionType = HandActionType.STRADDLE;
break;

// xyz: posts missed blind $0.5
case 'm':
firstDigitIndex = colonIndex + 21;
handActionType = HandActionType.POSTS_DEAD;
break;

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

0 comments on commit cec8481

Please sign in to comment.