public PokerHands EvaluatePokerHand(PokerHand pokerHand) { var pokerBl = new PokerBL(); if (pokerBl.isFlush(pokerHand)) { return(PokerHands.Flush); } else if (pokerBl.isThreeOfAKind(pokerHand)) { return(PokerHands.ThreeOfAKind); } else if (pokerBl.isOnePair(pokerHand)) { return(PokerHands.OnePair); } else { return(PokerHands.HighCard); } }
public PokerHand EvaluateWinningHand(List <PokerHand> pokerHandList) { var pokerBl = new PokerBL(); foreach (var pokerHand in pokerHandList) { pokerHand.PokerScore = pokerBl.EvaluatePokerHand(pokerHand); } var winningHand = pokerHandList.OrderByDescending(x => x.PokerScore).First(); //Check if winning hand has competition var duplicateList = pokerHandList.Where(x => x.PokerScore == winningHand.PokerScore).ToList(); var hasDuplicate = duplicateList.Count > 1; //Declare winner if (!hasDuplicate) { return(winningHand); } else { //Perform Tie Breaker var highScore = winningHand.PokerScore; var tieBreakerList = pokerHandList.Where(x => x.PokerScore == highScore).ToList(); if (highScore == PokerHands.HighCard || highScore == PokerHands.Flush) { foreach (var hand in tieBreakerList) { hand.HighCard = pokerBl.GetHighCard(hand); } var highCardWinner = tieBreakerList.OrderByDescending(x => x.HighCard).First(); return(highCardWinner); } else if (highScore == PokerHands.OnePair) { //Determine the higher pair foreach (var hand in tieBreakerList) { hand.HighCard = pokerBl.GetPairScore(hand); } var highPairWinner = tieBreakerList.OrderByDescending(x => x.HighCard).First(); return(highPairWinner); } else if (highScore == PokerHands.ThreeOfAKind) { foreach (var hand in tieBreakerList) { hand.HighCard = pokerBl.GetTrioScore(hand); } var highTrioWinner = tieBreakerList.OrderByDescending(x => x.HighCard).First(); return(highTrioWinner); } else { return(null); } } }