コード例 #1
0
ファイル: Program.cs プロジェクト: justbark/mtg
        public static void generateDeck(int minCards, int maxCards)
        {
            string[] colors = new string[] { "Blue", "Black", "Green", "Red", "White" };
            Deck newDeck = new Deck();

            Random rand = new Random();
            int index = rand.Next(0, colors.Length);
            Console.WriteLine(index);
            string primaryColor = colors[index];
            Console.WriteLine(primaryColor);

            int numCards = rand.Next(minCards, maxCards);
            Console.WriteLine(numCards);

            //================================================================
            //generate Weights
            //================================================================
            mutate(5, newDeck);
            newDeck.PrintWeights();
            //================================================================
            //landSection
            //================================================================
            int maxLand = 30;
            int minLand = 23;
            int landQuantity = rand.Next(minLand, maxLand);
            Console.WriteLine("land quatity = " + landQuantity);
            int cardsRemaining = numCards - landQuantity;
            Console.WriteLine(" Cards remaining = " + cardsRemaining);
            //this is just determining the number of lands for the deck. not actually selecting them

            //================================================================
            //deck quantities
            //===============================================================
            int maxCopyOfCard = 4;
            int maxColors = 2;
            //================================================================
            //percentages for deck
            //================================================================

            /*--------minimum percentages----------
            double minPercInstant = 0.17;
            double minPercSorcery = 0.17;
            double minPercCreature = 0.24;
            double minPercEnchantment = 0.17;
            double minPercPlaneswalker = 0.05;
            double minPercArtifact = 0.10;
            double minPercTribal = 0.10;

            //---------maximum percentages---------
            double maxPercInstant = 0.20;
            double maxPercSorcery = 0.20;
            double maxPercCreature = 0.50;
            double maxPercEnchantment = 0.20;
            double maxPercPlaneswalker = 0.10;
            double maxPercArtifact = 0.50;
            double maxPercTribal = 0.20;*/

            //================================================================
            //card selection
            //================================================================
            int quantInstant = (int)Math.Round(newDeck.weights[0] * cardsRemaining);
            int quantSorcery = (int)Math.Round(newDeck.weights[1] * cardsRemaining);
            int quantCreature = (int)Math.Round(newDeck.weights[2] * cardsRemaining);
            int quantEnchantment = (int)Math.Round(newDeck.weights[3] * cardsRemaining);
            int quantPlaneswalker = (int)Math.Round(newDeck.weights[4] * cardsRemaining);
            int quantArtifact = (int)Math.Round(newDeck.weights[5] * cardsRemaining);
            int quantTribal = (int)Math.Round(newDeck.weights[6] * cardsRemaining);

            //get the number of cards for the deck via the random deck quantities
            int totalCards = (quantInstant + quantSorcery + quantCreature + quantEnchantment + quantPlaneswalker + quantArtifact + quantTribal);
            Console.WriteLine("total cards = " + totalCards);
            //get the total number of cards including land
            int numGeneratedCards = landQuantity + totalCards;
            Console.WriteLine("numGeneratedCards = " + numGeneratedCards);
            //this is the number of cards that the deck is missing, due to decimals
            int requiredAdjustment = numCards - numGeneratedCards; // FIX ME. do something more intelligent with this value.
            Console.WriteLine("requiredAdjustment = " + requiredAdjustment);
            Console.WriteLine("Joes total cards =\n qI=" + quantInstant + "\n qS=" + quantSorcery + "\n qC="  + quantCreature + "\n qE="  + quantEnchantment + "\n qP="  + quantPlaneswalker + "\n qA="  + quantArtifact + "\n qT="  + quantTribal);
            Console.WriteLine("land quantity = " + landQuantity);

            while (quantInstant != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantInstant--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantSorcery != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantSorcery--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantCreature != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantCreature--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantEnchantment != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantEnchantment--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantPlaneswalker != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantPlaneswalker--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantArtifact != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantArtifact--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }

            while (quantTribal != 0)
            {
                int randomCardIndex = rand.Next(0, Shared.instant.Count);
                Card randomCard = Shared.instant[randomCardIndex];
                //create a subset of random cards. This keeps track to see if there are multiples of 1 card
                if (newDeck.deckCardList.Where(x => x == randomCard).Count() >= maxCopyOfCard)
                {
                    Console.WriteLine("Oops I picked a card too many times, moving on.");
                    continue;
                }
                if (!randomCard.colors.Contains(primaryColor))
                {
                    Console.WriteLine("this card is not the correct color. Moving on.");
                    continue;
                }
                newDeck.deckCardList.Add(randomCard);
                quantTribal--;
                Console.WriteLine("Ive selected " + randomCard.name + "\n" + "the deckSize is now " + newDeck.deckCardList.Count());

            }
            //======================================================
            //adding land to the deck
            //======================================================

            Card landCard = Shared.land.Where(x => x.colors.Contains(primaryColor)).First();
            if (landCard != null)
            {
                for (int i = 0; i < landQuantity; i++)
                {
                    newDeck.deckCardList.Add(landCard);
                }
            }
            else
            {
                Console.WriteLine("there has been an error. No mana card found");
                return;
            }

            /*quantOLand = 25
            rem  =60- 25 = 35
            max/minArtType
            0.20 0.10
            QuantArtType = rand.Next(minArtType, maxArtType)
            0.1578
            rem*QuantArtType =
            3.8
            4
            rem -= 4
            rem = rem - 4;
             newDeck.cards.Add(Shared.artifacts[whateverIndex]);
             the line above is how you get a new card into the deck list*/

            /*int cardIndex;

            for (int i = 0; i < numCards; i++)
            {
                cardIndex = rand.Next(0, Shared.cards.Count());
                newDeck.deckCardList.Add(Shared.cards[cardIndex]);
            }*/
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: justbark/mtg
        /*private static generateName(Deck deck)
        {
            // name the deck after some card in the deck, or card color.
            // These strings should be informed by the contents of newDeck.cards
            String properNoun;
            String adjective;
            String color;

            // example: "justin's big black deck"
            newDeck.name = properNoun + "\'s" + " " + adjective + " " + color + " deck";
            return "blah";
        }*/
        public static void mutate(int passes, Deck deck)
        {
            double fudge = 0.33; // this adjusts our mutation amplitude
            Random rand = new Random();
            for (int i = 0; i < passes; i++)
            {

                int rand_a = 0;
                int rand_b = 0;
                while (rand_a == rand_b)
                {
                    rand_a = rand.Next(0, deck.weights.Count - 1);
                    rand_b = rand.Next(0, deck.weights.Count - 1);
                }
                float mutationMagnitude = (float)(rand.NextDouble() * deck.weights.Average() * fudge);
                //Console.WriteLine("mutation magnitude = " + mutationMagnitude);
                if (deck.weights[rand_a] - mutationMagnitude <= 0.1 || deck.weights[rand_b] + mutationMagnitude >= 0.90)
                {
                    continue;
                }
                deck.weights[rand_a] -= mutationMagnitude;
                deck.weights[rand_b] += mutationMagnitude;
            }
        }