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; } }
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; } }
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); }
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); }