/// <summary>
 ///     For a cheating computer player in a poker game, creates a used deck with enough card for one player to make one swap.
 /// </summary>
 /// <param name="secondHandQuality">Cheat level.</param>
 /// <returns></returns>
 public Tuple<string, string> PopHands(int secondHandQuality)
 {
     var deckCount = secondHandQuality > 0 ? (int)(secondHandQuality / 8) : 0;
     var redealCount = secondHandQuality % 8;
     var structures = new List<NewDeckStructure>();
     for (int i = 0; i < deckCount + 1; i++)
     {
         var structure = new NewDeckStructure();
         structure.Deck = new Deck();
         structure.Deck.Shuffle();
         structure.Hand1 = $"{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()}";
         var redeals = (i < deckCount ? 8 : redealCount + 1);
         for (int j = 0; j < redeals; j++)
         {
             var hand2 = $"{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()},{structure.Deck.Pop()}";
             var fc = new FormationChecker(hand2);
             fc.CheckFormation();
             var hand2score = fc.Score;
             structure.Hands2.Add(Tuple.Create(hand2, hand2score));
         }
         structures.Add(structure);
     }
     structures.Sort((a, b) => (a.HighestDeck2Score > b.HighestDeck2Score ? 1 : (a.HighestDeck2Score < b.HighestDeck2Score ? -1 : 0)));
     this.deck = structures.Last().Deck;
     return Tuple.Create(structures.Last().Hand1, structures.Last().HighestHand2());
 }
        static void Main(string[] args)
        {
            do
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("Hand> ");
                var hand = Console.ReadLine().Trim();
                if (hand == "")
                    return;

                //Does user want to test the deck?
                if (string.Compare(hand, "test_deck", true) == 0)
                {
                    TestDeck();
                    continue;
                }

                //Does user want to test the deck manager?
                if (string.Compare(hand, "test_deck_manager", true) == 0)
                {
                    TestDeckManager();
                    continue;
                }

                //Else, assume user has entered a hand.
                try
                {
                    var f = new FormationChecker(hand);
                    if (f.CheckFormation())
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine(f.ToString());
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Can't check now.");
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.GetType());
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(ex.Message);
                }

            } while (true);
        }
 public static void TestDeckManager()
 {
     var dm = new DeckManager();
     var hand_2_quality = rnd.Next(100);
     var hands = dm.PopHands(hand_2_quality);
     Console.ForegroundColor = ConsoleColor.Blue;
     Console.WriteLine("Hand 1:");
     var f = new FormationChecker(hands.Item1);
     f.CheckFormation();
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine(f.ToString());
     Console.ForegroundColor = ConsoleColor.Blue;
     Console.WriteLine($"Hand 2 (quality {hand_2_quality}):");
     f = new FormationChecker(hands.Item2);
     f.CheckFormation();
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine(f.ToString());
 }