Beispiel #1
0
        public void DoATurn()
        {
            //Cards
            switch (current_turn)
            {
            case TurnName.PreFlop:
                player_hole_cards.AddRange(gameDeck.dealHoleCards(num_players));
                break;

            case TurnName.Flop:
                common_cards.AddRange(gameDeck.dealCommonCards(3));
                break;

            case TurnName.River:
            case TurnName.Turn:
                common_cards.AddRange(gameDeck.dealCommonCards(1));
                break;
            }

            if (current_turn == TurnName.PreFlop)
            {
                //DoBlinds();
            }

            //Betting.Betting( current_turn )
            //note: betting starts pre-flop on follower of BB, but on LB afterwards

            if (current_turn == TurnName.River)
            {
                DivvyKitty(
                    evalWinner(player_hole_cards, common_cards)
                    , ref players_chips);
            }
        }
Beispiel #2
0
 private bool TestNotEnoughCards(DeckClass inp_dc)
 {
     try { List <List <string> > ret = inp_dc.dealHoleCards(30, 2); }
     catch { return(true); }
     return(false);
 }
Beispiel #3
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);
        }