public void TestHighCard() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Diamonds, CardFace.King)); hand.Add(new Card(CardSuit.Diamonds, CardFace.Queen)); hand.Add(new Card(CardSuit.Spades, CardFace.Seven)); hand.Add(new Card(CardSuit.Spades, CardFace.Four)); hand.Add(new Card(CardSuit.Hearts, CardFace.Three)); Assert.AreEqual(hand.Rank, PokerHandRank.HighCard); }
public void TestFlush() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Clubs, CardFace.Jack)); hand.Add(new Card(CardSuit.Clubs, CardFace.Ten)); hand.Add(new Card(CardSuit.Clubs, CardFace.Nine)); hand.Add(new Card(CardSuit.Clubs, CardFace.Six)); hand.Add(new Card(CardSuit.Clubs, CardFace.Five)); Assert.AreEqual(hand.Rank, PokerHandRank.Flush); }
public void TestStraight() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Diamonds, CardFace.Jack)); hand.Add(new Card(CardSuit.Spades, CardFace.Ten)); hand.Add(new Card(CardSuit.Hearts, CardFace.Nine)); hand.Add(new Card(CardSuit.Diamonds, CardFace.Eight)); hand.Add(new Card(CardSuit.Clubs, CardFace.Seven)); Assert.AreEqual(hand.Rank, PokerHandRank.Straight); }
public void TestThreeOfAKind() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Clubs, CardFace.Queen)); hand.Add(new Card(CardSuit.Spades, CardFace.Queen)); hand.Add(new Card(CardSuit.Hearts, CardFace.Queen)); hand.Add(new Card(CardSuit.Hearts, CardFace.Nine)); hand.Add(new Card(CardSuit.Spades, CardFace.Two)); Assert.AreEqual(hand.Rank, PokerHandRank.ThreeOfAKind); }
public void TestOnePair() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Spades, CardFace.Ten)); hand.Add(new Card(CardSuit.Hearts, CardFace.Ten)); hand.Add(new Card(CardSuit.Spades, CardFace.Eight)); hand.Add(new Card(CardSuit.Hearts, CardFace.Seven)); hand.Add(new Card(CardSuit.Clubs, CardFace.Four)); Assert.AreEqual(hand.Rank, PokerHandRank.OnePair); }
public void TestFullHouse() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Clubs, CardFace.Five)); hand.Add(new Card(CardSuit.Diamonds, CardFace.Five)); hand.Add(new Card(CardSuit.Hearts, CardFace.Five)); hand.Add(new Card(CardSuit.Spades, CardFace.Seven)); hand.Add(new Card(CardSuit.Clubs, CardFace.Seven)); Assert.AreEqual(hand.Rank, PokerHandRank.FullHouse); }
public void TwoPairDecision_Score_ReturnsPair() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 2)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 4)); hand.Add(new Card(Suit.Spade, 5)); var sut = new TwoPairDecisionNode(); var result = sut.Eval(hand); result.Score.Should().Be(3); }
public void TwoPairs_WithTwoPair_EvalTrue() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 2)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 3)); hand.Add(new Card(Suit.Spade, 5)); ICardHandRule rule = new HasTwoPairsHandRule(); var result = rule.Eval(hand); result.Should().BeTrue(); }
public void Hand_WithNoPairs_EvalFalse() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 8)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 4)); hand.Add(new Card(Suit.Spade, 5)); ICardHandRule rule = new HasMultipleRankHandRule(); var result = rule.Eval(hand); result.Should().BeFalse(); }
public void ThreeOfKind_WithPair_EvalFalse() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 2)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 4)); hand.Add(new Card(Suit.Spade, 5)); ICardHandRule rule = new RepeatingRankHandRule(3); var result = rule.Eval(hand); result.Should().BeFalse(); }
public void Hand_With3OrKind_EvalTrue() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 2)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 4)); hand.Add(new Card(Suit.Spade, 2)); ICardHandRule rule = new HasMultipleRankHandRule(); var result = rule.Eval(hand); result.Should().BeTrue(); }
public void TwoPairs_WithPariAnd4OfKind_EvalFalse() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 3)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 3)); hand.Add(new Card(Suit.Spade, 3)); ICardHandRule rule = new HasTwoPairsHandRule(); var result = rule.Eval(hand); result.Should().BeFalse(); }
public void FourOfKind_WithFourSameRank_EvalTrue() { IHand hand = new PokerHand(); hand.Add(new Card(Suit.Heart, 2)); hand.Add(new Card(Suit.Diamond, 2)); hand.Add(new Card(Suit.Spade, 3)); hand.Add(new Card(Suit.Club, 2)); hand.Add(new Card(Suit.Spade, 2)); ICardHandRule rule = new RepeatingRankHandRule(4); var result = rule.Eval(hand); result.Should().BeTrue(); }
static void Main(string[] args) { bool debug = (args.Length > 0); int maxPokerHandSize = 5; // Two Hands PokerHand black = new PokerHand(maxPokerHandSize); PokerHand white = new PokerHand(maxPokerHandSize); string input; while ((input = Console.ReadLine()) != null) { // Debug - Some Test Cases and Expected Results //input = "2H 3D 5S 9C KD 2C 3H 4S AD AH"; // High Card, Pair //input = "2H 3D 4H 5D 6H 3C 4C 5C 6C 7C"; // Straight, Straight Flush //input = "2H 2D 3H 3D 4C AH AD TC TD TH"; // Two Pair, Full House (Correctly does 10) //input = "2H 2D 2C 4H 5H AH AD AC AS KD"; // 3Kind, 4Kind //input = "2H 4H 6H 8H TH 2D 4D 6D 8D TD"; // Flush (Tie)s //input = "2H 4D 6H 8D AH 3H 4C 6D 7C AD"; // Both Ace High, Black has Better Kickers //input = "2H 2D 4H 4D AH 2S 2C 4S 4C AC"; // Two Pair Real Tie if (debug) { Console.WriteLine(input); } // Clear the Hands black.Clear(); white.Clear(); // Parse and load Hands try { string[] cardStrings = input.Split(' '); for (int i = 0; i < black.MaxHandSize; ++i) { black.Add(new PlayingCard(cardStrings[i])); } for (int i = 0; i < white.MaxHandSize; ++i) { white.Add(new PlayingCard(cardStrings[i + black.MaxHandSize])); } } catch (Exception e) { Console.WriteLine("Bad Card in the Mix"); if (debug) { Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); } continue; } // Debug - Output the Scores if (debug) { Console.WriteLine("black score: " + black.ScoreHand().ToString()); Console.WriteLine("white score: " + white.ScoreHand().ToString()); } // Compare Hands - Output the Winner int compare = black.CompareTo(white); if (compare == 0) { Console.WriteLine("Tie."); } else if (compare < 0) { Console.WriteLine("White wins."); } else { Console.WriteLine("Black wins."); } } }
public static PokerHand CreateHand(params Tuple <CardSuit, CardValue>[] cards) { var result = new PokerHand(); foreach (var card in cards) { result.Add(new Card() { Suit = card.Item1, Value = card.Item2 }); } return(result); }
public void TestStraightFlush() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Clubs, CardFace.Jack)); hand.Add(new Card(CardSuit.Clubs, CardFace.Ten)); hand.Add(new Card(CardSuit.Clubs, CardFace.Nine)); hand.Add(new Card(CardSuit.Clubs, CardFace.Eight)); hand.Add(new Card(CardSuit.Clubs, CardFace.Seven)); Assert.AreEqual(hand.Rank, PokerHandRank.StraightFlush); var hand2 = new PokerHand(); hand2.Add(new Card(CardSuit.Clubs, CardFace.Queen)); hand2.Add(new Card(CardSuit.Clubs, CardFace.Jack)); hand2.Add(new Card(CardSuit.Clubs, CardFace.Ten)); hand2.Add(new Card(CardSuit.Clubs, CardFace.Nine)); hand2.Add(new Card(CardSuit.Clubs, CardFace.Eight)); Assert.AreEqual(hand.CompareTo(hand2), -1); }
public void TestTwoPair() { var hand = new PokerHand(); hand.Add(new Card(CardSuit.Hearts, CardFace.Jack)); hand.Add(new Card(CardSuit.Spades, CardFace.Jack)); hand.Add(new Card(CardSuit.Clubs, CardFace.Three)); hand.Add(new Card(CardSuit.Spades, CardFace.Four)); hand.Add(new Card(CardSuit.Hearts, CardFace.Two)); Assert.AreNotEqual(hand.Rank, PokerHandRank.TwoPair); var hand2 = new PokerHand(); hand2.Add(new Card(CardSuit.Hearts, CardFace.Jack)); hand2.Add(new Card(CardSuit.Spades, CardFace.Jack)); hand2.Add(new Card(CardSuit.Clubs, CardFace.Four)); hand2.Add(new Card(CardSuit.Spades, CardFace.Four)); hand2.Add(new Card(CardSuit.Hearts, CardFace.Two)); Assert.AreEqual(hand2.Rank, PokerHandRank.TwoPair); }
private IHand CreateHand(string s) { PokerHand hand = new PokerHand(); string[] cards = s.Split(' '); foreach (string card in cards) { CardSuit suit = CardSuit.Club; switch (card[1]) { case 'C': suit = CardSuit.Club; break; case 'D': suit = CardSuit.Diamond; break; case 'S': suit = CardSuit.Spade; break; case 'H': suit = CardSuit.Heart; break; } CardFace face = CardFace.AceHigh; switch (card[0]) { case 'J': face = CardFace.Jack; break; case 'Q': face = CardFace.Queen; break; case 'K': face = CardFace.King; break; case 'A': face = CardFace.AceHigh; break; default: { string faceString = card.Substring(0, 1); int faceInt = int.Parse(faceString); face = (CardFace)faceInt; } break; } hand.Add(new PokerCard(suit, face)); } return(hand); }
/// <summary>Get the Results for some Selections</summary> /// <param name="selections">Positions of the Card Selection</param> /// <returns>A Result Object containing the Game Results</returns> public virtual Result Selected(BitArray selections) { // Determine the Selected Hand PokerHand selectedHand = new PokerHand(5); PlayingCard[] cards = _playingCards.ToArray<PlayingCard>(); for (int i = 0; i < selections.Length; ++i) { if (selections[i]) { selectedHand.Add(cards[i]); } } // Compare to the best PokerHand bestHand = BestHand; bool isBest = (bestHand.CompareTo(selectedHand) == 0); // BitArray for the Best Hand BitArray bestHandBits = new BitArray(selections.Length); for (int i = 0; i < cards.Length; ++i) { bestHandBits[i] = (bestHand.Cards.Contains(cards[i])); } return new Result(isBest, bestHandBits, bestHand, selectedHand); }