static void Main(string[] args)
        {
            DeterministicDeck myDetermDeck = new DeterministicDeck();
            Card[] fiveCardSet = new Card[5];
            int maxHand = EnumExtender.GetMax(typeof(Hand));
            int[] handCounters = new int[maxHand + 1];

            fiveCardSet = myDetermDeck.GetFiveCards();
            int i, trialsNumber = 2598960;

            ProcessIndicator myProcessIndicator = new ProcessIndicator();
            myProcessIndicator.Start();
            for (i = 0; i < trialsNumber; i++)
            {
                Hand hand = HandChecker.Check(fiveCardSet);
                handCounters[(int)hand]++;
                fiveCardSet = myDetermDeck.NextHand();
            }
            myProcessIndicator.Stop();

            Console.WriteLine("\n");
            foreach (Hand hand in Enum.GetValues(typeof(Hand)))
            {
                Console.WriteLine("{0} : p = {1:#00.00000%}, number = {2}",
                    EnumExtender.GetDescription(hand).PadRight(15),
                    (double)handCounters[(int)hand] / (double)trialsNumber,
                    handCounters[(int)hand]);
            }

            Console.ReadKey(true);
        }
Example #2
0
        public CardControl(Card card)
        {
            InitializeComponent();

              Card = card;
              VisualStateManager.GoToState(this, Suit.ToString(), false);
        }
 public Card[] GetFiveCards()
 {
     Card[] fiveCards = new Card[5];
     for (int i = 0; i < 5; i++)
     {
         fiveCards[i] = cards[i];
     }
     return fiveCards;
 }
Example #4
0
 static void Main(string[] args)
 {
     Card card1 = new Card(Rank.Ace, Suite.Clubs);
     Card card2 = new Card(Rank.Jack, Suite.Spades);
     Card.useTrumps = false;
     Card.isAceHigh = true;
     Console.WriteLine("{0} <= {1} & {2}", card1.ToString(), card2.ToString(), card1 <= card2);
     Console.ReadKey();
 }
Example #5
0
        /// <summary>
        /// 此程序演示了集合索引,运算符重载等内容
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            #region 向CardLib添加一个Cards集合
            Deck myDeck = new Deck();
            myDeck.Shuffle();
            for (int i = 0; i < 52; i++)
            {
                Card tempCard = myDeck.GetCard(i);
                Console.Write(tempCard.ToString());
                if (i != 51)
                    Console.Write(", ");
                else
                    Console.WriteLine();
            }
            Console.ReadKey();
            #endregion

            #region 向CardLib添加深复制集合
            Deck deck1 = new Deck();
            Deck deck2 = (Deck)deck1.Clone();
            Console.WriteLine("The first card in the original deck is: {0}", deck1.GetCard(0));
            Console.WriteLine("The first card in the clone deck is: {0}", deck2.GetCard(0));
            deck1.Shuffle();
            Console.WriteLine("Original deck shuffled.");
            Console.WriteLine("The first card in the original deck is: {0}", deck1.GetCard(0));
            Console.WriteLine("The first card in the clone deck is: {0}", deck2.GetCard(0));
            Console.ReadKey();
            #endregion

            #region 向CardLib添加运算符重载
            Card.isAceHigh = true;
            Console.WriteLine("Aces are high.");
            Card.useTrumps = true;
            Card.trump = Suit.Club;
            Console.WriteLine("Clubs are trumps.");

            Card card1, card2, card3, card4, card5;
            card1 = new Card(Suit.Club, Rank.Five);
            card2 = new Card(Suit.Club, Rank.Five);
            card3 = new Card(Suit.Club, Rank.Ace);
            card4 = new Card(Suit.Heart, Rank.Ten);
            card5 = new Card(Suit.Diamond, Rank.Ace);
            Console.WriteLine("{0} == {1} ? {2}", card1.ToString(), card2.ToString(), card1 == card2);
            Console.WriteLine("{0} != {1} ? {2}", card1.ToString(), card3.ToString(), card1 != card3);
            Console.WriteLine("{0}.Equals({1}) ? {2}", card1.ToString(), card4.ToString(), card1.Equals(card4));
            Console.WriteLine("Card.Equals({0}, {1}) ? {2}", card3.ToString(), card4.ToString(), Card.Equals(card3, card4));
            Console.WriteLine("{0} > {1} ? {2}", card1.ToString(), card2.ToString(), card1 > card2);
            Console.WriteLine("{0} <= {1} ? {2}", card1.ToString(), card3.ToString(), card1 <= card3);
            Console.WriteLine("{0} > {1} ? {2}", card1.ToString(), card4.ToString(), card1 > card4);
            Console.WriteLine("{0} < {1} ? {2}", card1.ToString(), card4.ToString(), card1 < card4);
            Console.WriteLine("{0} > {1} ? {2}", card5.ToString(), card4.ToString(), card1 > card4);
            Console.WriteLine("{0} > {1} ? {2}", card4.ToString(), card5.ToString(), card1 > card4);
            Console.ReadKey();
            #endregion
        }
Example #6
0
 public Deck()
 {
     cards = new Card[52];
     for(int suitVal = 0; suitVal < 4; suitVal++)
     {
         for(int rankVal = 1; rankVal < 14; rankVal++)
         {
             cards[suitVal * 13 + rankVal - 1] = new Card((Suit)suitVal, (Rank)rankVal);
         }
     }
 }
Example #7
0
 public void PerformDraw(Deck deck, Card availableCard)
 {
     switch (Skill)
       {
     case ComputerSkillLevel.Dumb:
       DrawCard(deck);
       break;
     default:
       DrawBestCard(deck, availableCard, (Skill == ComputerSkillLevel.Cheats));
       break;
       }
 }
Example #8
0
        public bool Exists(Card aCard)
        {
            foreach (Card c in cards)
            {
                if (aCard.TextValue == c.TextValue)
                {
                    return true;
                }
            }

            return false;
        }
Example #9
0
        public void Shuffle()
        {
            Card[] newDeck = new Card[52];
            bool[] assigned = new bool[52];
            Random sourceGen = new Random();

            for(int i = 0; i < 52; i++)
            {
                int destCard = 0;
                bool foundCard = false;
                while (foundCard == false)
                {
                    destCard = sourceGen.Next(52);
                    if (assigned[destCard] == false)
                        foundCard = true;
                }
                assigned[destCard] = true;
                newDeck[destCard] = cards[i];
            }
            newDeck.CopyTo(cards, 0);
        }
Example #10
0
 private void InsertAllCards(List<Card> except)
 {
     for (int suitVal = 0; suitVal < 4; suitVal++)
       {
     for (int rankVal = 3; rankVal < 16; rankVal++)
     {
       var card = new Card((Suit)suitVal, (Rank)rankVal);
       if (except.Contains(card))
     continue;
       cards.Add(card);
     }
       }
       var JokerCard = new Card((Suit)3, (Rank)16);
       if (!except.Contains(JokerCard))
     cards.Add(new Card((Suit)3, (Rank)16));
       JokerCard = new Card((Suit)1, (Rank)17);
       if (!except.Contains(JokerCard))
       cards.Add(new Card((Suit)1, (Rank)17));
 }
Example #11
0
 public void setTrumphCard(Card trumphCard)
 {
     this.trumphCard = trumphCard;
 }
Example #12
0
 public void ChooseCard(Card card)
 {
     if (Chosen.Contains(card))
     Chosen.Remove(card);
     else
     Chosen.Add(card);
 }
Example #13
0
        public CardControl(Card card)
        {
            InitializeComponent();

              Card = card;
        }
Example #14
0
		public void Set (Card[] in_cards)
		{
			int i, n;
			n = in_cards.Length;
			if (n > 0)
			{
				//cards = new ArrayList (n+1);
                cards = new List<Card>(n + 1);
				for (i = 1; i <= n; ++i)
					cards.Add (in_cards[i]);
				last = n;
			}
		}
Example #15
0
		public void Cut (int n)
		{
			if (n <= 0) return;
			int i, j, k;
			Card[] temp = new Card[last + 1];
			System.Random rand = new System.Random();

			while (--n >= 0)
			{	
				k = rand.Next(last) + 1;
				if (k == 1) continue;
				j = 1;
				// Cut the deck
				for (i = k; i <= last; ++i)
					temp[j++] = this[i];
				for (i = 1; i < k; ++i)
					temp[j++] = this[i];

				for (i = 1; i <= last; ++i)
					this[i] = temp[i];
			}
		}
Example #16
0
 public void Remove(Card oldCard)
 {
     List.Remove(oldCard);
 }
Example #17
0
 public void AddCard(Card card)
 {
     cards.Add(card);
     last++;
 }
Example #18
0
 public void AddCard(Card card)
 {
     Hand.Add(card);
       if (Hand.Count > 7)
     State = PlayerState.MustDiscard;
 }
Example #19
0
 public void setCard(CardSuits suit, CardValues values)
 {
     this.card = new CardLib.Card(suit, values);
     card.Flip();
     pictureBox1.Image = card.FacingImage;
 }
Example #20
0
        /// <summary>
        /// Draw method
        /// </summary>
        /// <param name="prompt"></param>
        public Card CardDraw(string prompt)
        {
            #if DEBUG
            int suitValue;
            string choice = _cardGame.GetCardString(prompt);

            if(choice == "XX")
            {
                cardNo = random.Next(_avail.Count);
            }

            else
            {
                if (choice[1] == 'H')
                { suitValue = 0; }
                else if (choice[1] == 'D')
                { suitValue = 1; }
                else if (choice[1] == 'C')
                { suitValue = 2; }
                else
                { suitValue = 3; }

                if(choice[0] == 'T')
                {
                    cardNo = (suitValue * 13 + 9);
                }
                else if (choice[0] == 'A')
                {
                    cardNo = (suitValue * 13);
                }
                else
                {
                    cardNo = (suitValue * 13 + (int)Char.GetNumericValue(choice[0]) - 1);
                }
            }

            Card drawCard = new Card(cardNo);
            return drawCard;

            #else //release mode draw
            System.Threading.Thread.Sleep(5);
            int drawValue = random.Next(_avail.Count);
            Card drawCard = new Card(drawValue);
            return drawCard;
            #endif
        }
Example #21
0
 public void setCard(Card card)
 {
     this.card = card;
     pictureBox1.Image = card.BackImage;
 }
Example #22
0
 //Remove card from collection
 public void Remove(Card targetCard)
 {
     List.Remove(targetCard);
 }
Example #23
0
 private void DrawBestCard(Deck deck, Card availableCard, bool cheat = false)
 {
     var bestSuit = CalculateBestSuit();
       if (availableCard.suit == bestSuit)
     AddCard(availableCard);
       else if (cheat == false)
     DrawCard(deck);
       else
     AddCard(deck.SelectCardOfSpecificSuit(bestSuit));
 }
Example #24
0
 private void InsertAllCards(List<Card> except)
 {
     for (int suitVal = 0; suitVal < 4; suitVal++)
       {
     for (int rankVal = 1; rankVal < 14; rankVal++)
     {
       var card = new Card((Suit)suitVal, (Rank)rankVal);
       if (except.Contains(card))
     continue;
       cards.Add(card);
     }
       }
 }
Example #25
0
        public CardControl(Card card)
        {
            InitializeComponent();

            Card = card;
        }
Example #26
0
 public void Add(Card newCard)
 {
     List.Add(newCard);
 }
Example #27
0
 public void DiscardCard(Card card)
 {
     Hand.Remove(card);
       if (HasWon && OnPlayerHasWon != null)
     OnPlayerHasWon(this, new PlayerEventArgs { Player = this, State = PlayerState.Winner });
       if (OnCardDiscarded != null)
     OnCardDiscarded(this, new CardEventArgs { Card = card });
 }
Example #28
0
 /// <summary>
 /// 检查Cards集合中是否包含指定Card
 /// 这个方法将通过InnerList属性调用ArrayList的Contains方法
 /// </summary>
 /// <param name="card"></param>
 /// <returns></returns>
 public bool Contains(Card card)
 {
     return InnerList.Contains(card);
 }