private void StraightCards(List <Card> cards) { var hands = new List <List <Card> >(); if (cards.Count() >= 5) { hands.Add(cards.Take(5).ToList()); } if (cards.Count() >= 6) { hands.Add(cards.Skip(1).Take(5).ToList()); var tmpCards = cards.Take(4).ToList(); tmpCards.AddRange(cards.Skip(5).Take(1)); hands.Add(tmpCards.ToList()); } if (cards.Count() == 7) { hands.Add(cards.Skip(2).Take(5).ToList()); var tmpCards = cards.Take(4).ToList(); tmpCards.AddRange(cards.Skip(6).Take(1)); hands.Add(tmpCards.ToList()); var tmpCards1 = cards.Skip(1).Take(4).ToList(); tmpCards1.AddRange(cards.Skip(6).Take(1)); hands.Add(tmpCards1.ToList()); } foreach (var hand in hands) { if (HandValue.Equals(Hands.RoyalStraightFlush)) { break; } IsStraight(hand); } }
public (List <Card> Cards, Hands HandValue, Suits Suit) EvaluateHand(List <Card> cards) { HandValue = Hands.Nothing; Suit = 0; BestCards.Clear(); if (cards.Count() >= 2) { #region Sort the cards cards.Sort(); #endregion #region Royal Straight Flush & Straight Flush & Straight StraightCards(cards); if (HandValue.Equals(Hands.RoyalStraightFlush) || HandValue.Equals(Hands.StraightFlush)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Four of a kind IsFourOfAKind(cards); if (HandValue.Equals(Hands.FourOfAKind)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Full House IsFullHouse(cards); if (HandValue.Equals(Hands.FullHouse)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Flush FlushCards(cards); if (HandValue.Equals(Hands.Flush)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Straight if (HandValue.Equals(Hands.Straight)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Three of a Kind IsThreeOfAKind(cards); if (HandValue.Equals(Hands.ThreeOfAKind)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Two Pair IsTwoPair(cards); if (HandValue.Equals(Hands.TwoPair)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Pair IsPair(cards); if (HandValue.Equals(Hands.Pair)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region High Card HighCard(cards); #endregion } return(Cards : BestCards, HandValue : HandValue, Suit : Suit); }