private void CreateAndSerializeEnemyStrategy(Configuration config)
        {
            var strategyGenerator = new StrategiesGenerator(config.GeneticConfig.MaxStrategySize);

            EnemyStrategy = strategyGenerator.GenerateEnemyProgram();
            StrategySerializator.SerializeToFile(enemyStrategyFile, EnemyStrategy, new FightStat());
        }
Exemple #2
0
        private void LogAllStrategies(Population population)
        {
            string folderName = $"{directory}Generation{population.Index}";

            try
            {
                if (Directory.Exists(folderName))
                {
                    Directory.Delete(folderName, true);
                }
                Directory.CreateDirectory(folderName);
            }
            catch (Exception)
            {
                logger.Error("Cannot create population directory");
            }
            int index = 0;

            foreach (var pair in population.SpeciesAndValues)
            {
                string filename = $"{folderName}\\#{index} - fitness={pair.Value.Result}";
                try
                {
                    StrategySerializator.SerializeToFile(filename, pair.Key, pair.Value);
                }
                catch (Exception)
                {
                    logger.Error($"Cannot create file {filename}");
                }
                index++;
            }
        }