Esempio n. 1
0
        private static bool ReplaceSetWithNewCards(Deck deck, Table table, IList<Card> set)
        {
            Card[] nextCards = deck.GetNext(3);
            if (!nextCards.Any()) return false; // Not enough cards left in deck

            // Loop through each card in the set looking for it's position on the table
            // And replace card with new card from the deck.
            for (int i = 0; i < set.Count; i++)
            {
                for (int j = 0; j < table.Cards.Count(); j++)
                {
                    if (table.Cards[j] != set[i]) continue;

                    Console.WriteLine(String.Format("Replace Card {0}, {1} with {2}", i, table.Cards[j], nextCards[i]));
                    //TODO use list. Don't replace in array.
                    //TODO look for more than one set
                    //TODO if no sets, add 3 more cards
                    //TODO try combinations of two and loop through remaining cards
                    table.Cards[j] = nextCards[i];
                    break;
                }
            }

            return true;
        }
Esempio n. 2
0
        public void CanShuffleDeck()
        {
            var deck = new Deck();
            String newDeck = String.Join<Card>(",", deck.Cards);

            deck.Shuffle();
            String shuffledDeck = String.Join<Card>(",", deck.Cards);

            Assert.AreNotEqual(newDeck, shuffledDeck);
        }
Esempio n. 3
0
 public void CanGetCardsFromDeck()
 {
     var deck = new Deck();
     Card[] firstDeal = deck.GetNext(12);
     Assert.AreEqual(12, firstDeal.Count());
     Assert.AreEqual(12, deck.Index);
     Card[] secondHand = deck.GetNext(3);
     Assert.AreEqual(3, secondHand.Count());
     Assert.AreEqual(15, deck.Index);
 }
Esempio n. 4
0
 public void FindMatchingCombinationsAndReplaceCards()
 {
     var deck = new Deck();
     var table = new Table { Cards = deck.GetNext(12) };
     var combinations = new Combinations<Card>(table.Cards, 3);
     var sets = combinations.Where(IsMatch);
     var cards = sets.FirstOrDefault();
     Console.WriteLine(String.Format("Match found: {{{0} {1} {2}}}", cards[0], cards[1], cards[2]));
     ReplaceSetWithNewCards(deck, table, cards);
 }
Esempio n. 5
0
        public void GetSetCombinations()
        {
            var deck = new Deck();
            var table = new Table { Cards = deck.GetNext(12) };

            Combinations<Card> combinations = new Combinations<Card>(table.Cards, 3);

            foreach (IList<Card> c in combinations)
            {
                Console.WriteLine(String.Format("{{{0} {1} {2}}}", c[0], c[1], c[2]));
            }
        }
Esempio n. 6
0
        public void CanBuildShuffledDeck()
        {
            var deck = new Deck();
            String x = String.Join<Card>(",", deck.Cards);

            var shuffledDeck = new ShuffledDeck();
            String y = String.Join<Card>(",", shuffledDeck.Cards);

            var deck2 = new Deck();
            String z = String.Join<Card>(",", deck2.Cards);

            Assert.AreNotEqual(x, y);
            Assert.AreEqual(x, z);
        }
Esempio n. 7
0
        public void CanReplaceCardsInSet()
        {
            var deck = new Deck();
            var table = new Table {Cards = deck.GetNext(12)};

            Card[] nextCards = deck.GetNext(3);
            table.Cards[0] = nextCards[0];
            Assert.AreEqual(table.Cards[0], deck.Cards[12]);

            table.Cards[1] = nextCards[1];
            Assert.AreEqual(table.Cards[1], deck.Cards[13]);

            table.Cards[2] = nextCards[2];
            Assert.AreEqual(table.Cards[2], deck.Cards[14]);
        }
Esempio n. 8
0
        public void FindFirstMatchingCombinations()
        {
            var deck = new Deck();
            var table = new Table {Cards = deck.GetNext(12)};

            var combinations = new Combinations<Card>(table.Cards, 3);

            foreach (IList<Card> c in combinations)
            {
                if (IsMatch(c))
                {
                    Console.WriteLine(String.Format("{{{0} {1} {2}}}", c[0], c[1], c[2]));
                    break;
                }
            }
        }
Esempio n. 9
0
 public void EndOfDeckReturnsNoCards()
 {
     var deck = new Deck();
     Card[] cards = deck.GetNext(100);
     Assert.AreEqual(0, cards.Count());
 }
Esempio n. 10
0
 public void CanDealFirst12CardsOntoTable()
 {
     var deck = new Deck();
     var table = new Table {Cards = deck.GetNext(12)};
     Assert.AreEqual(table.Cards.Count(), 12);
 }
Esempio n. 11
0
 public void CanBuildDeck()
 {
     var deck = new Deck();
     Assert.AreEqual(deck.Cards.Count(), 81);
 }
Esempio n. 12
0
        private static bool ReplaceSetWithNewCards(Deck deck, Table table, IList<Card> set)
        {
            Card[] nextCards = deck.GetNext(3);
            if (!nextCards.Any()) return false;

            for (int i = 0; i < set.Count; i++)
            {
                String before = String.Join<Card>(",", table.Cards);

                for (int j = 0; j < table.Cards.Count(); j++)
                {
                    if (table.Cards[j] != set[i]) continue;
                    Console.WriteLine(String.Format("Replace Card {0}, {1} with {2}", i, table.Cards[j], nextCards[i]));
                    table.Cards[j] = nextCards[i];
                    break;
                }

                String after = String.Join<Card>(",", table.Cards);
                Assert.AreNotEqual(before, after);
            }

            return true;
        }