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)); }
public void GetPanmixia_returns_valid_strategy() { var initialStrategies = new List <Strategy>(); for (int i = 0; i < config.PopulationSize; i++) { initialStrategies.Add(StrategiesGenerator.GenerateProgram()); } var strategies = crossover.GetPanmixia(initialStrategies); foreach (var strategy in strategies) { Assert.IsTrue(StrategiesGenerator.CheckProgram(strategy.commands)); } }
public void GetMutatedSpecies_returns_valid_strategy() { var initialStrategies = new List <Strategy>(); for (int i = 0; i < config.PopulationSize; i++) { initialStrategies.Add(StrategiesGenerator.GenerateProgram()); } var strategies = mutation.GetMutatedSpecies(initialStrategies, 10); foreach (var strategy in strategies) { Assert.IsTrue(StrategiesGenerator.CheckProgram(strategy.commands)); } }
// 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}"); }