public bool IsSraightFlush(Hand hand) { if (IsFlush(hand)) return IsStraight(hand); return false; }
public bool IsFullHouse(Hand hand) { IEnumerable<IGrouping<Rank, Card>> groupings = hand.GroupBy(c => c.Rank); return(groupings.Count() == 2 && (groupings.ElementAt(0).Count() == 2 || groupings.ElementAt(0).Count() == 3)); }
public bool IsFourOfAKind(Hand hand) { foreach (IGrouping<Rank, Card> grouping in hand.GroupBy(c => c.Rank)) if (grouping.Count() == 4) return true; return false; }
public bool IsRoyalFlush(Hand hand) { Card bestCardRank = (from c in hand where c.Rank.Value == 14 select c).FirstOrDefault(); if (bestCardRank != null) return IsSraightFlush(hand); return false; }
/// <summary> /// TODO Move all of this to the game descriptor class /// </summary> /// <param name="hand"></param> /// <returns></returns> public Hand.HandType GetBestHandType(Hand hand) { if (IsRoyalFlush(hand)) return Hand.HandType.RoyalFlush; else if (IsSraightFlush(hand)) return Hand.HandType.StraightFlush; else if (IsFourOfAKind(hand)) return Hand.HandType.FourOfAkind; else if (IsFullHouse(hand)) return Hand.HandType.FullHouse; else if (IsFlush(hand)) return Hand.HandType.Flush; else if (IsStraight(hand)) return Hand.HandType.Straight; else if (IsThreeOfAKind(hand)) return Hand.HandType.ThreeOfAKind; else if (IsTwoPair(hand)) return Hand.HandType.TwoPair; else if (IsTwoOfAKind(hand)) return Hand.HandType.TwoOfAKind; return Hand.HandType.HighCard; }
public bool IsStraight(Hand hand) { CardCollection cards = new CardCollection(hand.OrderBy(c => c.Rank.Value)); for (int i = 0; i < cards.Count; ++i) { if (cards.Count > i) { if ((cards[i].Rank.Value + 1) != cards[i + 1].Rank.Value) return false; } } return true; }
public bool IsHighCard(Hand hand) { return true; }
public bool IsFlush(Hand hand) { return (hand.Select(c => c.Suit).Distinct().Count() == 1); }
public bool IsTwoPair(Hand hand) { IEnumerable<IGrouping<Rank, Card>> groupings = hand.GroupBy(c => c.Rank); return ((from g in groupings where g.Count() == 2 select g).Count() == 2); }
public Player(Hand hand) { _hand = hand; }
public Player() { _hand = new Hand(); }
public CardCollectionOperationResult RemoveCard(Hand hand, Card card) { hand.Remove(card); return new CardCollectionOperationResult(hand, card); }
public Hand.HandType GetBestHand(Hand hand) { HandRankManager rankManager = new HandRankManager(); return rankManager.GetBestHandType(hand); }
public CardCollectionOperationResult AddCard(Hand hand, Card card) { hand.Add(card); return new CardCollectionOperationResult(hand); }