예제 #1
0
        private void TribeNamesSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            object currentItem = GraphLinesSelector.SelectedValue;

            GraphLinesSelector.Items.Clear();
            if (TribeNamesSelector.SelectedValue == null)
            {
                return;
            }
            bool previousItemFound = false;

            if (StatisticsCollector.GetEventNames(TribeNamesSelector.SelectedValue.ToString()) == null)
            {
                return;
            }
            foreach (string lineName in StatisticsCollector.GetEventNames(TribeNamesSelector.SelectedValue.ToString()).ToArray().OrderBy(s => s))
            {
                if (currentItem != null && currentItem.ToString() == lineName)
                {
                    previousItemFound = true;
                }
                GraphLinesSelector.Items.Add(lineName);
            }
            if (previousItemFound)
            {
                GraphLinesSelector.SelectedValue = currentItem;
            }
        }
예제 #2
0
        private void EndlessSimultaion()
        {
            while (true)
            {
                if (World.IsExtinct)
                {
                    endlessSimulationRunning = false;
                    Thread.Sleep(100);
                }
                while (!endlessSimulationRunning)
                {
                    Thread.Sleep(100);
                }
                while (stepCalculationInProgress)
                {
                    Thread.Sleep(10);
                }
                stepCalculationInProgress = true;
                World.SimulateYear(Dispatcher);
                Dispatcher.Invoke(new System.Action(delegate()
                {
                    int restartAfter = Convert.ToInt32(txtRestartSim.Text);
                    if (restartAfter > 0 && World.Year >= restartAfter)
                    {
                        World.CollectFinalState();
                        StatisticsCollector.SaveDetaliedStatistic();
                        World.InitializeNext(Dispatcher);
                    }
                    lblYear.Content = World.Year.ToString() + "  " + World.spendedTime;
                }));

                stepCalculationInProgress = false;
            }
        }
예제 #3
0
 private void Expander_Expanded(object sender, RoutedEventArgs e)
 {
     TribeNamesSelector.Items.Clear();
     TribeNamesSelector.Items.Add(StatisticsCollector.GLOBAL);
     foreach (string tribeName in StatisticsCollector.GetTribeNames())
     {
         if (tribeName != StatisticsCollector.GLOBAL)
         {
             TribeNamesSelector.Items.Add(tribeName);
         }
     }
 }
예제 #4
0
파일: World.cs 프로젝트: kraidiky/TribeSim
        private static void ReportEndOfYearStatistics()
        {
            foreach (Tribe t in tribes)
            {
                StatisticsCollector.ReportCountEvent(t.TribeName, "Tribes in the world.");
                StatisticsCollector.ReportSumEvent(t.TribeName, "Population", t.Population);
            }

            World.tribes.Parallel((tribe) => { tribe.ReportEndOfYearStatistics(); });
            if (WorldProperties.CollectLiveMemes > 0.5)
            {
                StatisticsCollector.ReportGlobalSumEvent("Live memes", Meme.CountLiveMemes());
            }
        }
예제 #5
0
 private void Clear_Click(object sender, RoutedEventArgs e)
 {
     if (TribeNamesSelector.SelectedValue == null)
     {
         return;
     }
     if (GraphLinesSelector.SelectedValue == null)
     {
         return;
     }
     ChartArea.AddLineGraph((ObservableDataSource <Point>)(StatisticsCollector.GetDataSet(TribeNamesSelector.SelectedValue.ToString(), GraphLinesSelector.SelectedValue.ToString()).DataSource), TribeNamesSelector.SelectedValue.ToString() + ": " + GraphLinesSelector.SelectedValue.ToString());
     foreach (var v in ChartArea.Children.ToArray())
     {
         if (v is Microsoft.Research.DynamicDataDisplay.LineGraph)
         {
             ChartArea.Children.Remove(v);
         }
     }
 }
예제 #6
0
파일: Tribe.cs 프로젝트: kraidiky/TribeSim
        public double GoHunting(AvailableFeatures huntingEfficiencyFeature)
        {
            double sumHuntingPowers       = 0;
            double cooperationCoefficient = 0;
            int    numHunters             = 0;

            foreach (Tribesman man in members)
            {
                var chance = man.GetFeature(AvailableFeatures.LikelyhoodOfNotBeingAFreeRider);
                if (randomizer.Chance(chance))
                {
                    double huntingEfforts = man.GoHunting(huntingEfficiencyFeature);
                    if (huntingEfforts > 0)
                    {
                        sumHuntingPowers       += huntingEfforts;
                        cooperationCoefficient += man.GetFeature(AvailableFeatures.CooperationEfficiency);
                        numHunters++;
                    }
                }
                else
                {
                    man.SkipHunting();
                }
            }
            if (members.Count > 0)
            {
                StatisticsCollector.ReportAverageEvent(TribeName, "Percentage of hunters", (double)numHunters / members.Count);
            }
            if (numHunters == 0)
            {
                return(0);
            }
            cooperationCoefficient /= numHunters;
            StatisticsCollector.ReportAverageEvent(TribeName, "Average hunting efforts", sumHuntingPowers * cooperationCoefficient);
            StatisticsCollector.ReportSumEvent(TribeName, "Total hunting efforts", sumHuntingPowers * cooperationCoefficient);

            return(sumHuntingPowers * cooperationCoefficient);
        }
예제 #7
0
파일: World.cs 프로젝트: kraidiky/TribeSim
        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;
        }
예제 #8
0
파일: World.cs 프로젝트: kraidiky/TribeSim
        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)}");
                }
            }
        }
예제 #9
0
파일: Meme.cs 프로젝트: kraidiky/TribeSim
 public void ReportDetaliedStatistic()
 {
     StatisticsCollector.ReportEvent(new SucessStatistic(this, World.Year));
 }