Ejemplo n.º 1
0
        public void PopulationListToDBMapperTest()
        {
            List <Population> pop = new List <Population>()
            {
                new Population(999999, "2131", 0, 0, 1)
            };

            PopulationDB mappedPop = new PopulationDB(pop.First());

            Assert.IsTrue(mappedPop.IdObject == pop.First().IdObject&& mappedPop.Score == pop.First().Score);
            Assert.IsTrue(mappedPop.GenerationNumber == pop.First().GenerationNumber&& mappedPop.MovesCount == pop.First().MovesCount);
        }
Ejemplo n.º 2
0
        public List <Population> SelectionFromCurrentGeneration(int count, List <Population> pop)
        {
            CurrentPop             = Repository.GetPopulationFromDb();
            Repository.MaxIdObject = PopulationDB.GetMaxIdObject();
            Repository.MaxPopGenerationNumber++;
            pop.Clear();
            var top = Repository.GetTopPopulationFromDb();

            foreach (var populationDb in top)
            {
                pop.Add(PopulationMapper.MapPopDbToPop(populationDb, Repository.MaxIdObject, Repository.MaxPopGenerationNumber));
                Repository.MaxIdObject++;
                count--;
            }

            for (int j = 0; j < count / 2; j++)
            {
                var AllPop       = Repository.GetAllPopulation();
                var firstPlayer  = GlobalVariables.Random.Next(0, AllPop.Count);
                var secondPlayer = GlobalVariables.Random.Next(0, AllPop.Count);
                if (AllPop[firstPlayer].Score > AllPop[secondPlayer].Score)
                {
                    pop.Add(PopulationMapper.MapPopDbToPop(AllPop[firstPlayer], Repository.MaxIdObject, Repository.MaxPopGenerationNumber));
                }
                else
                {
                    pop.Add(PopulationMapper.MapPopDbToPop(AllPop[secondPlayer], Repository.MaxIdObject, Repository.MaxPopGenerationNumber));
                }

                Repository.MaxIdObject++;
            }

            for (int i = 0; i < (count / 2); i++)
            {
                var firstPlayer  = GlobalVariables.Random.Next(0, CurrentPop.Count);
                var secondPlayer = GlobalVariables.Random.Next(0, CurrentPop.Count);
                if (CurrentPop[firstPlayer].Score > CurrentPop[secondPlayer].Score)
                {
                    pop.Add(PopulationMapper.MapPopDbToPop(CurrentPop[firstPlayer], Repository.MaxIdObject, Repository.MaxPopGenerationNumber));
                }
                else
                {
                    pop.Add(PopulationMapper.MapPopDbToPop(CurrentPop[secondPlayer], Repository.MaxIdObject, Repository.MaxPopGenerationNumber));
                }

                Repository.MaxIdObject++;
            }
            return(pop);
        }
Ejemplo n.º 3
0
 public Population MapPopDbToPop(PopulationDB pop, int IdObj = 0, int maxPopGenerationNumber = 0)
 {
     return(new Population(IdObj, pop.AiMoves, 0, maxPopGenerationNumber, pop.MovesCount));
 }