private void CreateAndSerializeEnemyStrategy(Configuration config) { var strategyGenerator = new StrategiesGenerator(config.GeneticConfig.MaxStrategySize); EnemyStrategy = strategyGenerator.GenerateEnemyProgram(); StrategySerializator.SerializeToFile(enemyStrategyFile, EnemyStrategy, new FightStat()); }
private void InitiatePopulation(StrategyGeneratorConfig strategyGeneratorConfig) { var generator = new StrategiesGenerator(maxLength, strategyGeneratorConfig); var initialStrategies = Enumerable.Range(0, size).Select(i => generator.GenerateProgram()); UpdateStrategies(initialStrategies); }
public void GenerateRandomProgram_should_return_working_program() { var generator = new StrategiesGenerator(30); var program = generator.GenerateProgram(); Assert.IsTrue(StrategiesGenerator.CheckProgram(program.commands)); }
private void MakeNextGeneration() { var nextGenerationStrategies = GetNextGenerationStrategies(); if (!nextGenerationStrategies.Any(strategy => StrategiesGenerator.CheckProgram(strategy.commands))) { throw new Exception("Wrong strategy!"); } population.UpdateStrategies(nextGenerationStrategies); population = geneticEngine.SelectPopulation(population); logger.LogGeneration(population); population.IncreaseIndex(); }
// public static void Main() // { // Clear(); // var configuration = Configuration.DeserializeFromFile(ConfigFilename); // var geneticAlgorithm = new GeneticAlgorithm(configuration); // geneticAlgorithm.Run(); // } // // private static void Clear() // { // for (int i = 0; i < 30; i++) // { // string folderName = $"Logs\\Generation{i}"; // if (Directory.Exists(folderName)) // Directory.Delete(folderName, true); // } // } public static void Main() { var configuration = Configuration.DeserializeFromFile(ConfigFilename); var strategiesGenerator = new StrategiesGenerator(5000); var strategy = strategiesGenerator.GenerateProgram(); var enemyStrategy = strategiesGenerator.GenerateEnemyProgram(); System.IO.File.WriteAllLines("strategy.txt", strategy.commands); var mapGenerator = new MapGenerator(configuration); var map = mapGenerator.GenerateMap(); // SerializeMap(map); var simulator = new BattleSimulator(map, strategy, enemyStrategy, true); var value = simulator.Execute(); Console.WriteLine($"Fitness value: {value}"); }
public void TestInitialize() { mutation = new Mutation(); StrategiesGenerator = new StrategiesGenerator(100); }
public void TestInitialize() { crossover = new Crossover(config); StrategiesGenerator = new StrategiesGenerator(100); }