public int CompareTo(object obj) { if (obj == null) { return(1); } else { PokerCard otherPokerCard = (PokerCard)obj; if (otherPokerCard != null) { if (this.Value.CompareTo(otherPokerCard.Value) != 0) { return(this.Value.CompareTo(otherPokerCard.Value)); } else { return(this.Suit.CompareTo(otherPokerCard.Suit)); } } else { throw new ArgumentException("Object is not a PokerCard"); } } }
/// <summary> /// Returns if the hand contains four of a kind /// </summary> /// <returns></returns> public bool HasFourOfAKind() { bool result = true; int count = 1; const int four = 4; PokerCard pivotCard = Hand[0]; for (int i = 1; result && count < four && i < Hand.Count; i++) { result = (pivotCard.Suit != Hand[i].Suit && pivotCard.Value == Hand[i].Value); count++; } if (!result) { result = true; count = 1; pivotCard = Hand[1]; for (int i = 2; result && count < four && i < Hand.Count; i++) { result = (pivotCard.Suit != Hand[i].Suit && pivotCard.Value == Hand[i].Value); count++; } } if (result) { HighestCard = pivotCard.Value; } return(result); }
/// <summary> /// Returns if the hand contains a Royal Flush /// </summary> /// <returns></returns> public bool HasRoyalFlush() { bool result = true; PokerCard pivotCard = Hand[0]; if (pivotCard.Value == PokerCard.ValueEnum.T) { for (int i = 1; result && i < Hand.Count; i++) { result = (pivotCard.Suit == Hand[i].Suit && pivotCard.Value + 1 == Hand[i].Value); pivotCard = Hand[i]; } } else { result = false; } if (result) { HighestCard = Hand.Last().Value; } return(result); }
/// <summary> /// Returns if the hand constains a straight flush /// </summary> /// <returns></returns> public bool HasStraightFlush() { bool result = true; PokerCard pivotCard = Hand[0]; for (int i = 1; result && i < Hand.Count; i++) { result = (pivotCard.Suit == Hand[i].Suit && pivotCard.Value + 1 == Hand[i].Value); pivotCard = Hand[i]; if (!result && i == Hand.Count - 1 && Hand[0].Suit == Hand[i].Suit && Hand[i].Value == PokerCard.ValueEnum.A && Hand[0].Value == PokerCard.ValueEnum.Two) { result = true; } } if (result) { HighestCard = Hand.Last().Value; } return(result); }
/// <summary> /// Returns if the hand contains three of a kind /// </summary> /// <returns></returns> private bool HasThreeOfAKind() { bool result = true; int count = 1; const int three = 3; PokerCard pivotCard = Hand[0]; for (int i = 1; result && count < three && i < Hand.Count; i++) { result = (pivotCard.Suit != Hand[i].Suit && pivotCard.Value == Hand[i].Value); count++; } if (!result) { result = true; count = 1; pivotCard = Hand[1]; for (int i = 2; result && count < three && i < Hand.Count; i++) { result = (pivotCard.Suit != Hand[i].Suit && pivotCard.Value == Hand[i].Value); count++; } } if (!result) { result = true; count = 1; pivotCard = Hand[2]; for (int i = 3; result && count < three && i < Hand.Count; i++) { result = (pivotCard.Suit != Hand[i].Suit && pivotCard.Value == Hand[i].Value); count++; } } if (result) { HighestCard = pivotCard.Value; } return(result); }