private async Task ControlAlgorithm() { if (playerPopulation.Count == 0) { Load(); } Random random = new Random(); IterationFitnessList.Clear(); Population population = new Population(StartState.SizeOfPopulation, playerPopulation, random, 11, StartState.Budget, StartState.MutationsNumber, StartState.BestTeamsToCrossOver); ChoosenTeam = population.Evolve(StartState.IterationsNumber, playerPopulation, IterationFitnessList); TeamsList.Clear(); var list = population.Teams.Skip(population.Teams.Count - 20).OrderByDescending(n => n.Fitness); foreach (var team in list) { TeamsList.Add(team); } }
public bool GetTeams(XmlDocument response, int? teamID) { TeamsList teamsList = new TeamsList(); if (teamID != null) { Teams tempTeams = new Teams((int)teamID); if (!tempTeams.RecordExists) { teamsList.Add(new Teams() { ID = Convert.ToInt32(teamID), TeamName = "UNKNOWN" }); } else { teamsList.Add(tempTeams); } } bool newTeamsAdded = false; PlayersList players = new PlayersList(); foreach (XmlNode subRootNode in response.DocumentElement.ChildNodes) { if (subRootNode.Name == "teams") { foreach (XmlNode teamNode in subRootNode) { Teams team = new Teams(); if (teamNode["team_id"] != null) { team.LoadItem(Convert.ToInt32(teamNode["team_id"].InnerText)); if (!team.RecordExists) { team = new Teams(); } } else { team = new Teams(); } if (teamNode["team_id"] != null) team.ID = Convert.ToInt32(teamNode["team_id"].InnerText); if (team.ID == teamID) { Teams tempTeams = teamsList.Find(x => x.ID == teamID); if (tempTeams != null) { teamsList.Remove(tempTeams); } } if (teamNode["name"] != null) team.TeamName = teamNode["name"].InnerText; if (teamNode["tag"] != null) team.Tag = teamNode["tag"].InnerText; if (teamNode["time_created"] != null) team.TimeCreated = teamNode["time_created"].InnerText; if (teamNode["rating"] != null) team.Rating = teamNode["rating"].InnerText; if (teamNode["logo"] != null) team.Logo = teamNode["logo"].InnerText; if (teamNode["logo_sponsor"] != null) team.LogoSponsor = teamNode["logo_sponsor"].InnerText; if (teamNode["country_code"] != null) team.CountryCode = teamNode["country_code"].InnerText; if (teamNode["url"] != null) team.URL = teamNode["url"].InnerText; if (teamNode["games_played_with_current_roster"] != null) team.GamesPlayed = Convert.ToInt32(teamNode["games_played_with_current_roster"].InnerText); if (teamNode["admin_account_id"] != null) team.AdminAccount = Convert.ToInt32(teamNode["admin_account_id"].InnerText); team.LastUpdated = DateTime.Now; if (!QuiteMode) Console.WriteLine("Team ID: " + team.ID + " Name: " + team.TeamName); if (!team.RecordExists) { newTeamsAdded = true; } team.InsertOrUpdate(); TeamPlayersList teamPlayers = new TeamPlayersList(); teamPlayers.GetByTeam(team.ID); //Players addPlayer(players, teamPlayers, team.ID, teamNode, "player_0_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_1_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_2_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_3_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_4_account_id"); // Reserves addPlayer(players, teamPlayers, team.ID, teamNode, "player_5_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_6_account_id"); addPlayer(players, teamPlayers, team.ID, teamNode, "player_7_account_id"); players.UpdateAll(); //leagues; team = null; players.Clear(); teamPlayers.ForEach(x => x.Delete()); } } } if (teamsList.Count > 0) { teamsList.ForEach(x => x.LastUpdated = DateTime.Now); teamsList.UpdateAll(); } if (File.Exists("GetTeamInfo" + (teamID != null ? teamID.ToString() : "") + "(" + DateTime.Now.ToString("ddMMyyyy") + ").xml")) { File.Delete("GetTeamInfo" + (teamID != null ? teamID.ToString() : "") + "(" + DateTime.Now.ToString("ddMMyyyy") + ").xml"); } return newTeamsAdded; }
private void PopulateTeamsList() { TeamsList.Add(Game.AwayTeam); TeamsList.Add(Game.HomeTeam); }