public bool Calculate(IPokerHand hand) { var straight = new Straight(hand); var flush = new Flush(hand); return(straight.IsHighRank && flush.IsHighRank); }
/// <summary> /// Checks if a Hand is already contained in this list /// </summary> /// <param name="givenHand">Hand to check for</param> /// <returns>true if the hand does exist, false if it doesn't</returns> public bool HandExists(IPokerHand givenHand) { try { if (givenHand == null) { throw new ArgumentNullException("GivenHand"); } foreach (IPokerHand pokerHand in this) { if (givenHand.Equals(pokerHand)) { return(true); } } return(false); } catch (ArgumentNullException excep) { Log.Error("Unhandled", excep); return(false); } catch (Exception excep) { if (givenHand != null) { excep.Data.Add("Looking for Hand ", givenHand.GameId); } Log.Error("Unhandled", excep); return(false); } }
/// <summary> /// Adds a hand, but only if it is not in the Hand collection yet /// </summary> /// <param name="hand"></param> /// <returns>true if it was added, false if it was already in the Hand collection</returns> public bool AddHand(IPokerHand hand) { try { if (hand == null) { throw new ArgumentNullException("hand"); } // Make sure it doesn't exist yet if (!HandExists(hand)) { _hands.Add(hand); return(true); } else { return(false); } } catch (ArgumentNullException excep) { Log.Error("Ignore Hand", excep); } return(false); }
static bool HandIsNotYetInDatabase(IPokerHand convertedHand, ISession session) { IQuery query = session.GetNamedQuery(FindConvertedPokerHandByGameIdAndSite); return(SetParametersForFindConvertedPokerHand(query, convertedHand.GameId, convertedHand.Site) .UniqueResult <IConvertedPokerHand>() == null); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHand = (OnePair)ConvertToThisType(other); if (Pair.First().Rank > otherHand.Pair.First().Rank) { return(1); } if (Pair.First().Rank < otherHand.Pair.First().Rank) { return(1); } return(Utils.ComapreCards(Kickers, otherHand.Kickers)); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHighCard = Utils.GetHighestCard(other.Cards); var myHighCard = Utils.GetHighestCard(Cards); if (myHighCard.Rank > otherHighCard.Rank) { return(1); } if (myHighCard.Rank < otherHighCard.Rank) { return(-1); } return(0); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHand = (FullHouse)ConvertToThisType(other); var cmp = Utils.ComapreCards(Triple, otherHand.Triple); if (cmp != 0) { return(cmp); } return(Utils.ComapreCards(Pair, otherHand.Pair)); }
public bool Calculate(IPokerHand hand) { return(hand.Cards.Count == 5 && hand.Cards .GroupBy(c => c.Rank.Rank) .Count() == 2); }
public bool Calculate(IPokerHand hand) { var handRanks = hand.Cards.Select(c => c.Rank.Score); return(handRanks.Select((i, j) => i - j) .Distinct() .Count() == 1); }
public bool Calculate(IPokerHand hand) { return(hand.Cards.Count > 1 && hand.Cards .GroupBy(c => c.Suit.Type) .Distinct() .Count() == 1); }
public int CompareTo(IPokerHand other) { if (Score == other.Score) { return(CompareWithSame(other)); } return(Score.CompareTo(other.Score)); }
protected override int CompareWithSame(IPokerHand other) { var result = CompareHandMaxRank(other); if (result == 0) { return(CompareKickers(other)); } return(result); }
private static Rank GetStraightHighestRank(IPokerHand hand) { var ranks = new List <Rank>(hand.HandCards.Select(x => x.Rank)); if (ranks.Contains(Rank.Ace) && ranks.Contains(Rank.Two)) { ranks.Remove(Rank.Ace); } return(ranks.Max()); }
protected override int CompareWithSame(IPokerHand other) { var result = CompareHandMaxRank(other); if (result == 0) { result = HandCards.Min(x => x.Rank).CompareTo(other.HandCards.Min(x => x.Rank)); } return(result); }
public virtual bool Equals(IPokerHand other) { if (other == null) { return(false); } if (other.HandRank == HandRank) { return(Cards.OrderBy(c => c.Rank).SequenceEqual(other.Cards.OrderBy(c => c.Rank))); } return(false); }
public void CreateInstanceHelper(IPokerHand pokerHand, HandRanks expectedHandRank, IEnumerable <Card> cards, bool isValid) { if (isValid) { Assert.NotNull(pokerHand); Assert.AreEqual(expectedHandRank, pokerHand.HandRank); CollectionAssert.AreEquivalent(cards, pokerHand.Cards); } else { Assert.IsNull(pokerHand); } }
public bool Calculate(IPokerHand hand) { var straightFlush = new StraightFlush(hand); if (!straightFlush.IsHighRank) { return(false); } var handRanks = hand.Cards.Select(c => c.Rank.Score); return(handRanks .Any(r => r == 10 && r == 13)); }
public int CompareKickers(IPokerHand other) { var cards = Cards.Except(HandCards).Select(x => x.Rank).OrderByDescending(x => x).ToList(); var otherCards = other.Cards.Except(other.HandCards).Select(x => x.Rank).OrderByDescending(x => x).ToList(); for (int i = 0; i < 5 - HandCards.Count; i++) { var kickerResult = cards[i].CompareTo(otherCards[i]); if (kickerResult != 0) { return(kickerResult); } } return(0); }
public override bool Equals(IPokerHand other) { if (other == null) { return(false); } if (other.HandRank == HandRanks.RoyalFlush) { var othersuit = other.Cards.First().Suit; var mysuit = Cards.First().Suit; if (mysuit == othersuit) { return(true); } } return(false); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } return(0); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } return(Utils.ComapreCards(Cards, other.Cards)); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHand = (TwoPairs)ConvertToThisType(other); if (HighPair.First().Rank > otherHand.HighPair.First().Rank) { return(1); } if (HighPair.First().Rank < otherHand.HighPair.First().Rank) { return(-1); } if (LowPair.First().Rank > otherHand.LowPair.First().Rank) { return(1); } if (LowPair.First().Rank < otherHand.LowPair.First().Rank) { return(-1); } if (Kicker.Rank > otherHand.Kicker.Rank) { return(1); } if (Kicker.Rank < otherHand.Kicker.Rank) { return(-1); } return(0);//in a real game this should NEVER happen! }
/// <summary> /// Removes a Poker Hand from the list /// </summary> /// <param name="handToRemove">Hand to be removed</param> /// <returns>true if removed successfully, otherwise false</returns> public bool RemoveHand(IPokerHand handToRemove) { try { if (handToRemove == null) { throw new ArgumentNullException("HandToRemove"); } return(_hands.Remove(handToRemove)); } catch (ArgumentNullException excep) { Log.Error("Unhandled", excep); } return(false); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHand = (Flush)ConvertToThisType(other); return(Utils.ComapreCards(Cards, otherHand.Cards)); }
public IPokerHand[][] GetOrdered(IEnumerable <IPokerHand> hands) { var sortedList = new SortedList <int, List <IPokerHand> >(); var nextOrder = 1; var handsOrdered = hands.OrderByDescending(x => x); IPokerHand previous = null; foreach (var hand in handsOrdered) { if (previous == null || previous.CompareTo(hand) != 0) { sortedList.Add(nextOrder, new List <IPokerHand>()); nextOrder++; } sortedList[nextOrder - 1].Add(hand); previous = hand; } return(sortedList.Select(x => x.Value.ToArray()).ToArray()); }
public override int CompareTo(IPokerHand other) { if (other is null) { return(-1); } if (HandRank > other.HandRank) { return(1); } if (HandRank < other.HandRank) { return(-1); } var otherHand = (FourOfAKind)ConvertToThisType(other); if (QuadRank > otherHand.QuadRank) { return(1); } if (QuadRank < otherHand.QuadRank) { return(-1); } if (Kicker.Rank > otherHand.Kicker.Rank) { return(1); } if (Kicker.Rank < otherHand.Kicker.Rank) { return(-1); } return(0); }
protected override int CompareWithSame(IPokerHand other) { return(CompareStraight(other)); }
public virtual int CompareTo(IPokerHand other) { throw new NotImplementedException(); }
public object ConvertToThisType(IPokerHand pokerHand) { return(Convert.ChangeType(pokerHand, GetType())); }
public ThreeOfAKind(IPokerHand hand) { Title = nameof(ThreeOfAKind); IsHighRank = Calculate(hand); }