Пример #1
0
        public bool TestNotEvenPair(List <string> inp_holeCards,
                                    List <string> inp_commonCards,
                                    int exp_result,
                                    HandClass inp_hc)
        {
            var _hs = inp_hc.evaluateHands(inp_holeCards, inp_commonCards);

            return(_hs.Item1 == exp_result);
        }
Пример #2
0
        public bool TestHand(List <string> inp_holeCards,
                             List <string> inp_commonCards,
                             int exp_result,
                             HandClass inp_hc,
                             HandClass.HandStrength exp_hs)
        {
            var _hs = inp_hc.evaluateHands(inp_holeCards, inp_commonCards);

            bool isTrips = _hs.Item1 == (int)exp_hs;

            bool isNumber = _hs.Item2 == exp_result;

            if (isTrips & isNumber)
            {
                return(true);
            }
            return(false);
        }
Пример #3
0
        public bool TestKickers(List <string> inp_holeCards,
                                List <string> inp_commonCards,
                                int kicker_val,
                                int kicker_ind,
                                HandClass inp_hc)
        {
            var _hs = inp_hc.evaluateHands(inp_holeCards, inp_commonCards);

            List <int> kickers = _hs.Item3;
            int        ki;

            try {
                ki = kickers[kicker_ind];
            }
            catch {
                return(false);
            }

            return(ki == kicker_val);
        }
Пример #4
0
        public List <int> evalWinner(List <List <string> > playerHoleCards, List <string> commonCards)
        {
            /*returns: List of player(s) who are top hand in the game */

            HandClass  hc        = new HandClass();
            int        playerLen = playerHoleCards.Count;
            List <int> ret       = new List <int>()
            {
            };

            List <Tuple <int, int, List <int> > > eval_ret2 = new List <Tuple <int, int, List <int> > >();
            List <int> evalHand = new List <int>()
            {
            };
            List <int> evalRank = new List <int>()
            {
            };
            List <List <int> > evalKickers = new List <List <int> >()
            {
            };

            foreach (List <string> _holeCards in playerHoleCards)
            {
                eval_ret2.Add(hc.evaluateHands(_holeCards, commonCards));
                evalHand.Add(hc.evaluateHands(_holeCards, commonCards).Item1);
                evalRank.Add(hc.evaluateHands(_holeCards, commonCards).Item2);
                evalKickers.Add(hc.evaluateHands(_holeCards, commonCards).Item3);
            }

            int        maxHand  = evalHand.Max();
            List <int> topHands = Enumerable.Range(0, evalHand.Count)
                                  .Where(i => evalHand[i] == maxHand)
                                  .ToList();

            if (topHands.Count == 1)
            {
                return(topHands);
            }
            else
            {
                int        maxRank  = evalRank.Max();
                List <int> topRanks = Enumerable.Range(0, topHands.Count)
                                      .Where(i => (evalRank[i] == maxRank) &
                                             (evalHand[i] == maxHand))
                                      .ToList();
                if (topRanks.Count == 1)
                {
                    return(topRanks);
                }
                else
                {
                    List <List <int> > kickersLeft = new List <List <int> >();
                    for (int h = 0; h < topRanks.Count; h++)
                    {
                        kickersLeft.Add(evalKickers[topRanks[h]]);
                    }

                    List <int> maxKickers = maxKicker(kickersLeft);

                    List <int> topKickers = Enumerable.Range(0, evalHand.Count)
                                            .Where(i => (evalRank[i] == maxRank) &
                                                   (evalHand[i] == maxHand) &
                                                   (Enumerable.SequenceEqual(
                                                        evalKickers[i], maxKickers)))
                                            .ToList();

                    if (topKickers.Count == 1)
                    {
                        return(topKickers);
                    }
                    else
                    {
                        //Split Pot, not even kickers break the tie
                        return(topKickers);
                    }
                }
            }
        }
Пример #5
0
        public int RunTests(string[] args)
        {
            bool print = false;

            if (args[0] == "PrintThere")
            {
                Console.WriteLine("Start Tests");
                print = true;
            }

            HandClass hc = new HandClass();


            List <string> cards;
            List <string> cards2;

            //List<string> cards3;

            Results = new List <Tuple <int, bool> >();
            bool tx;

            //Misc functions
            List <int> a = new List <int>()
            {
                1, 2
            };
            List <int> b = new List <int>()
            {
                1, 2
            };

            tx = Enumerable.SequenceEqual(a.OrderBy(t => t), b.OrderBy(t => t));
            ResultsUtil(tx, print);

            List <int> c = new List <int>()
            {
                1, 2
            };
            List <int> d = new List <int>()
            {
                1, 3
            };

            tx = Enumerable.SequenceEqual(c.OrderBy(t => t), d.OrderBy(t => t));
            ResultsUtil(!tx, print);

            tx = Enumerable.SequenceEqual(a, b);
            ResultsUtil(tx, print);

            //There is a pair
            cards = new List <string> {
                "2|3", "2|2"
            };
            cards2 = new List <string> {
                "5|1", "6|3", "7|2", "10|2", "11|1"
            };
            tx = TestHand(cards, cards2, 2, hc, HandClass.HandStrength.Pair);
            ResultsUtil(tx, print);

            //No Pairs
            cards = new List <string> {
                "1|3", "2|2"
            };
            cards2 = new List <string> {
                "5|1", "6|3", "7|2", "10|2", "11|1"
            };
            tx = TestHand(cards, cards2, -1, hc, HandClass.HandStrength.Pair);
            ResultsUtil(!tx, print);

            tx = TestHand(cards, cards2, 0, hc, HandClass.HandStrength.HighCards);
            ResultsUtil(tx, print);

            //Test TwoPair
            cards = new List <string> {
                "0|3", "1|2"
            };
            cards2 = new List <string> {
                "1|1", "0|3", "2|2", "5|2", "6|1"
            };
            tx = TestHand(cards, cards2, (100 * 1) + 0, hc, HandClass.HandStrength.TwoPair);
            ResultsUtil(tx, print);

            //Test Trips
            cards = new List <string> {
                "0|3", "1|2"
            };
            cards2 = new List <string> {
                "1|1", "1|3", "2|2", "5|2", "6|1"
            };
            tx = TestHand(cards, cards2, 1, hc, HandClass.HandStrength.Trips);
            ResultsUtil(tx, print);
            //TestArrayInit();

            //Test Straight
            cards = new List <string> {
                "0|2", "1|3"
            };
            cards2 = new List <string> {
                "2|2", "3|3", "4|2", "7|0", "8|0"
            };
            tx = TestHand(cards, cards2, 4, hc, HandClass.HandStrength.Straight);
            ResultsUtil(tx, print);

            cards = new List <string> {
                "0|2", "1|3"
            };
            cards2 = new List <string> {
                "2|2", "3|3", "9|2", "7|0", "12|0"
            };
            tx = TestHand(cards, cards2, 3, hc, HandClass.HandStrength.Straight);
            ResultsUtil(tx, print);

            cards = new List <string> {
                "12|2", "1|2"
            };
            cards2 = new List <string> {
                "11|2", "10|3", "9|2", "8|0", "12|1"
            };
            tx = TestHand(cards, cards2, 12, hc, HandClass.HandStrength.Straight);
            ResultsUtil(tx, print);

            //high card from 6 card straight
            cards = new List <string> {
                "0|2", "1|3"
            };
            cards2 = new List <string> {
                "2|2", "3|3", "4|2", "7|0", "12|0"
            };
            tx = TestHand(cards, cards2, 4, hc, HandClass.HandStrength.Straight);
            ResultsUtil(tx, print);

            //Test Flush
            cards = new List <string> {
                "0|2", "1|2"
            };
            cards2 = new List <string> {
                "1|2", "1|3", "2|2", "5|2", "6|2"
            };
            tx = TestHand(cards, cards2, 0, hc, HandClass.HandStrength.Flush);
            ResultsUtil(tx, print);

            //Test FullHouse
            cards = new List <string> {
                "2|3", "1|2"
            };
            cards2 = new List <string> {
                "1|1", "1|3", "2|2", "5|2", "6|1"
            };
            tx = TestHand(cards, cards2, (1 * 100) + 2, hc, HandClass.HandStrength.FullHouse);
            ResultsUtil(tx, print);

            cards = new List <string> {
                "2|3", "7|2"
            };
            cards2 = new List <string> {
                "1|1", "7|3", "2|2", "5|2", "7|1"
            };
            tx = TestHand(cards, cards2, (7 * 100) + 2, hc, HandClass.HandStrength.FullHouse);
            ResultsUtil(tx, print);


            //Test FourOfAKind
            cards = new List <string> {
                "2|3", "2|2"
            };
            cards2 = new List <string> {
                "1|1", "1|3", "2|0", "2|2", "6|1"
            };
            tx = TestHand(cards, cards2, 2, hc, HandClass.HandStrength.FourOfAKind);
            ResultsUtil(tx, print);
            tx = TestHand(cards, cards2, 6, hc, HandClass.HandStrength.FourOfAKind);
            ResultsUtil(!tx, print);

            //Test StraightFlush

            cards = new List <string> {
                "0|3", "1|3"
            };
            cards2 = new List <string> {
                "2|3", "3|3", "4|3", "7|0", "8|0"
            };
            tx = TestHand(cards, cards2, 4, hc, HandClass.HandStrength.StraightFlush);
            ResultsUtil(tx, print);

            //acelow
            cards = new List <string> {
                "0|1", "1|1"
            };
            cards2 = new List <string> {
                "2|1", "3|1", "9|2", "7|0", "12|1"
            };
            tx = TestHand(cards, cards2, 3, hc, HandClass.HandStrength.StraightFlush);
            ResultsUtil(tx, print);

            cards = new List <string> {
                "12|2", "1|2"
            };
            cards2 = new List <string> {
                "11|2", "10|2", "9|2", "8|2", "12|1"
            };
            tx = TestHand(cards, cards2, 12, hc, HandClass.HandStrength.StraightFlush);
            ResultsUtil(tx, print);

            //straight and flush but not straight flush
            cards = new List <string> {
                "12|2", "1|2"
            };
            cards2 = new List <string> {
                "11|2", "10|2", "9|2", "8|0", "12|1"
            };
            tx = TestHand(cards, cards2, 12, hc, HandClass.HandStrength.StraightFlush);
            ResultsUtil(!tx, print);


            //Test Kickers
            cards = new List <string> {
                "2|3", "5|1"
            };
            cards2 = new List <string> {
                "5|1", "6|3", "7|2", "4|2", "11|1"
            };

            tx = TestKickers(cards, cards2, 11, 0, hc);
            ResultsUtil(tx, print);

            tx = TestKickers(cards, cards2, 7, 1, hc);
            ResultsUtil(tx, print);

            tx = TestKickers(cards, cards2, 6, 2, hc);
            ResultsUtil(tx, print);

            cards = new List <string> {
                "0|3", "1|2"
            };
            cards2 = new List <string> {
                "1|1", "0|3", "2|2", "5|2", "6|1"
            };
            tx = TestKickers(cards, cards2, 6, 0, hc);
            ResultsUtil(tx, print);

            //BUG? - Better kicker but on a lower [two]pair bug?
            cards = new List <string> {
                "2|3", "2|1"
            };
            cards2 = new List <string> {
                "6|1", "0|3", "3|2", "4|2", "6|1"
            };
            tx = TestKickers(cards, cards2, 4, 0, hc);
            ResultsUtil(tx, print);
            cards = new List <string> {
                "6|3", "6|1"
            };
            cards2 = new List <string> {
                "2|1", "0|3", "3|2", "4|2", "2|1"
            };
            tx = TestKickers(cards, cards2, 4, 0, hc);
            ResultsUtil(tx, print);
            cards = new List <string> {
                "6|3", "6|1"
            };
            cards2 = new List <string> {
                "2|1", "1|3", "3|2", "2|2", "4|1"
            };
            tx = TestKickers(cards, cards2, 4, 0, hc);
            ResultsUtil(tx, print);

            //test HighCards kickers
            cards = new List <string> {
                "2|3", "3|1"
            };
            cards2 = new List <string> {
                "5|1", "6|3", "7|2", "0|2", "11|1"
            };
            tx = TestKickers(cards, cards2, 11, 0, hc);
            ResultsUtil(tx, print);

            tx = TestKickers(cards, cards2, 3, 4, hc);
            ResultsUtil(tx, print);


            //test kickers with trips
            cards = new List <string> {
                "2|3", "1|2"
            };
            cards2 = new List <string> {
                "1|1", "1|3", "3|2", "5|2", "6|1"
            };

            tx = TestKickers(cards, cards2, 6, 0, hc);
            ResultsUtil(tx, print);

            tx = TestKickers(cards, cards2, 5, 1, hc);
            ResultsUtil(tx, print);

            tx = TestKickers(cards, cards2, 3, 2, hc);
            ResultsUtil(!tx, print); //trips dont have a thrid kicker, tx should be false

            //test kickers with fourofakind
            cards = new List <string> {
                "2|3", "2|2"
            };
            cards2 = new List <string> {
                "1|1", "3|3", "2|0", "2|2", "6|1"
            };
            tx = TestKickers(cards, cards2, 6, 0, hc);
            ResultsUtil(tx, print);
            tx = TestKickers(cards, cards2, 3, 1, hc);
            ResultsUtil(!tx, print); //quads dont have a 2nd kicker


            //Game Class
            GameAtom g = new GameAtom();

            List <List <string> > playerHoleCards = new List <List <string> >();
            List <string>         player1         = new List <string> {
                "2|3", "1|2"
            };
            List <string> player2 = new List <string> {
                "2|3", "2|2"
            };

            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            List <string> commonCards = new List <string> {
                "1|1", "3|3", "2|0", "2|2", "6|1"
            };


            //test better hand wins
            List <int> ret2 = g.evalWinner(playerHoleCards, commonCards);

            tx = TestWinner(ret2, 1);
            ResultsUtil(tx, print);

            //test better rank wins
            player1 = new List <string> {
                "7|3", "7|2"
            };
            player2 = new List <string> {
                "6|3", "6|2"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "1|1", "3|3", "2|0", "2|2", "5|1"
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestWinner(ret2, 0);
            ResultsUtil(tx, print);

            //test better kickers wins
            player1 = new List <string> {
                "6|3", "10|2"
            };
            player2 = new List <string> {
                "6|3", "9|2"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "1|1", "3|3", "2|0", "2|2", "6|1"
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestWinner(ret2, 0);
            ResultsUtil(tx, print);

            //test better second-kicker wins
            player1 = new List <string> {
                "6|3", "8|2"
            };
            player2 = new List <string> {
                "6|3", "9|2"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "1|1", "3|3", "2|0", "10|2", "11|1"
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestWinner(ret2, 1);
            ResultsUtil(tx, print);

            //test better kicker in worse hand loses
            player1 = new List <string> {
                "6|3", "12|2"
            };
            player2 = new List <string> {
                "5|3", "5|2"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "1|1", "3|3", "5|0", "6|2", "11|1"
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestWinner(ret2, 1);
            ResultsUtil(tx, print);


            //test better flush kicker wins
            player1 = new List <string> {
                "7|0", "8|0"
            };
            player2 = new List <string> {
                "6|0", "9|0"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "1|1", "1|0", "2|0", "10|0", "11|0"
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestWinner(ret2, 1);
            ResultsUtil(tx, print);

            //test 6th-best kicker in flush doesn't matter
            player1 = new List <string> {
                "1|0", "4|0"
            };
            player2 = new List <string> {
                "2|0", "0|0"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            commonCards = new List <string> {
                "6|0", "7|0", "8|0", "10|0", "11|0"
            };
            List <int> exp_ret2 = new List <int>()
            {
                0, 1
            };

            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestPotSplit(ret2, exp_ret2);
            ResultsUtil(tx, print);

            //test high card pot-split
            //test pot split 3-way with fourhands
            List <string> player3, player4;

            player1 = new List <string> {
                "1|0", "4|0"
            };
            player2 = new List <string> {
                "2|0", "4|0"
            };
            player3 = new List <string> {
                "2|3", "1|1"
            };
            player4 = new List <string> {
                "1|2", "4|1"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            playerHoleCards.Add(player3);
            playerHoleCards.Add(player4);
            commonCards = new List <string> {
                "0|1", "7|1", "8|0", "10|0", "11|2"
            };
            exp_ret2 = new List <int>()
            {
                0, 1, 3
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestPotSplit(ret2, exp_ret2);
            ResultsUtil(tx, print);

            //test potsplit for board beats all hands
            player1 = new List <string> {
                "1|0", "4|0"
            };
            player2 = new List <string> {
                "2|0", "4|0"
            };
            player3 = new List <string> {
                "2|3", "1|1"
            };
            player4 = new List <string> {
                "1|2", "4|1"
            };
            playerHoleCards = new List <List <string> >();
            playerHoleCards.Add(player1);
            playerHoleCards.Add(player2);
            playerHoleCards.Add(player3);
            playerHoleCards.Add(player4);
            commonCards = new List <string> {
                "5|1", "7|1", "8|0", "10|0", "11|2"
            };
            exp_ret2 = new List <int>()
            {
                0, 1, 3, 2
            };
            ret2 = g.evalWinner(playerHoleCards, commonCards);
            tx   = TestPotSplit(ret2, exp_ret2);
            ResultsUtil(tx, print);

            //Kitty splitting
            List <int> playersChips = new List <int>()
            {
                10, 10
            };

            g.setKitty(49);
            exp_ret2 = new List <int>()
            {
                0
            };
            g.DivvyKitty(exp_ret2, ref playersChips);
            tx = (playersChips[0] == 59) ? true : false;
            ResultsUtil(tx, print);

            //TestPotSplit
            playersChips = new List <int>()
            {
                10, 10, 10
            };
            List <int> expPlayersChips = new List <int>()
            {
                34, 34, 10
            };

            g.setKitty(49);
            exp_ret2 = new List <int>()
            {
                0, 1
            };
            g.DivvyKitty(exp_ret2, ref playersChips);
            tx = TestPlayerChip(playersChips, expPlayersChips);
            ResultsUtil(tx, print);

            //Test Dealing

            //Look for a colision in dealing cards
            DeckClass             dc   = new DeckClass();
            List <List <string> > ret3 = dc.dealHoleCards(10);

            tx = TestCardCollisions(ret3);
            ResultsUtil(tx, print);

            //Test that TestCardCollision actually detects collisions
            //should return false as we purposefully setup a collision
            player1 = new List <string> {
                "1|0", "4|0"
            };
            player2 = new List <string> {
                "2|0", "4|0"
            };
            player3 = new List <string> {
                "2|3", "1|1"
            };
            ret3.Add(player1);
            ret3.Add(player2);
            ret3.Add(player3);
            tx = TestCardCollisions(ret3);
            ResultsUtil(!tx, print);

            //Look for a colision in dealing cards
            int nI = _rnd.Next(50);

            for (int i = 1; i < nI; i++)
            {
                int nJ = _rnd.Next(15);
                dc   = new DeckClass();
                ret3 = dc.dealHoleCards(nJ);
                tx   = TestCardCollisions(ret3);
                if (!tx)
                {
                    ResultsUtil(tx, print);
                }
            }
            ResultsUtil(true, print);

            //Deal too many cards
            //note, program collapses if this happens
            //also note: you can't do
            dc = new DeckClass();
            tx = TestNotEnoughCards(dc);
            ResultsUtil(tx, print);



            Console.WriteLine(" ----------------------------------------------------- ");
            PrintOutResults();
            return(1);
        }