public void TestSupportedLanguages() { int registered = LanguageGen.Registry.Count; for (int i = 1; i < registered; i++) { LanguageGen lang = LanguageGen.Registry[Value.At, i]; Console.WriteLine(lang.Name); } }
public void TestSentences() { RNG random = new RNG("Language!"); int registered = LanguageGen.Registry.Count; for (int i = 1; i < registered; i++) { LanguageGen lang = LanguageGen.Registry[Value.At, i]; Console.WriteLine("==============================================================================="); Console.WriteLine(lang.Name); Console.WriteLine(); for (int j = 0; j < 10; j++) { Console.WriteLine(lang.Sentence(random, 1, 30, 79)); } } }
public void TestSentencesRandom() { RNG random = new RNG("Language!"); RNG randomLang = new RNG("Random Languages!"); for (int i = 0; i < 10; i++) { LanguageGen lang = LanguageGen.RandomLanguage(randomLang); Console.WriteLine("==============================================================================="); Console.Write(lang.Name); Console.Write(", using state "); Console.WriteLine(lang.Summary.Substring(2, 32)); Console.WriteLine(); for (int j = 0; j < 10; j++) { Console.WriteLine(lang.Sentence(random, 1, 30, 79)); } } }
public void WriteSentences() { RNG random = new RNG("Language!"); int registered = LanguageGen.Registry.Count; StringBuilder sb = new StringBuilder(); for (int i = 1; i < registered; i++) { LanguageGen lang = LanguageGen.Registry[Value.At, i]; sb.AppendLine("==============================================================================="); sb.Append(lang.Name); sb.AppendLine(); for (int j = 0; j < 10; j++) { sb.AppendLine(lang.Sentence(random, 1, 30, 79)); } } string temp = System.IO.Path.GetTempFileName(); File.WriteAllText(temp, sb.ToString()); Console.WriteLine(temp); }
static void Main(string[] args) { //NameGen names = new NameGen(); //// would it help with memory if I saved every 250, then read them back into a hashset, and started all over again? //int count = 0; //HashSet<string> namesTest = new HashSet<string>(); //string currentName; //while (true) //{ // count++; // currentName = names.SingleName(CoreEnums.Word.ElfMale); // namesTest.Add(currentName); // Console.Write(namesTest.Count + "; " + currentName + "\n"); //} //Database worldGen = new Database(System.Configuration.ConfigurationManager.AppSettings["Testing"]); Database worldGen = new Database("DevWorldGen"); new PopulateDatabaseNames(worldGen).AddAdjectives(); Console.ReadLine(); CalendarGen calendar = new CalendarGen(); IYear calendarYear = calendar.Generate(); // Generate the mythology MythosGen mythos = new MythosGen(); List<IMythology> mythologies = new List<IMythology>(); if ((_Random.Next(0, 2) == 1)) { mythologies.AddRange(mythos.GenerateMultiple()); } else { mythologies.Add(mythos.GenerateSingle()); } // Generate the world WorldGen worlds = new WorldGen(); IWorld world = worlds.Generate(mythologies); // Generate the common language LanguageGen languages = new LanguageGen(); ILanguage commonTongue = languages.Generate(); // Generate the races RaceGen raceGen = new RaceGen(mythologies, commonTongue); List<IRace> races = raceGen.GenerateMultiple(_Random.Next(3, 8)); // Generate the civilizations present CivilizationGen civGen = new CivilizationGen(); List<ICivilization> civilizations = civGen.GenerateMultiple(races); // Generate the continents ContinentGen continentGen = new ContinentGen(world); List<IContinent> continents = continentGen.Generate(_Random.Next(2, 5)); // TODO: I don't think the Climate/Features is totally working // TODO: military structures (castles, outposts, etc...), 1-3-5 per region, determine control of the region (must be an odd number) // Generate the regions within the continents RegionGen regionGen = new RegionGen(); List<IRegion> availableRegions = new List<IRegion>(); // this is for a starting region of a civilization foreach (IContinent continent in continents) { continent.ListOfRegions = regionGen.Generate(continent, civilizations); availableRegions.AddRange(continent.ListOfRegions); } // now assign a starting region and hamlet to each civilization PopulationCenterGen popGen = new PopulationCenterGen(); foreach (ICivilization civilization in civilizations) { int index = _Random.Next(0, availableRegions.Count - 1); IRegion region = availableRegions.ElementAt(index); civilization.RegionsOwned.Add(availableRegions[index]); availableRegions.RemoveAt(index); civilization.PopulationCenters.Add(popGen.GenerateSingle(civilization)); } // How will populations spread? When the settlement reaches a certain population, a certain "level"? // Once they fill a region they'll move into adjacent regions, begin clashing with others // I need to define both TotalPopulation as well as individual civilization's populations // All of this will create a population for each civilization // TODO: is this implemented..? Each person needs to be added to the hamlet in the region established in the previous foreach // http://www.codeproject.com/Articles/189374/The-Basics-of-Task-Parallelism-via-C CancellationTokenSource cts = new CancellationTokenSource(); // do I really need this? //List<IPerson> totalPopulation = new List<IPerson>(); PersonGen populace = new PersonGen(); //int populationCount = 0; //switch (civilizations.First().Race.GetType().Name.ToLower()) //{ // case "humans": // //populationCount = _Random.Next(650, 720); // populationCount = 25; // break; // case "dwarves": // //populationCount = _Random.Next(820, 900); // populationCount = 25; // break; // default: // //populationCount = _Random.Next(1100, 1400); // populationCount = 25; // break; //} //PersonHelper personInfo = new PersonHelper(); //personInfo.Civilization = civilizations.First(); //personInfo.Race = civilizations.First().Race; //personInfo.Mythology = civilizations.First().Race.Mythos; //// maybe we should check the population levels before starting the next loop? First thing in the for loop? //IPopulationCenters popCenter = civilizations.First().PopulationCenters.First(pc => pc.Population.Count < pc.MaxPopulation); //personInfo.OriginatesFrom = popCenter; // WHAT HAPPENS WHEN WE RUN OUT OF CITIES!? //personInfo.Father = new Person(); //personInfo.Mother = new Person(); //personInfo.Partner = new Person(); //// TODO: the name generator is not threadsafe I do not think. Need to start storing names in a DB ////int index = civilizations.FindIndex(c => c.Id == civilizations.First().Id); //Task<List<IPerson>> populationTask = new Task<List<IPerson>>(() => populace.GenerateMultiple(civilizations.First(), populationCount, personInfo), cts.Token); //populationTask.Start(); //populationTask.Wait(); #region //civilization.TotalPopulation = populationTask.Result; //totalPopulation.AddRange(populationTask.Result); // I DON'T THINK THIS IS THREAD SAFE // would it be better to create a list of tasks and then execute them? int totalPopulation = 0; List<Task> tasks = new List<Task>(); foreach (ICivilization civilization in civilizations) { int populationCount = 0; switch (civilization.Race.GetType().Name.ToLower()) { case "humans": //populationCount = _Random.Next(650, 720); populationCount = 25; break; case "dwarves": //populationCount = _Random.Next(820, 900); populationCount = 25; break; default: //populationCount = _Random.Next(1100, 1400); populationCount = 25; break; } PersonHelper personInfo = new PersonHelper(); personInfo.Civilization = civilization; personInfo.Race = civilization.Race; personInfo.Mythology = civilization.Race.Mythos; // maybe we should check the population levels before starting the next loop? First thing in the for loop? IPopulationCenters popCenter = civilization.PopulationCenters.First(pc => pc.Population.Count < pc.MaxPopulation); personInfo.OriginatesFrom = popCenter; // WHAT HAPPENS WHEN WE RUN OUT OF CITIES!? personInfo.Father = new Person(); personInfo.Mother = new Person(); personInfo.Partner = new Person(); // TODO: the name generator is not threadsafe I do not think. Need to start storing names in a DB int index = civilizations.FindIndex(c => c.Id == civilization.Id); Task<List<IPerson>> populationTask = new Task<List<IPerson>>(() => populace.GenerateMultiple(civilization, populationCount, personInfo), cts.Token); //tasks.Add(populationTask); populationTask.Start(); //civilization.TotalPopulation = populationTask.Result; //totalPopulation.AddRange(populationTask.Result); //populationTask.Wait(); totalPopulation += populationCount; } //foreach (Task task in tasks) //{ // task.Start(); //} Task.WaitAll(); cts.Cancel(); #endregion Console.WriteLine("Total Civilizations: " + civilizations.Count); Console.WriteLine("Total Population: " + totalPopulation); Console.ReadLine(); }