예제 #1
0
 public TexasHoldemGame()
 {
     user        = new Player();
     computer    = new Player();
     deck        = new Deck();
     pot         = 0;
     sharedCards = new SharedCards();
 }
예제 #2
0
        public Tuple <double, double, double> GetOddsOfWinningDrawingAndLosing(SharedCards shared)
        {
            Deck        deck           = new Deck();
            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++;
                }
            }

            return(new Tuple <double, double, double>(potentialWins / possibleHands.Count, potentialDraws / possibleHands.Count, potentialLosses / possibleHands.Count));
        }
예제 #3
0
        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);
        }