//private const string PathResults = "../../results";

        public FormationResult GetResults()
        {
            var result = new FormationResult();

            DirectoryInfo d = new DirectoryInfo(PathResults);

            foreach (var file in d.GetFiles("*.json"))
            {
                try
                {
                    using (StreamReader sr = new StreamReader(PathResults + "/" + file.Name))
                    {
                        string line = sr.ReadToEnd();
                        result = JsonConvert.DeserializeObject <FormationResult>(line);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("The file results could not be read:");
                    Console.WriteLine(e.Message);
                }
            }

            return(result);
        }
示例#2
0
        public void BuildPerfectSquad(Formation formation, List <string> permutations)
        {
            this.result    = new FormationResult();
            this.formation = formation;
            // this.GetFromPlayersFromEa();
            this.SetPlayersToMemory();

            //EDMAR - ALL PLAYERS MUST COME FROM ABOVE
            //this.players = this.players.Where(p => p.Club != "Icons" && !p.IsSpecialType && p.Color == "rare_gold" && p.Rating > 78 && p.League.ToLower().StartsWith("pre")).ToList();
            this.players = this.players.Where(p => p.Club != "Icons" && !p.IsSpecialType && p.Color == "rare_gold" && p.Rating > 78 && p.Rating < 99).ToList();

            // Removing players that have positions that are not in this formation
            var allPositions = this.formation.Positions.Select(pos => pos.PositionEnum).Distinct().ToList();

            this.players = this.players.Where(pl => allPositions.Contains(pl.Position)).ToList();

            this.players = this.players.OrderByDescending(p => p.Rating).ToList();

            this.BuildSquad(permutations);
        }