Esempio n. 1
0
        private static void CombineDecks(Queue<Deck> Deck, List<Deck> ToAdd)
        {
            // Shuffle the input deck to prevent ENDLESS WAR(!) or 'biased' results
            ToAdd.FastShuffle();

            foreach (Deck c in ToAdd)
                Deck.Enqueue(c);
        }
Esempio n. 2
0
        // War Game Functions
        //----------------------------------------------------------------------------------------------------------
        private static void RunGame(GameStats g, List<Deck> CardDeck, Queue<Deck> PlayerDeck, Queue<Deck> ComputerDeck, bool FastShuffle, bool DealFirst)
        {
            if (FastShuffle)
                CardDeck.FastShuffle();
            else
                CardDeck.Shuffle();

            DealCards(PlayerDeck, ComputerDeck, CardDeck, DealFirst);

            // Calculate hand weight for each player
            foreach (Deck c in PlayerDeck)
                g.PlayerWeight += c.Value - 8;

            foreach (Deck c in ComputerDeck)
                g.ComputerWeight += c.Value - 8;

            // Create temporary deck to store cards in
            List<Deck> Temp = new List<Deck>();

            // Main game loop
            ulong turns = 0;

            while (PlayerDeck.Count > 0 && ComputerDeck.Count > 0)
            {
                turns++;

                // Grab a card from each player
                Deck PlayerCard = PlayerDeck.Dequeue();
                Deck ComputerCard = ComputerDeck.Dequeue();

                Temp.Add(PlayerCard);
                Temp.Add(ComputerCard);

                // Check to see who's card has a higher value
                if (PlayerCard.Value > ComputerCard.Value)
                    CombineDecks(PlayerDeck, Temp);

                else if (ComputerCard.Value > PlayerCard.Value)
                    CombineDecks(ComputerDeck, Temp);

                else // tie
                    TieBreaker(PlayerDeck, ComputerDeck, Temp);

                Temp.Clear();
            }

            if (PlayerDeck.Count == 0 && ComputerDeck.Count == 0) // There was a tie for every card!
                g.Draws++;
            else if (ComputerDeck.Count == 0)
                g.PlayerWins++;
            else
                g.ComputerWins++;

            g.Turns += turns;
        }