/// <summary> /// Evaluates the handrank and maps it to the corresponding hand strength bucket. /// </summary> /// <param name="board">current community cards (or board)</param> /// <param name="holeCards">current hole cards of the player</param> /// <returns></returns> public static HandStrengthBucket MapToBucket(List <Card> board, List <Card> holeCards) { var evaluator = new HandEvaluator(holeCards, board); var rank = evaluator.GetHandRank(); if (rank >= HandRank.TwoPairs) { return(HandStrengthBucket.TopHands); } var topCards = evaluator.GetTopFiveCards(rank); if (rank == HandRank.Pair) { var pairValue = topCards.First().Value; var boardOrderedByValue = board.OrderBy(x => x.Value); var lowestValue = boardOrderedByValue.First().Value; var topValue = boardOrderedByValue.Last().Value; if (pairValue >= topValue) { // either a overpair (e.g. Pocket Aces) or top pair return(HandStrengthBucket.TopPair); } else if (pairValue < topValue && pairValue > lowestValue) { return(HandStrengthBucket.MiddlePair); } else { return(HandStrengthBucket.LowPair); } } else { //highcard bool hasAce = topCards.Any(x => x.Value == CardValue.Ace); if (hasAce) { return(HandStrengthBucket.HighCardAce); } else { return(HandStrengthBucket.HighCardElse); } } }
public void TestStraightCards() { var holeCards = new List <Card>(); holeCards.Add(new Card(CardSuit.Diamonds, CardValue.Six)); holeCards.Add(new Card(CardSuit.Clubs, CardValue.Ten)); var board = new List <Card>(); board.Add(new Card(CardSuit.Diamonds, CardValue.Nine)); board.Add(new Card(CardSuit.Spades, CardValue.Seven)); board.Add(new Card(CardSuit.Hearts, CardValue.Six)); board.Add(new Card(CardSuit.Clubs, CardValue.Eight)); var evaluator = new HandEvaluator(holeCards, board); var topCards = evaluator.GetTopFiveCards(evaluator.GetHandRank()); Assert.AreEqual(topCards.Count, 5); }