public void RemoveOnePairSuited()
        {
            Stopwatch   watch = new Stopwatch();
            List <Card> cards = new List <Card>
            {
                new Card(Rank.Ace, Suit.Clubs),
                new Card(Rank.Ace, Suit.Hearts),
                new Card(Rank.Six, Suit.Hearts),
                new Card(Rank.Seven, Suit.Clubs),
                new Card(Rank.Jack, Suit.Hearts),
            };

            FiveCardHand hand = new FiveCardHand(cards);

            hand.Sort();
            watch.Start();
            var newCards = hand.RemovePairs();

            watch.Stop();


            Assert.AreEqual(4, newCards.Count);
            Assert.AreEqual(5, hand.Cards.Count);
            Assert.Greater(30, watch.ElapsedMilliseconds);
            Assert.AreEqual(true, newCards[0].Rank == Rank.Six && newCards[1].Rank == Rank.Seven && newCards[2].Rank == Rank.Jack && newCards[3].Rank == Rank.Ace && newCards[3].Suit == Suit.Hearts);
        }
        public void RemoveThreeAndPair()
        {
            Stopwatch   watch = new Stopwatch();
            List <Card> cards = new List <Card>
            {
                new Card(Rank.Ace, Suit.Hearts),
                new Card(Rank.Ace, Suit.Clubs),
                new Card(Rank.Ace, Suit.Hearts),
                new Card(Rank.Seven, Suit.Clubs),
                new Card(Rank.Seven, Suit.Hearts),
            };

            FiveCardHand hand = new FiveCardHand(cards);

            hand.Sort();
            watch.Start();
            var newCards = hand.RemovePairs();

            watch.Stop();


            Assert.AreEqual(2, newCards.Count);
            Assert.AreEqual(5, hand.Cards.Count);
            Assert.Greater(10, watch.ElapsedMilliseconds);
            Assert.AreEqual(true, newCards[0].Rank == Rank.Seven && newCards[1].Rank == Rank.Ace);
        }
Exemplo n.º 3
0
        public static PokerScoreOuts CalculateTurn(FiveCardHand cards)
        {
            ISet <int> open       = new HashSet <int>(),
                       missingOne = new HashSet <int>(),
                       missingTwo = new HashSet <int>(),
                       inside     = new HashSet <int>(),
                       outside    = new HashSet <int>();

            var withoutPair = cards.RemovePairs();
            var handList    = new List <int> {
                cards.Cards[0].ToInt(), cards.Cards[1].ToInt(), cards.Cards[2].ToInt(), cards.Cards[3].ToInt(), cards.Cards[4].ToInt()
            };

            if (withoutPair.Count <= 2)
            {
                return(PokerHelper.CreateTurnOuts(0, true));
            }
            if (withoutPair.Count == 3)
            {
                if (withoutPair[2].Rank == Rank.Ace && withoutPair[0].Rank <= Rank.Four)
                {
                    withoutPair = new List <Card> {
                        withoutPair[2], withoutPair[0], withoutPair[1]
                    }
                }
                ;
                open       = PokerHelper.CountThreeOpenEnded(handList, withoutPair);
                missingOne = PokerHelper.CountThreeMissingOne(handList, withoutPair);
                missingTwo = PokerHelper.CountThreeMissingTwo(handList, withoutPair);

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            if (withoutPair.Count == 4)
            {
                outside = PokerHelper.CountOutsideStraightDraws(handList, withoutPair);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                }

                inside = PokerHelper.CountInsideStraightDraws(handList, withoutPair);
                if (inside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                }

                if (withoutPair[3].Rank == Rank.Ace)
                {
                    var comb = new List <Card> {
                        withoutPair[3], withoutPair[0], withoutPair[1]
                    };
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                foreach (var comb in PokerEnumerator.GetThreeCardsFromFour(withoutPair))
                {
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            if (withoutPair.Count == 5)
            {
                //Four card collections
                if (withoutPair[4].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1], withoutPair[2]
                    };

                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    if (outside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                    }

                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                    if (inside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                    }
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromFive(withoutPair))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count * 4));
                }

                //Three card collections
                if (withoutPair[4].Rank == Rank.Ace)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1]
                    };
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                foreach (var comb in PokerEnumerator.GetThreeCardsFromFive(withoutPair))
                {
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            throw new ArgumentException("Without pair count should never be more than five");
        }