Beispiel #1
0
        //Возвращает случайный родительский геном, один из двух
        public static Genomes GetRandomParent(Genomes Parent_1, Genomes Parent_2)
        {
            if (Randomizer.NextDouble() > 0.5)
            {
                return(Parent_1);
            }

            else
            {
                return(Parent_2);
            }
        }
Beispiel #2
0
        //Скрещиваем два старых генома для создания нового
        private static Genomes MakeChild(Genomes Parent1, Genomes Parent2, GameState State)
        {
            //Создаем новый экземпляр класса Genomes, заполняем его значениями, зависящими от родительских геномов
            Genomes Child = new Genomes();

            Child.ID = Randomizer.NextDouble();
            Child.NumberOfRowsCleared   = GetRandomParent(Parent1, Parent2).NumberOfRowsCleared;
            Child.WeightedHeight        = GetRandomParent(Parent1, Parent2).WeightedHeight;
            Child.CumulativeHeight      = GetRandomParent(Parent1, Parent2).CumulativeHeight;
            Child.RelativeHeight        = GetRandomParent(Parent1, Parent2).RelativeHeight;
            Child.NumberOfMissingBlocks = GetRandomParent(Parent1, Parent2).NumberOfMissingBlocks;
            Child.Roughness             = GetRandomParent(Parent1, Parent2).Roughness;
            Child.GenomeRating          = -1;



            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.WeightedHeight += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }

            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.CumulativeHeight += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }

            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.RelativeHeight += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }

            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.NumberOfMissingBlocks += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }

            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.NumberOfRowsCleared += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }

            if (Randomizer.NextDouble() < State.MutationRate)
            {
                Child.Roughness += Randomizer.NextDouble() * State.MutationStep * 2 - State.MutationStep;
            }


            return(Child);
        }
Beispiel #3
0
        public static void CreateFirstPopulation(GameState State)
        {
            //Мы заполняем нашу популяцию первоначальными геномами, генерируя их в конструкторе
            for (int i = 0; i < State.SizeOfPopulation; i++)
            {
                Genomes Genome = new Genomes();
                Genome.ID = Randomizer.NextDouble();
                Genome.NumberOfRowsCleared   = Randomizer.NextDouble() - State.MutationRate;
                Genome.WeightedHeight        = Randomizer.NextDouble() - State.MutationRate;
                Genome.CumulativeHeight      = Randomizer.NextDouble() - State.MutationRate;
                Genome.RelativeHeight        = Randomizer.NextDouble() - State.MutationRate;
                Genome.NumberOfMissingBlocks = Randomizer.NextDouble() * State.MutationRate;
                Genome.Roughness             = Randomizer.NextDouble() - State.MutationRate;

                State.ListOfGenomes.Add(Genome);
            }

            //Оцениваем первый геном
            EvaluateNextGenome(State);
        }
Beispiel #4
0
        //Загружает оптимальный геном
        public static void LoadOptimalPopulation(GameState State)
        {
            for (int i = 0; i < State.SizeOfPopulation; i++)
            {
                Genomes Genome = new Genomes();

                Genome.ID = 1;

                Genome.NumberOfRowsCleared   = 0.22568649650722883;
                Genome.WeightedHeight        = 0.08679520494876472;
                Genome.CumulativeHeight      = 0.6152727732730796;
                Genome.RelativeHeight        = 0.15842464424735841;
                Genome.NumberOfMissingBlocks = 0.15452215909537684;
                Genome.Roughness             = 0.021586109522043928;
                Genome.GenomeRating          = 100000;

                State.ListOfGenomes.Add(Genome);
            }

            EvaluateNextGenome(State);
        }