コード例 #1
0
 public bool CanGenerateStartingPopulation()
 {
     using (var db = new DbContextRunningCube())
     {
         return(db.PopulationData.Any()? false : true);
     }
 }
コード例 #2
0
        public List <Enemy> GetEnemiesFromDb()
        {
            DbContextRunningCube dbContext = new DbContextRunningCube();
            List <EnemyDB>       enemyData = dbContext.EnemiesData.ToList();

            return(Mapper.MapDbToObj(enemyData));
        }
コード例 #3
0
 public void SaveGeneratedEnemies(List <EnemyDB> enemies)
 {
     using (var db = new DbContextRunningCube())
     {
         db.EnemiesData.AddRange(enemies);
         db.SaveChanges();
     }
 }
コード例 #4
0
 public void SaveParameters(double mutaionPercent, double speedOfame, int amoutOfPopulation)
 {
     using (var db = new DbContextRunningCube())
     {
         db.Parameters.Add(new ParametersDB(mutaionPercent, speedOfame
                                            , amoutOfPopulation));
         db.SaveChanges();
     }
 }
コード例 #5
0
        public List <PopulationDB> GetTopPopulationFromDb()
        {
            using (var dbContext = new DbContextRunningCube())
            {
                var list = dbContext.PopulationData.Where(x => x.Score != 0).OrderByDescending(x => x.Score).Take(5);

                return(list.ToList());
            }
        }
コード例 #6
0
        public List <PopulationDB> GetAllPopulation()
        {
            List <PopulationDB> pop = new List <PopulationDB>();

            using (var dbContext = new DbContextRunningCube())
            {
                var lit = dbContext.PopulationData.ToList();
                return(lit);
            }
        }
コード例 #7
0
 public void ClearEnemies()
 {
     using (var db = new DbContextRunningCube())
     {
         if (db.Parameters.Any())
         {
             db.Database.ExecuteSqlCommand("TRUNCATE TABLE [ParametersDBs]");
             db.SaveChanges();
         }
     }
 }
コード例 #8
0
        public void UpdateScoreForCurrentPopulation(int playerAiCounter, int idObj, int score)
        {
            using (var dbContext = new DbContextRunningCube())
            {
                var population = dbContext.PopulationData.FirstOrDefault(x => x.IdObject == idObj);

                population.Score      = score;
                population.MovesCount = playerAiCounter;
                dbContext.SaveChanges();
            }
        }
コード例 #9
0
        public List <PopulationDB> GetPopulationFromDb()
        {
            List <PopulationDB> pop = new List <PopulationDB>();

            using (var dbContext = new DbContextRunningCube())
            {
                MaxPopGenerationNumber = dbContext.PopulationData.Max(x => x.GenerationNumber);
                pop = dbContext.PopulationData.Where(x => x.GenerationNumber == MaxPopGenerationNumber).ToList();
                return(pop);
            }
        }
コード例 #10
0
 public ParametersDB GetParameters()
 {
     using (var dbContext = new DbContextRunningCube())
     {
         if (dbContext.Parameters.Any())
         {
             var parameters = dbContext.Parameters.ToList();
             return(parameters.OrderByDescending(x => x.IdObject).First());
         }
         return(new ParametersDB());
     }
 }
コード例 #11
0
        public void SaveTrainedPopulation(int playerAiCounter, int currentPopulationIdObject, int scoreSpriteScore)
        {
            using (var dbContext = new DbContextRunningCube())
            {
                var population = dbContext.PopulationData.FirstOrDefault(x => x.IdObject == currentPopulationIdObject);

                population.Score      = scoreSpriteScore;
                population.MovesCount = playerAiCounter;
                population.Trained    = true;
                dbContext.SaveChanges();
            }
        }
コード例 #12
0
        public PopulationDB GetBestPopulation()
        {
            PopulationDB xd;

            using (var dbContext = new DbContextRunningCube())
            {
                var list = dbContext.PopulationData.OrderByDescending(x => x.MovesCount);
                xd = list.FirstOrDefault();
            }

            return(xd);
        }
コード例 #13
0
        public string GenerateStartPopulation(IEnumerable <PopulationDB> players)
        {
            var result = "Population 0 is already generated!";

            using (var db = new DbContextRunningCube())
            {
                if (!db.PopulationData.Any())
                {
                    db.PopulationData.AddRange(players);
                    db.SaveChanges();

                    result = "Generated!";
                }
            }
            return(result);
        }