예제 #1
0
        } // end constructor

        // Returns a List<Hand> of the specified dimension.
        // Each hand populated randomly, without duplication (i.e. no card appears twice)
        public List <Hand> Deal(int handCount, int handLength)
        {
            // What error checking is missing here?
            //If handCount and handLength are possible, eg not over 52.

            List <Hand> dealtHands = new List <Hand>();

            // Used to insure each card appears only once in the deal
            bool[,] cardUsed = new bool[RankCount, SuitCount];
            Random rand = new Random();

            // Take time to make sure you understand the logic.
            // This is a very common algorithm pattern.
            for (int h = 0; h < handCount; h++)
            {
                Hand currentHand = new Hand();
                int  cardCount   = 0;

                while (cardCount < handLength)
                {
                    int nextCardRank = rand.Next(RankCount);
                    int nextCardSuit = rand.Next(SuitCount);

                    if (cardUsed[nextCardRank, nextCardSuit] == false)
                    {
                        currentHand.AddCard(cards[nextCardRank, nextCardSuit]);
                        cardUsed[nextCardRank, nextCardSuit] = true;
                        cardCount++;
                    }
                }
                currentHand.ComputeHCP();

                //Sorts current hand by suit and rank
                currentHand.SortHand();

                dealtHands.Add(currentHand);
            } // all hands dealt

            //Sorts all hands by the highest points
            dealtHands.Sort();

            return(dealtHands);
        } // end Deal
예제 #2
0
        // Returns a List<Hand> of the specified dimension.
        // Each hand populated randomly, without duplication (i.e. no card appears twice)
        public List<Hand> Deal(int handCount, int handLength)
        {
            // What error checking is missing here?
            //If handCount and handLength are possible, eg not over 52.

            List<Hand> dealtHands = new List<Hand>();

            // Used to insure each card appears only once in the deal
            bool[,] cardUsed = new bool[RankCount, SuitCount];
            Random rand = new Random();

            // Take time to make sure you understand the logic.
            // This is a very common algorithm pattern.
            for (int h = 0; h < handCount; h++)
            {
                Hand currentHand = new Hand();
                int cardCount = 0;

                while (cardCount < handLength)
                {
                    int nextCardRank = rand.Next(RankCount);
                    int nextCardSuit = rand.Next(SuitCount);

                    if (cardUsed[nextCardRank, nextCardSuit] == false)
                    {
                        currentHand.AddCard(cards[nextCardRank, nextCardSuit]);
                        cardUsed[nextCardRank, nextCardSuit] = true;
                        cardCount++;
                    }
                }
                currentHand.ComputeHCP();

                //Sorts current hand by suit and rank
                currentHand.SortHand();

                dealtHands.Add(currentHand);
            } // all hands dealt

            //Sorts all hands by the highest points
            dealtHands.Sort();

            return dealtHands;
        }
예제 #3
0
        public void PrintHand(ListBox displayBox, Hand handToPrint)
        {
            String spadeString   = "S:\t";
            String heartString   = "H:\t";
            String diamondString = "D:\t";
            String clubString    = "C:\t";

            // Remember the ShortRank data member in the Card class?
            // Here's where we use it...
            handToPrint.SortHand();
            foreach (Card c in handToPrint.CardsInHand)
            {
                switch (c.Suit)
                {
                case SuitValue.Spades:
                    spadeString += c.ShortRank + " ";
                    break;

                case SuitValue.Hearts:
                    heartString += c.ShortRank + " ";
                    break;

                case SuitValue.Diamonds:
                    diamondString += c.ShortRank + " ";
                    break;

                case SuitValue.Clubs:
                    clubString += c.ShortRank + " ";
                    break;
                }
            }

            displayBox.Items.Add(spadeString);
            displayBox.Items.Add(heartString);
            displayBox.Items.Add(diamondString);
            displayBox.Items.Add(clubString);

            int hcp = handToPrint.TotalHCP;

            displayBox.Items.Add("HCP: " + hcp);
        }
예제 #4
0
        public void PrintHand(ListBox displayBox, Hand handToPrint)
        {
            String spadeString = "S:\t";
            String heartString = "H:\t";
            String diamondString = "D:\t";
            String clubString = "C:\t";

            // Call to sort an individual hand
            handToPrint.SortHand();

            // Remember the ShortRank data member in the Card class?
            // Here's where we use it...
            foreach(Card c in handToPrint.CardsInHand)
            {
                switch(c.Suit)
                {
                    case SuitValue.Spades:
                        spadeString += c.ShortRank + " ";
                        break;
                    case SuitValue.Hearts:
                        heartString += c.ShortRank + " ";
                        break;
                    case SuitValue.Diamonds:
                        diamondString += c.ShortRank + " ";
                        break;
                    case SuitValue.Clubs:
                        clubString += c.ShortRank + " ";
                        break;
                }
            }

            displayBox.Items.Add(spadeString);
            displayBox.Items.Add(heartString);
            displayBox.Items.Add(diamondString);
            displayBox.Items.Add(clubString);

            int hcp = handToPrint.TotalHCP;
            displayBox.Items.Add("HCP: " + hcp);
        }