public bool CanGenerateStartingPopulation() { using (var db = new DbContextRunningCube()) { return(db.PopulationData.Any()? false : true); } }
public List <Enemy> GetEnemiesFromDb() { DbContextRunningCube dbContext = new DbContextRunningCube(); List <EnemyDB> enemyData = dbContext.EnemiesData.ToList(); return(Mapper.MapDbToObj(enemyData)); }
public void SaveGeneratedEnemies(List <EnemyDB> enemies) { using (var db = new DbContextRunningCube()) { db.EnemiesData.AddRange(enemies); db.SaveChanges(); } }
public void SaveParameters(double mutaionPercent, double speedOfame, int amoutOfPopulation) { using (var db = new DbContextRunningCube()) { db.Parameters.Add(new ParametersDB(mutaionPercent, speedOfame , amoutOfPopulation)); db.SaveChanges(); } }
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()); } }
public List <PopulationDB> GetAllPopulation() { List <PopulationDB> pop = new List <PopulationDB>(); using (var dbContext = new DbContextRunningCube()) { var lit = dbContext.PopulationData.ToList(); return(lit); } }
public void ClearEnemies() { using (var db = new DbContextRunningCube()) { if (db.Parameters.Any()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE [ParametersDBs]"); db.SaveChanges(); } } }
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(); } }
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); } }
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()); } }
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(); } }
public PopulationDB GetBestPopulation() { PopulationDB xd; using (var dbContext = new DbContextRunningCube()) { var list = dbContext.PopulationData.OrderByDescending(x => x.MovesCount); xd = list.FirstOrDefault(); } return(xd); }
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); }