0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Story
    {                                      //Sorry I've been gone a while. I'm coming back to this after all this time to see if I can fix it.

        public static void WriteStory()
        {

            Random rnd = new Random();

            //Genders

            string[] genders = { "Man", "Woman", "Neutral", "Noun", "Other" };

            //Names

            string[] male_names = { "Austin", "Ace", "Appolo", "Asher", "Benson", "Brock", "Baird", "Bennett", "Christopher", "Caleb", "Chaddick", "Campbell", "Callum", "Dominic", "Dayton",
                "Davey", "Dylan", "Eli", "Eastwood", "Eddison", "Emmett", "Elliot", "Ferris", "Finn", "Fuller", "Grady", "Garrison", "Guy", "Garth", "Grayson", "Henry", "Hagan", "Houston",
                "Hartley", "Holt", "Isaiah", "Indy", "Irving", "Josiah", "Jordan", "Jace", "Jamison", "Jack", "Kingston", "Kyler", "Kade", "Keegan", "Kason", "Landon", "Luca", "Lambert",
                "Lincoln", "Magnus", "Micah", "Malone", "Monroe", "Nico", "Nolan", "Niles", "Noah", "Orion", "Oakley", "Oliver", "Orin", "Princeton", "Parker", "Porter", "Paxton", "Quinn",
                "Quade", "Quentin", "Rafe", "Remi", "Ramsey", "Rhett", "Rowan", "Sawyer", "Samson", "Sebastian", "Shiloh", "Thomas", "Tristan", "Topher", "Tanner", "Thornton", "Upton", "Urbain",
                "Vance", "Voss", "Vinny", "Weston", "Wyatt", "Wade", "Xavier", "Xander", "Yates", "York", "Zeke", "Zane" };

            string[] female_names = { "Abigail", "Adeline", "Alex", "Ariel", "Aurora", "Averie", "Belle", "Berkleigh", "Blake", "Brielle", "Brinley", "Brooklyn", "Crystal", "Catarina", "Cambridge",
                "Camryn", "Cayleigh", "Delilah", "Demi", "Dani", "Darsey", "Desire", "Emma", "Emory", "Elsa", "Eva", "Ellerie", "Ember", "Fiona", "Felicia", "Faith", "Felicity", "Frankie", "Georgia",
                "Gabriella", "Gianna", "Gisele", "Gemma", "Hendrix", "Henley", "Harper", "Hadley", "Harmony", "Isabella", "Illianna", "Iris", "Izzie", "Juliana", "Jordyn", "Jillian", "Jasmine",
                "Jaclyn", "Josie", "Kimber", "Katalina", "Kya", "Kayleigh", "Kadence", "Lily", "Lianna", "Leah", "Lacie", "Lola", "Merida", "Madeline", "Marcilee", "Maisie", "Makaylyn", "Max",
                "Nora", "Nia", "Nadia", "Natalia", "Nahla", "Orion", "Owyn", "Ophelia", "Olivia", "Oriahna", "Phoenix", "Priscilla", "Paige", "Polly", "Primrose", "Quinn", "Quaid", "Randalynn",
                "Randi", "Roxy", "Raven", "Renee", "Staci", "Sami", "Selah", "Skye", "Snow", "Tianna", "Tiffany", "Teigan", "Tessa", "Trinity", "Ursula", "Uriah", "Vivi", "Victoria", "Venicia",
                "Valentina", "Venus", "Winona", "Wendy", "Winnie", "Waverly", "Willow", "Xenia", "Xia", "Yoli", "Yasmine", "Ysabelle", "Yesenia", "Zora", "Zoe", "Zayla", "Zahra" };

            string[] neutral_names = { "Addison", "Adrian", "Ainsley", "Alex", "Andy", "Ari", "Ash", "Aspen", "Aubrey", "Bailey", "Bay", "Blaine", "Bobbie", "Brett", "Brook", "Caelan", "Campbell",
                "Carroll", "Charlie", "Chris", "Clay", "Corey", "Dana", "Dakota", "Dale", "Daryl", "Devin", "Dorian", "Drew", "Eddie", "Eli", "Elliot", "Frances", "Frankie", "Gabriel", "Glenn",
                "Gray", "Harper", "Hayden", "Jamie", "Jean", "Jesse", "Jordan", "Jules", "Julian", "Kaden", "Kelly", "Kennedy", "Lake", "Logan", "Max", "Morgan", "Pat", "Peyton", "Ray", "Reed",
                "Riley", "River", "Roan", "Rudy", "Ryan", "Sage", "Sam", "Shawn", "Sean", "Stevie", "Tanner", "Taylor", "Toby", "Tyler", "Val", "West", "Winter", "Xavier", "Zane" };

            string[] nouns = { "dog", "cat", "bird", "goat", "cow", "horse", "snake", "man", "woman", "child", "rat", "mouse", "jug", "house", "stick", "tree", "rock", "pony", "book", "coin", "cup",
                "leaf", "insect", "beetle", "car", "wagon", "ox", "sword", "gun", "tire", "lake", "ship", "boat", "airplane", "spaceship", "boy", "girl", "potato", "carrot", "chicken", "demon", "angel",
                "island", "town", "city", "computer", "laptop", "TV", "CEO", "dresser", "table", "chair", "bed", "plant", "animal", "restaurant", "ruby", "sapphire", "diamond", "radio", "bag",
                "keyboard", "sofa", "biscuit", "whale", "fish", "tuna", "shark", "outfit", "bandit", "bear", "elf", "troll", "library", "police officer", "fireman", "cheese", "milk", "garden", "banana" };

            string[] others = { "I", "We", "You", "She", "He", "They", "It" };

            //For use with "others" pronouns

            string[] others0 = { "myself", "you", "her", "him", "them", "it" };

            string[] others1 = { "ourselves", "you", "her", "him", "them", "it" };

            string[] others2 = { "me", "us", "yourself", "her", "him", "them", "it" };

            string[] others3 = { "me", "us", "you", "herself", "him", "them", "it" };

            string[] others4 = { "me", "us", "you", "her", "himself", "them", "it" };

            string[] others5 = { "me", "us", "you", "her", "him", "themself", "it" };

            string[] others6 = { "me", "us", "you", "her", "him", "them", "itself" };

            //Pronouns, Articles, and Adjectives

            int index_o0 = rnd.Next(others0.Length);

            int index_o1 = rnd.Next(others1.Length);

            int index_o2 = rnd.Next(others2.Length);

            int index_o3 = rnd.Next(others3.Length);

            int index_o4 = rnd.Next(others4.Length);

            int index_o5 = rnd.Next(others5.Length);

            int index_o6 = rnd.Next(others6.Length);

            int x = rnd.Next(genders.Length);

            int index_male = rnd.Next(male_names.Length);

            int index_female = rnd.Next(female_names.Length);

            int index_neutral = rnd.Next(neutral_names.Length);

            int index_nouns = rnd.Next(nouns.Length);

            int index_others = rnd.Next(others.Length);

            int index_obj = rnd.Next(nouns.Length);


            string gender = genders[x];

            string name = null;

            string obj = nouns[index_obj];

            string[] articles0 = { "An", "The", "That" };
            string[] articles1 = { "A", "The", "That" };
            string Article = null;
            int index_art0 = rnd.Next(articles0.Length);
            int index_art1 = rnd.Next(articles1.Length);
            string[] adjectives = { "strange", "weird", "blue", "red", "green", "purple", "orange", "yellow", "dead", "happy", "sad", "lively", "smelly", "colorful", "hairy", "bold", "tan", "beautiful",
                "scenic", "sickly", "lovely", "tired", "moldy", "spoiled", "dancing", "fast", "slow", "smart", "gassy", "pulsating", "pooping", "floral", "black", "white", "American", "French",
                "Hispanic", "German", "Australian", "Danish", "Swedish", "African", "fat", "skinny", "tall", "short", "large", "big", "small", "tiny", "miniscule", "devilish", "scared", "angry",
                "cute", "evil", "angelic", "feathery", "ugly", "hungry" };
            string adj = null;
            int index_adj = rnd.Next(adjectives.Length);

            string pronoun0 = null;
            string pronoun1 = null;
            string pronoun2 = null;

            switch (gender)
            {

                case "Man":
                    pronoun0 = others4[index_o4];
                    pronoun1 = "his";
                    pronoun2 = "he";
                    name = male_names[index_male];
                    break;

                case "Woman":
                    pronoun0 = others3[index_o3];
                    pronoun1 = "her";
                    pronoun2 = "she";
                    name = female_names[index_female];
                    break;

                case "Neutral":
                    pronoun0 = others5[index_o5];
                    pronoun1 = "their";
                    pronoun2 = "they";
                    name = neutral_names[index_neutral];
                    break;

                case "Noun":
                    pronoun0 = others6[index_o6];
                    pronoun1 = "its";
                    pronoun2 = "it";
                    name = nouns[index_nouns];
                    if (name[0] == 'a' || name[0] == 'e' || name[0] == 'i' || name[0] == 'o' || name[0] == 'u')
                    {
                        Article = articles0[index_art0];
                    }
                    else
                    {
                        Article = articles1[index_art1];
                    }
                    adj = adjectives[index_adj];
                    break;

                case "Other":
                    name = others[index_others];

                    if (name == "I")
                    {
                        pronoun0 = others0[index_o0];
                        pronoun1 = "my";
                        pronoun2 = "I";
                    }
                    else if (name == "We")
                    {
                        pronoun0 = others1[index_o1];
                        pronoun1 = "our";
                        pronoun2 = "we";
                    }
                    else if (name == "You")
                    {
                        pronoun0 = others2[index_o2];
                        pronoun1 = "your";
                        pronoun2 = "you";
                    }
                    else if (name == "She")
                    {
                        pronoun0 = others3[index_o3];
                        pronoun1 = "her";
                        pronoun2 = "she";
                    }
                    else if (name == "He")
                    {
                        pronoun0 = others4[index_o4];
                        pronoun1 = "his";
                        pronoun2 = "he";
                    }
                    else if (name == "They")
                    {
                        pronoun0 = others5[index_o5];
                        pronoun1 = "their";
                        pronoun2 = "they";
                    }
                    else if (name == "It")
                    {
                        pronoun0 = others1[index_o6];
                        pronoun1 = "its";
                        pronoun2 = "it";
                    }
                    break;
            }




//HERE:



            //Let's get some verbs in here!

            string action = null;

            string reaction = null;

            string[] Tense0 = { "Past", "Present", "Future" };

            int y = rnd.Next(Tense0.Length);

            string tense0 = Tense0[y];

            string tense1 = null;

            string[] past_act = { "once told", "told", "once showed", "showed", "screamed at", "shouted to", "meowed at", "bit", "had bitten" };

            string[] past_react = { "exploded!", "died!", "become a pretty princess!" };

            string[] present_act0 = { "tells", "shows", "screams at", "shouts to", "meows at", "bites" };

            string[] present_act1 = { "telling", "showing", "screaming at", "shouting to", "meowing at", "biting" };

            string[] present_react0 = { "explodes!", "dies!", "becomes a pretty princess!" };

            string[] present_react1 = { "exploding!", "dying!", "becoming a pretty princess!" };

            string[] future_act0 = { "will tell", "will show", "will scream at", "will shout to", "will meow at", "will bite" };

            string[] future_act1 = { "going to tell", "going to show", "going to scream at", "going to shout to", "going to meow at", "going to bite" };

            string[] future_react0 = { "will explode!" };

            string[] future_react1 = { "going to explode!" };



            //This next bit is about tense and "had", "have", "has", "is", & "are"


            //Past

            int index_pastA = rnd.Next(past_act.Length);

            int index_pastR = rnd.Next(past_react.Length);

            //Present

            int index_presA0 = rnd.Next(present_act0.Length);

            int index_presA1 = rnd.Next(present_act1.Length);

            var present_act2 = new string[index_presA0 + index_presA1];

            int index_presA2 = rnd.Next(present_act2.Length);

            int index_presR0 = rnd.Next(present_react0.Length);

            int index_presR1 = rnd.Next(present_react1.Length);

            var present_react2 = new string[index_presR0 + index_presR1];

            int index_presR2 = rnd.Next(present_react2.Length);

            //Future

            int index_futA0 = rnd.Next(future_act0.Length);

            int index_futA1 = rnd.Next(future_act1.Length);

            var future_act2 = new string[index_futA0 + index_futA1];

            int index_futA2 = rnd.Next(future_act2.Length);

            int index_futR0 = rnd.Next(future_react0.Length);

            int index_futR1 = rnd.Next(future_react1.Length);

            var future_react2 = new string[index_futR0 + index_futR1];

            int index_futR2 = rnd.Next(future_react2.Length);



            switch (tense0)
            {

                case "Past":
                    action = past_act[index_pastA];
                    reaction = past_react[index_pastR];
                    break;

                case "Present":
                    action = present_act2[index_presA2];
                    reaction = present_react2[index_presR2];
                    break;

                case "Future":
                    action = future_act2[index_futA2];
                    reaction = future_react2[index_futR2];
                    break;
            }





            bool Past = false;
            bool Present = false;
            bool Future = false;

            switch (tense0)
            {
                case "Past":
                    Past = true;
                    Present = false;
                    Future = false;
                    break;

                case "Present":
                    Past = false;
                    Present = true;
                    Future = false;
                    break;

                case "Future":
                    Past = false;
                    Present = false;
                    Future = true;
                    break;
            }

            switch (gender)
            {
                case "Man":
                    if (Past == true)
                    {
                        tense1 = "had";
                    }

                    else if (Present == true)
                    {
                        tense1 = "is";
                    }
                    else if (Future == true)
                    {
                        tense1 = "is";
                    }
                    break;

                case "Woman":

                    if (Past == true)
                    {
                        tense1 = "had";
                    }

                    else if (Present == true)
                    {
                        tense1 = "is";
                    }
                    else if (Future == true)
                    {
                        tense1 = "is";
                    }

                    break;

                case "Neutral":

                    if (Past == true)
                    {
                        tense1 = "had";
                    }

                    else if (Present == true)
                    {
                        tense1 = "are";
                    }
                    else if (Future == true)
                    {
                        tense1 = "are";
                    }

                    break;

                case "Noun":

                    if (Past == true)
                    {
                        tense1 = "had";
                    }

                    else if (Present == true)
                    {
                        tense1 = "is";
                    }
                    else if (Future == true)
                    {
                        tense1 = "is";
                    }

                    break;

                case "Other":
                    name = others[index_others];

                    if (name == "I")
                    {
                        if (Past == true)
                        {
                            tense1 = "have";
                        }

                        else if (Present == true)
                        {
                            tense1 = "am";
                        }
                        else if (Future == true)
                        {
                            tense1 = "am";
                        }
                    }
                    else if (name == "We")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "are";
                        }
                        else if (Future == true)
                        {
                            tense1 = "are";
                        }
                    }
                    else if (name == "You")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "are";
                        }
                        else if (Future == true)
                        {
                            tense1 = "are";
                        }
                    }
                    else if (name == "She")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "is";
                        }
                        else if (Future == true)
                        {
                            tense1 = "is";
                        }
                    }
                    else if (name == "He")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "is";
                        }
                        else if (Future == true)
                        {
                            tense1 = "is";
                        }
                    }
                    else if (name == "They")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "are";
                        }
                        else if (Future == true)
                        {
                            tense1 = "are";
                        }
                    }
                    else if (name == "It")
                    {
                        if (Past == true)
                        {
                            tense1 = "had";
                        }

                        else if (Present == true)
                        {
                            tense1 = "is";
                        }
                        else if (Future == true)
                        {
                            tense1 = "is";
                        }
                    }
                    break;
            }




            //Conjunction time!

            string[] conjunction = { "for", "and", "nor", "but", "or", "yet", "so", "after", "although", "as", "as if", "as long as", "as much as", "as soon as", "as though", "because", "before",
                "by the time", "even if", "even though", "if", "in order that", "in case", "in the event that", "lest", "now that", "once", "only", "only if", "provided that", "since", "so",
                "supposing", "that", "than", "though", "till", "unless", "until", "when", "whenever", "where", "whereas", "wherever", "whether or not", "while" };

            int index_conj0 = rnd.Next(conjunction.Length);

            int index_conj1 = rnd.Next(conjunction.Length);

            string conj0 = conjunction[index_conj0];

            string conj1 = conjunction[index_conj1];


            //Time for the story!


            string Tale = ($"{Article} {adj} {name} {tense1} {action} {pronoun0} {conj1} {pronoun1} {obj} {conj0} {pronoun2} {tense1} {reaction}");


            //The result


            Console.WriteLine(Tale);

        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Story.WriteStory();

            Console.ReadLine();

        }
    }
}

"An unhandled exception of type 'System.IndexOutOfRangeException' occurred in ConsoleApplication1.exe" the exception occurred at the end of the Future case. This is part of a much larger code to make a random story generator. The future_act0 and future_act1 need to be separate for grammar reasons. Same with the Present variables.

  • 1
    Does this answer your question? [What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?](https://stackoverflow.com/questions/20940979/what-is-an-indexoutofrangeexception-argumentoutofrangeexception-and-how-do-i-f) – germi Dec 04 '19 at 10:43
  • What are you trying to do with `var future_react2 = new string[index_futR0 + index_futR1];`? – Innat3 Dec 04 '19 at 10:48
  • I need to take 1 string from either at random. – DemiBlueman Dec 04 '19 at 10:52
  • `new string[index_futR0 + index_futR1];` does not copy data, it just creates a new array of strings. (empty ones) – Jeroen van Langen Dec 04 '19 at 10:58
  • @JeroenvanLangen then what should I do for that? – DemiBlueman Dec 04 '19 at 11:07
  • @DemiBlueman What is it what you want? You want to combine these arrays? You can try this: `string[] combined = others0.Concat(others1).ToArray();` _(make sure that the namespace `using System.Linq;` is at the top of the file.)_ – Jeroen van Langen Dec 04 '19 at 11:11
  • I need to combine them while keeping them separate for the later code `case "Present": action = present_act2[index_presA2]; reaction = present_react2[index_presR2]; break; case "Future": action = future_act2[index_futA2]; reaction = future_react2[index_futR2]; break; }` @JeroenvanLangen – DemiBlueman Dec 04 '19 at 11:27

1 Answers1

1

Your code is overly long and confusing, I suggest you start of by using an enum instead of an array of strings to classify the verb tenses.

public enum Tense
{
    Past,
    Present,
    Future
}

Then we can declare two List<>'s of Tuples (Tense, string[]) where we add our actions and reactions, classified by their Tense.

var actions = new List<(Tense, string[])>
{
    (Tense.Past, past_act),
    (Tense.Present, present_act0),
    (Tense.Present, present_act1),
    (Tense.Future, future_act0),
    (Tense.Future, future_act1)
};

var reactions = new List<(Tense, string[])>
{
    (Tense.Past, past_react),
    (Tense.Present, present_react0),
    (Tense.Present, present_react1),
    (Tense.Future, future_react0),
    (Tense.Future, future_react1)
 };

We then retrieve a random value from our Tense enum

 Random r = new Random();
 Tense t = (Tense)r.Next(Enum.GetNames(typeof(Tense)).Length);

Finally, using Linq we filter out the lists to retrieve the values of the required Tense, and shuffle them before retrieving a value.

 string action = actions
                     .Where(x => x.Item1 == t)      // filter according to tense
                         .SelectMany(x => x.Item2)  // merge the sublists (e.g. future_act0 and future_act1 into the same collection
                            .OrderBy(x => r.Next()) // shuffle them
                                .FirstOrDefault();  // grab the first

 string reaction = reactions
                       .Where(x => x.Item1 == t)       // filter according to tense
                           .SelectMany(x => x.Item2)   // merge the sublists (e.g. future_react0 and future_react1 into the same collection
                               .OrderBy(x => r.Next()) // shuffle them
                                   .FirstOrDefault();  // grab the first

I realize this solution is very different from yours, but I hope it gives you at least some insight on an alternate way of doing things.

Innat3
  • 3,561
  • 2
  • 11
  • 29