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); }
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]); }
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; }
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); }
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])); } }
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; } } }
public void EndOfDeckReturnsNoCards() { var deck = new Deck(); Card[] cards = deck.GetNext(100); Assert.AreEqual(0, cards.Count()); }
public void CanDealFirst12CardsOntoTable() { var deck = new Deck(); var table = new Table {Cards = deck.GetNext(12)}; Assert.AreEqual(table.Cards.Count(), 12); }
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; }