예제 #1
0
 public void ReplaceCard(AbstractCombinatoricsPuzzleCard card)
 {
     if (card != null && DeadCards.Contains(card))
     {
         Deck.Add(card);
         DeadCards.Remove(card);
     }
 }
예제 #2
0
        public AbstractCombinatoricsPuzzleCard DrawCard()
        {
            AbstractCombinatoricsPuzzleCard card = null;

            if (Deck.Count > 0)
            {
                lock (Deck)
                {
                    card = Deck[0];
                    Deck.Remove(card);
                    DeadCards.Insert(0, card);
                }
            }
            return(card);
        }
예제 #3
0
 /// <summary>
 /// Richard Durstenfeld version of Fisher–Yates shuffle -- To shuffle an array a of n elements(indices 0..n-1):
 ///   for i from n−1 downto 1 do
 ///   j ← random integer such that 0 ≤ j ≤ i
 ///   exchange a[j] and a[i]
 /// </summary>
 private void Shuffle()
 {
     lock (Deck)
     {
         AbstractCombinatoricsPuzzleCard tempCard = null;
         for (int index = Deck.Count - 1; index > 0; index--)
         {
             int random = Random.Next(0, index + 1);
             if (index != random)
             {
                 tempCard     = Deck[index];
                 Deck[index]  = Deck[random];
                 Deck[random] = tempCard;
             }
         }
     }
 }