Exemple #1
0
        public void CrossoverSpecies_should_return_valid_strategy()
        {
            var algo1 = new Strategy(Enumerable.
                                     Range(0, config.MaxStrategySize)
                                     .Select(i => "Forward").ToList());
            var algo2 = new Strategy(Enumerable.
                                     Range(0, config.MaxStrategySize)
                                     .Select(i => "Shoot").ToList());
            var result = StrategyCrossoverMethods.Crossover(algo1, algo2, config.MaxStrategySize);

            Assert.IsTrue(StrategiesGenerator.CheckProgram(result.commands));
        }
        public void GenerateRandomProgram_should_return_working_program()
        {
            var generator = new StrategiesGenerator(30);
            var program   = generator.GenerateProgram();

            Assert.IsTrue(StrategiesGenerator.CheckProgram(program.commands));
        }
Exemple #3
0
        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 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));
            }
        }