private static string FillString(string rawArtifact) { Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); // Set up the name generator MarkovChainsNameGenerator generator = new MarkovChainsNameGenerator(random: rnd, minLength: 3, maxLength: 7);; generator.TrainMapBuilder(@"../../ArtifactGenerator/Sources/names.txt"); int index; string line; string curArtifact = rawArtifact; List <string> nouns = new List <string>(); List <string> adjectives = new List <string>(); // Load the lists of nouns and adjectives using (StreamReader r = new StreamReader(@"../../ArtifactGenerator/Sources/nouns.txt")) { while ((line = r.ReadLine()) != null) { nouns.Add(line); } } using (StreamReader r = new StreamReader(@"../../ArtifactGenerator/Sources/adjectives.txt")) { while ((line = r.ReadLine()) != null) { adjectives.Add(line); } } // Replace all instance of <NAME> with a generated name while ((index = curArtifact.IndexOf("<NAME>")) != -1) { curArtifact = curArtifact.Remove(index, "<NAME>".Length); curArtifact = curArtifact.Insert(index, generator.GetName()); } // Replace all instance of <NOUN> with a randomly chosen noun while ((index = curArtifact.IndexOf("<NOUN>")) != -1) { curArtifact = curArtifact.Remove(index, "<NOUN>".Length); curArtifact = curArtifact.Insert(index, nouns[rnd.Next(0, nouns.Count)]); } // Replace all instance of <ADJECTIVE> with a randomly chosen noun while ((index = curArtifact.IndexOf("<ADJECTIVE>")) != -1) { curArtifact = curArtifact.Remove(index, "<ADJECTIVE>".Length); curArtifact = curArtifact.Insert(index, adjectives[rnd.Next(0, adjectives.Count)]); } return(curArtifact); }
public static List <Artifact> GenerateArticats(out Dictionary <int, Artifact> artifactHistory) { // Set up the artifact generator Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); MarkovChainsNameGenerator artifactGenerator = new MarkovChainsNameGenerator(random: rnd, minLength: 2, maxLength: 10, capitalize: false, skipWhitespace: false, blacklistedNames: blacklist); artifactGenerator.TrainMapBuilder(@"../../ArtifactGenerator/Sources/structures.txt"); // Get the history of previous artifacts and set up IDs for new artifacts artifactHistory = LoadHistory(); int[] histKeys = new int[artifactHistory.Count]; artifactHistory.Keys.CopyTo(histKeys, 0); int curID = 0; // By default set the current ID as 0 if (artifactHistory != null) { curID = histKeys[histKeys.Length - 1]; } // If there is a history, then start ID off of that else { artifactHistory = new Dictionary <int, Artifact>(); } // Get a bunch of artifact strings and send them to the parser IEnumerable <string> artifacts = artifactGenerator.GetNames(100); // Generate a bunch of artifacts, the parser will trim it down List <Artifact> newArtifacts = ArtifactParser.ParseArtifacts(new List <string>(artifacts)); // ID the artifacts and save the new artifacts in the history structure Console.WriteLine("Todays artifacts:"); for (int i = 0; i < newArtifacts.Count; i++) { newArtifacts[i].ID = curID + i + 1; artifactHistory[newArtifacts[i].ID] = newArtifacts[i]; Console.WriteLine(Artifact.ToString(newArtifacts[i])); } return(newArtifacts); }