Ejemplo n.º 1
0
        public GeneticData GeneticAlgorithm(
            ISelector selector,
            IMutator mutator,
            ICrosser crosser,
            IEndCondition endCondition,
            GeneticData startPopulation
            )
        {
            const int selectedCount = 4;

            GeneticData best = null;
            var         currentCombinations = new List <GeneticData> {
                startPopulation
            };

            while (!endCondition.IsEnd(currentCombinations, envData))
            {
                var selected = selector.SelectBests(currentCombinations, selectedCount, envData);
                var crossed  = crosser.Cross(selected, envData);
                currentCombinations = mutator.Mutate(crossed, envData);
                best = selector.SelectBests(currentCombinations.Concat(new[] { best }).ToList(), 1, envData).First();
            }

            return(best);
        }
Ejemplo n.º 2
0
 public Game(DrawDeck drawDeck, GameInput input, IEndCondition endCondition)
 {
     DrawDeck = drawDeck;
     Input = input;
     _endCondition = endCondition;
 }