public static void Initialize(Dispatcher d, int randomSeed) { WorldProperties.ResetFeatureDescriptions(); randomizer = new Random(randomSeed); StatisticsCollector.Reset(); Meme.ClearMemePool(); tribes.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); if (!string.IsNullOrWhiteSpace(baseFolder)) { logFolder = Path.Combine(baseFolder, DateTime.Now.ToString("yyyyMMdd_HHmmss")); } else { baseFolder = Properties.Settings.Default.LogBaseFolder; if (string.IsNullOrWhiteSpace(baseFolder)) { logFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Tribe Sim Results", DateTime.Now.ToString("yyyyMMdd_HHmmss")); } else { logFolder = Path.Combine(baseFolder, DateTime.Now.ToString("yyyyMMdd_HHmmss")); } } Directory.CreateDirectory(logFolder); tribesLogFolder = Path.Combine(logFolder, "Tribes"); memesLogFolder = Path.Combine(logFolder, "Memes"); tribesmanLogFolder = Path.Combine(logFolder, "Tribesmen"); simDataFolder = Path.Combine(logFolder, "Results"); Directory.CreateDirectory(tribesmanLogFolder); Directory.CreateDirectory(tribesLogFolder); Directory.CreateDirectory(memesLogFolder); if (WorldProperties.CollectFilesData > 0.5) { Directory.CreateDirectory(simDataFolder); } Year = 0; int i; for (i = 0; i < WorldProperties.StartingNumberOfTribes; i++) { Tribe t = new Tribe(randomizer.Next(int.MaxValue)); int numberOfTribesmen = (int)Math.Round(randomizer.NormalRandom(WorldProperties.StartingTribePopulationMean, WorldProperties.StartingTribePopulationStdDev)); for (int ii = 0; ii < numberOfTribesmen; ii++) { Tribesman man = Tribesman.GenerateTribesmanFromAStartingSet(randomizer); t.AcceptMember(man); } tribes.Add(t); } int maxReproductionAge = 5000; // Это сломатся если у нас появятся сверхдолгожители if (WorldProperties.MaximumBreedingAge > 0) { maxReproductionAge = (int)WorldProperties.MaximumBreedingAge + 1; } Tribesman.reproductionCostIncrease = new double[maxReproductionAge]; i = 0; for (; i < WorldProperties.BreedingCostsIncreaseAge; i++) { Tribesman.reproductionCostIncrease[i] = 0; } for (; i < maxReproductionAge; i++) { Tribesman.reproductionCostIncrease[i] = (i - WorldProperties.BreedingCostsIncreaseAge) * WorldProperties.BreedingCostsIncreaseCoefficient; } ReportEndOfYearStatistics(); d.Invoke(new Action(delegate() { StatisticsCollector.ConsolidateNewYear(); })); Tribesman.UseGompertzAgeing = WorldProperties.UseGompertzAgeing > 0.5; }
public static void SimulateYear(Dispatcher d) { Year++; if (Year == 1000) // Первые 1000 циклов пропускаем. Там всякое медленное делается. { stopwatch = Stopwatch.StartNew(); } if (Year % 11000 == 0) { stopwatch.Stop(); spendedTime = stopwatch.Elapsed; } PrepareForANewYear(); if (WorldProperties.SkipLifeSupportStep < 0.5) { LifeSupport(); } if (WorldProperties.SkipSpontaneousMemeInventionStep < 0.5) { InventMemes(); } if (WorldProperties.SkipForgettingMemesStep < 0.5) { ForgetUnusedMemes(); } if (WorldProperties.SkipTeachingStep < 0.5) { Teach(); } if (WorldProperties.SkipFreeRiderPunishmentStep < 0.5) { PunishFreeRiders(); } if (WorldProperties.SkipHuntingStep < 0.5) { HuntAndShare(AvailableFeatures.HuntingEfficiency); } if (WorldProperties.SkipHuntingBStep < 0.5) { HuntAndShare(AvailableFeatures.HuntingBEfficiency); } if (WorldProperties.SkipUselessActionsStep < 0.5) { UselessAction(); } if (WorldProperties.SkipStudyingStep < 0.5) { Study(); } if (WorldProperties.SkipDeathStep < 0.5) { Die(); } foreach (Tribe t in tribes.ToArray()) { if (t.IsExtinct) { tribes.Remove(t); } } if (WorldProperties.SkipBreedingStep < 0.5) { Breed(); } if (WorldProperties.SkipMigrationStep < 0.5) { Migrate(); } if (WorldProperties.SkipGroupSplittingStep < 0.5) { SplitGroups(); } if (WorldProperties.SkipCulturalExchangeStep < 0.5) { CulturalExchange(); } OverpopulationPrevention(); if ((WorldProperties.CollectGraphData > 0.5 && (Year % (int)WorldProperties.CollectGraphData == 0)) || (WorldProperties.CollectFilesData > 0 && (Year % (int)WorldProperties.CollectFilesData == 0 || (Year + 1) % (int)WorldProperties.CollectFilesData == 0))) { ReportEndOfYearStatistics(); d.Invoke(new Action(delegate() { StatisticsCollector.ConsolidateNewYear(); })); } if (Year % 11000 == 1) { Console.WriteLine($"========== year:{Year} =========="); for (int i = 0; i < tribes.Count; i++) { Console.WriteLine($"tribe[{tribes[i].seed}] rnd:{tribes[i].randomizer.Next(10000)}"); } } }