Example #1
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Debug.WriteLine(h.ToString());
        }
Example #2
0
        public void HandToString()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            Hand h = new Hand(hands[0]);

            Assert.AreEqual(10, h.Points());
            Assert.AreEqual(2, h.ExtraPoints());
        }
Example #3
0
        public void Hand_CalcPointsPerSuite()
        {
            Deck deck = new Deck();
            deck.Shuffle(123456);
            IHand[] hands = deck.Deal(13, 1);

            IHand h = hands[0];

            Assert.AreEqual(6, h.Spades.Points());
            Assert.AreEqual(1, h.Hearts.Points());
            Assert.AreEqual(3, h.Diamonds.Points());
            Assert.AreEqual(0, h.Clubs.Points());
        }
Example #4
0
        private static void Stats()
        {
            int maxRoyalFlush = 10;

            Console.Write("Royal Flushes to get: ");
            maxRoyalFlush = Console.ReadLine().ToIntegerOrDefault(-1);

            Deck deck = new Deck();
            deck.CreateDefaultDeck(false);
            deck.Shuffle();

            var cards = deck.Draw(7).ToList();
            int tryCount = 0;

            int highCard = 0;
            int pair = 0;
            int twoPair = 0;
            int threeKind = 0;
            int fullHouse = 0;
            int straight = 0;
            int flush = 0;
            int straightFlush = 0;
            int fourKind = 0;
            int royalFlush = 0;

            DateTime startTime = DateTime.Now;

            while (royalFlush < maxRoyalFlush)
            {
                tryCount++;
                //for (int i = 0; i < cards.Count; i++)
                //{
                //    Console.Write(cards[i].ToString());

                //    if (i < cards.Count - 1)
                //    {
                //        Console.Write(',');
                //    }
                //    else
                //    {
                //        Console.WriteLine();
                //    }
                //}

                switch (Poker.GetHand(cards))
                {
                    case Poker.Hands.Flush:
                        flush++;
                        break;
                    case Poker.Hands.FourKind:
                        fourKind++;
                        break;
                    case Poker.Hands.FullHouse:
                        fullHouse++;
                        break;
                    case Poker.Hands.Pair:
                        pair++;
                        break;
                    case Poker.Hands.RoyalFlush:
                        royalFlush++;
                        break;
                    case Poker.Hands.Straight:
                        straight++;
                        break;
                    case Poker.Hands.StraightFlush:
                        straightFlush++;
                        break;
                    case Poker.Hands.ThreeKind:
                        threeKind++;
                        break;
                    case Poker.Hands.TwoPair:
                        twoPair++;
                        break;
                    case Poker.Hands.HighCard:
                        highCard++;
                        break;
                }

                Console.SetCursorPosition(0, 0);
                Console.WriteLine(string.Format("Pairs: {0} ({1})\r\n2 Pairs: {2} ({3})\r\nPairs of 3: {4} ({5})\r\nPairs of 4: {6} ({7})\r\nFull Houses: {8} ({9})\r\nFlushes: {10} ({11})\r\nStraights: {12} ({13})\r\nStraight Flushes: {14} ({15})\r\nRoyal Flushes: {16} ({17})\r\nHigh Card: {18} ({19})",
                    pair, ((decimal)pair / (decimal)tryCount).ToString("P9"), twoPair, ((decimal)twoPair / (decimal)tryCount).ToString("P9"), threeKind, ((decimal)threeKind / (decimal)tryCount).ToString("P9"), fourKind, ((decimal)fourKind / (decimal)tryCount).ToString("P9"),
                    fullHouse, ((decimal)fullHouse / (decimal)tryCount).ToString("P9"), flush, ((decimal)flush / (decimal)tryCount).ToString("P9"), straight, ((decimal)straight / (decimal)tryCount).ToString("P9"), straightFlush, ((decimal)straightFlush / (decimal)tryCount).ToString("P9"), royalFlush, ((decimal)royalFlush / (decimal)tryCount).ToString("P9"), highCard, ((decimal)highCard / (decimal)tryCount).ToString("P9")));

                deck.Shuffle();
                cards = deck.Draw(7).ToList();
            }

            TimeSpan difference = DateTime.Now - startTime;

            Console.WriteLine(string.Format("Took {0} tries.", tryCount));

            Console.WriteLine(string.Format("Took {0} seconds ({1}/second)", difference.TotalSeconds, ((decimal)tryCount / (decimal)difference.TotalSeconds).ToString("F5")));

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("Pairs: {0} ({1})\r\n2 Pairs: {2} ({3})\r\nPairs of 3: {4} ({5})\r\nPairs of 4: {6} ({7})\r\nFull Houses: {8} ({9})\r\nFlushes: {10} ({11})\r\nStraights: {12} ({13})\r\nStraight Flushes: {14} ({15})\r\nRoyal Flushes: {16} ({17})\r\nHigh Card: {18} ({19})",
                pair, ((decimal)pair / (decimal)tryCount).ToString("P9"), twoPair, ((decimal)twoPair / (decimal)tryCount).ToString("P9"), threeKind, ((decimal)threeKind / (decimal)tryCount).ToString("P9"), fourKind, ((decimal)fourKind / (decimal)tryCount).ToString("P9"),
                fullHouse, ((decimal)fullHouse / (decimal)tryCount).ToString("P9"), flush, ((decimal)flush / (decimal)tryCount).ToString("P9"), straight, ((decimal)straight / (decimal)tryCount).ToString("P9"), straightFlush, ((decimal)straightFlush / (decimal)tryCount).ToString("P9"), royalFlush, ((decimal)royalFlush / (decimal)tryCount).ToString("P9"), highCard, ((decimal)highCard / (decimal)tryCount).ToString("P9")));
            sb.Append("\r\n").Append(string.Format("Took {0} tries.", tryCount)).Append("\r\n");
            sb.Append(string.Format("Took {0} seconds ({1}/second)", difference.TotalSeconds, ((decimal)tryCount / (decimal)difference.TotalSeconds).ToString("F5"))).Append("\r\n\r\n");

            SaveFile(sb.ToString());
        }
Example #5
0
        /// <summary>
        /// This method initializes PlayerHands  and initializes round
        /// TO DO :: SET ACTIVE PLAYER ID TO START THE ROUND
        /// </summary>
        /// <param name="round">Round Index</param>
        /// <returns></returns>
        public bool startRound(int round)
        {
            gameData.ActivePlayerId = gameData.RoundStarter;
            this.gameRoundStatusLabel.Text = "Round : " + gameData.CurrentRound;
            gameData.HandCounter = 0;
            gameData.CurrentPot.ClearPot();

            gameDeck = new Deck();
            gameDeck.Shuffle();

            Hand[] hand = new Hand[4];

            int counter = 0;
            for (int j = 0; j < 4; j++)
            {
                hand[j] = new Hand();

                for (int i = counter; i < counter + 13; i++)
                {
                    hand[j].AddCard((SpadesCard)gameDeck.CardPile[i]);
                }

                counter = counter + 13;
                hand[j].sort();

            }

            // initialize 4 players hand
            int k = 0;
            foreach (player p in gameData.CurrentPlayerList)
            {
                p.Hand = hand[k];
                k++;
                p.TotalBid = 0;
                p.TotalTrick = 0;
            }

            gameData.GameState = GameState.BIDDING;
            updateGameState(gameData);
            return true;
        }
Example #6
0
 private void PrepareHands()
 {
     Deck deck = new Deck();
     deck.Shuffle();
     this.myHands = deck.Deal(myGame.NumberPlayers);
     if (deck.Cards.Length > 0) {
         //TODO create a kitty and notify players
     }
     myGame.PlayerControllers.ForEach(pc => pc.HandReady());
 }