示例#1
0
        public void Shuffle()
        {
            int count = DeckCount;

            while (count > 1)
            {
                count--;
                int         randomNumber  = rng.Next(count + 1);
                PlayingCard currentNumber = Cards[randomNumber];
                Cards[randomNumber] = Cards[count];
                Cards[count]        = currentNumber;
            }
        }
示例#2
0
        public void SetHand(PlayingCard card)
        {
            if (PlayerHand.Count == 5)
            {
                throw new ApplicationException("Hand is full. Cannot receive more cards.");
            }

            if (PlayerHand == null || PlayerHand.Count < 5)
            {
                PlayerHand.Add(card);
                HandSum += card.CardValue;
            }
        }
示例#3
0
        public int CheckHandValue(Player currentPlayer, int attempt = 0)
        {
            currentPlayer.SortHand();
            List <PlayingCard> currentHand = currentPlayer.SortedHand;
            PlayingCard        firstCard   = currentHand[attempt];
            var groups      = currentHand.GroupBy(c => c.CardValue).OrderByDescending(grp => grp.Count());
            var mostMatches = groups.First();
            int value       = currentHand[attempt].CardValue;

            if (mostMatches.Count() >= 2 && attempt == 0)
            {
                value = mostMatches.Key;
            }

            return(value);
        }
示例#4
0
        public Hands CheckHand(Player currentPlayer)
        {
            Hands handType = Hands.HighCard;

            currentPlayer.SortHand();
            List <PlayingCard> currentHand = currentPlayer.SortedHand;
            PlayingCard        firstCard   = currentHand[0];
            var groups      = currentHand.GroupBy(c => c.CardValue).OrderByDescending(grp => grp.Count());
            var mostMatches = groups.First();

            if (currentHand.Where(c => c.CardSuit == firstCard.CardSuit).Count() == 5)
            {
                handType = Hands.Flush;
            }

            if (groups.Count() == 2 && mostMatches.Count() == 4)
            {
                handType = Hands.FourOfAKind;
            }

            if (groups.Count() == 2 && mostMatches.Count() == 3)
            {
                handType = Hands.FullHouse;
            }

            if (groups.Count() == 3 && mostMatches.Count() == 3)
            {
                handType = Hands.ThreeOfAKind;
            }

            if (groups.Count() == 3 && mostMatches.Count() == 2)
            {
                handType = Hands.TwoPair;
            }

            if (groups.Count() == 4 && mostMatches.Count() == 2)
            {
                handType = Hands.OnePair;
            }

            return(handType);
        }