public double GetOddsOfWinning(SharedCards shared) { PokerDeck deck = new PokerDeck(new RandomNumberGenerator()); List <Card> remainingCards = new List <Card>(); while (deck.CardsRemaining > 0) { Card nextCard = deck.PickCard(); if (!nextCard.Equals(First) && !nextCard.Equals(Second) && shared.Cards.All(c => !c.Equals(nextCard))) { remainingCards.Add(nextCard); } } List <HoldemHand> possibleHands = new List <HoldemHand>(); for (int firstIndex = 0; firstIndex < remainingCards.Count - 1; firstIndex++) { for (int secondIndex = firstIndex + 1; secondIndex < remainingCards.Count; secondIndex++) { possibleHands.Add(new HoldemHand { First = remainingCards[firstIndex], Second = remainingCards[secondIndex] }); } } double potentialWins = 0; double potentialDraws = 0; double potentialLosses = 0; PokerHand myBestHand = GetBestHand(shared); foreach (HoldemHand hand in possibleHands) { int compareTo = myBestHand.CompareTo(hand.GetBestHand(shared)); if (compareTo < 0) { potentialLosses++; } else if (compareTo > 0) { potentialWins++; } else { potentialDraws++; } } var pairs = possibleHands .Where(hand => hand.GetBestHand(shared).GetHandRank() == PokerHand.HandRank.Pair); return(potentialWins / possibleHands.Count); }
public Round(INumberGenerator numberGenerator) { deck = new PokerDeck(numberGenerator); player = new HoldemHand { First = deck.PickCard(), Second = deck.PickCard() }; computer = new HoldemHand { First = deck.PickCard(), Second = deck.PickCard() }; shared = new SharedCards() { Cards = new Card[] { deck.PickCard(), deck.PickCard(), deck.PickCard(), deck.PickCard(), deck.PickCard() } }; }
public PokerHand GetBestHand(SharedCards shared) { List <Card> cards = new List <Card>(); cards.Add(First); cards.Add(Second); cards.AddRange(shared.Cards); List <PokerHand> possibleHands = GetAllPossibleHands(cards); PokerHand bestHand = possibleHands[0]; for (int index = 1; index < possibleHands.Count; index++) { if (bestHand.CompareTo(possibleHands[index]) < 0) { bestHand = possibleHands[index]; } } return(bestHand); }