public override HandValue CheckCombination(List <Card> cards) { var request = from c in cards group c by c.Suit into grp where grp.Count() >= 5 select grp; if (request.Count() == 1) { List <Cards.Card> oneSuitCards = request.First().OrderByDescending(c => c.Value).ToList(); // constant that sets distance between highest and lowest card in the combination const int Range = 4; for (int i = oneSuitCards.Count() - 1; i - Range >= 0; i--) { if (oneSuitCards[i].Value - Range == oneSuitCards[i - Range].Value) { List <Card> vinningCombination = oneSuitCards.Skip(i - Range).Take(5).ToList(); COMBINATION combination = COMBINATION.StraightFlush; return(new HandValue(cards, vinningCombination, combination)); } } } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } else { return(null); } }
public override HandValue CheckCombination(List <Card> cards) { var cardsInOrder = cards.GroupBy(c => c.Value).OrderBy(g => g.Key).ToList(); // constant that sets distance between highest and lowest card in the combination const int Range = 4; for (int i = cardsInOrder.Count() - 1; i - Range >= 0; i--) { if (cardsInOrder[i].Key - Range == cardsInOrder[i - Range].Key) { List <Card> vinningCombination = cardsInOrder.Skip(i - Range).Take(5).Select(g => g.First()).ToList(); COMBINATION combination = COMBINATION.Straight; return(new HandValue(cards, vinningCombination, combination)); } } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } else { return(null); } }
public override HandValue CheckCombination(List <Card> cards) { var tripples = from c in cards group c by c.Value into grp where grp.Count() == 3 orderby grp.Key descending select grp; var pairs = from c in cards group c by c.Value into grp where grp.Count() == 2 orderby grp.Key descending select grp; if (tripples.Count() >= 1 && pairs.Count() >= 1) { List <Cards.Card> vinningCombination = tripples.First().Union(pairs.First()).ToList(); COMBINATION combination = COMBINATION.FullHouse; return(new HandValue(cards, vinningCombination, combination)); } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } else { return(null); } }
public override HandValue CheckCombination(List <Cards.Card> cards) { var request = from c in cards group c by c.Suit into gr where gr.Count() >= 5 select gr; if (request.Count() == 1) { List <Card> OneSuitCards = request.First().OrderByDescending(c => c.Value).ToList(); if (OneSuitCards[0].Value == VALUE.ACE && OneSuitCards[4].Value == VALUE.TEN) { List <Card> vinningCombination = OneSuitCards.Take(5).ToList(); COMBINATION combination = COMBINATION.RoyalStraightFlush; return(new HandValue(cards, vinningCombination, combination)); } } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } return(null); }
public override HandValue CheckCombination(List <Card> cards) { var OneValueCards = from c in cards group c by c.Value into grp where grp.Count() >= 3 select grp; if (OneValueCards.Count() == 1) { List <Cards.Card> vinningCombination = OneValueCards.First().ToList(); COMBINATION combination = COMBINATION.ThreeKind; return(new HandValue(cards, vinningCombination, combination)); } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } else { return(null); } }
public override HandValue CheckCombination(List <Card> cards) { var OneValueCards = from c in cards group c by c.Value into grp where grp.Count() == 2 orderby grp.Key descending select grp; if (OneValueCards.Count() >= 2) { List <Cards.Card> vinningCombination = OneValueCards.First().Union(OneValueCards.Take(2).Last()).ToList(); COMBINATION combination = COMBINATION.TwoPairs; return(new HandValue(cards, vinningCombination, combination)); } if (_nextChecker != null) { return(_nextChecker.CheckCombination(cards)); } else { return(null); } }
/// <summary> /// Saves the result of checking combination /// </summary> /// <param name="cards">All the cards from hand and table</param> /// <param name="vinningCombination">The cards that form the combination</param> /// <param name="combination">The type of combination formed in this handValue</param> public HandValue(List <Card> cards, List <Card> vinningCombination, COMBINATION combination) { Cards = cards; VinningCombination = vinningCombination; Combination = combination; }