public static bool TryStartSubgame(GameState gameState, out GameState subgameState)
        {
            subgameState = null;
            var subgameDecks = new List <Deck>();

            foreach (var deck in gameState.Decks)
            {
                var deckCopy = DeckHelper.GetDeckCopy(deck);
                if (deckCopy.SpaceCards.Count == 0)
                {
                    continue;
                }
                var topCard = deckCopy.SpaceCards.Dequeue();
                if (deckCopy.SpaceCards.Count < topCard)
                {
                    return(false);
                }
                var subgameDeckCards = new List <int>();
                for (int i = 0; i < topCard; i++)
                {
                    subgameDeckCards.Add(deckCopy.SpaceCards.Dequeue());
                }
                var subgameDeck = new Deck(deckCopy.PlayerName, subgameDeckCards);
                subgameDecks.Add(subgameDeck);
            }
            if (subgameDecks.Count < 2)
            {
                return(false);
            }
            subgameState = new GameState(subgameDecks, false);
            return(true);
        }
        public static bool TryPlayClassicRound(
            GameState initialGameState,
            out GameState finalGameState)
        {
            finalGameState = initialGameState;
            var deckCopies = new List <Deck>();

            foreach (var deck in initialGameState.Decks)
            {
                var deckCopy = DeckHelper.GetDeckCopy(deck);
                deckCopies.Add(deckCopy);
            }

            var topCards            = new List <int>();
            var bestCardPlayerIndex = -1;
            var bestCard            = -1;

            for (int playerIndex = 0; playerIndex < deckCopies.Count; playerIndex++)
            {
                var deck = deckCopies[playerIndex];
                if (deck.SpaceCards.Count == 0)
                {
                    continue;
                }
                var topCard = deck.SpaceCards.Dequeue();
                topCards.Add(topCard);

                if (topCard > bestCard)
                {
                    bestCard            = topCard;
                    bestCardPlayerIndex = playerIndex;
                }
            }

            // If one or fewer players still have cards, then the game is over
            if (topCards.Count < 2)
            {
                return(false);
            }

            // Add the cards to the winner's deck
            if (bestCardPlayerIndex >= 0)
            {
                var deck       = deckCopies[bestCardPlayerIndex];
                var cardsToAdd = topCards
                                 .OrderByDescending(card => card)
                                 .Select(card => card)
                                 .ToList();
                foreach (var card in cardsToAdd)
                {
                    deck.SpaceCards.Enqueue(card);
                }
            }

            finalGameState = new GameState(deckCopies, false);
            return(true);
        }