Ejemplo n.º 1
0
        public void FillDivisions()
        {
            var latitudalTeams = Teams.OrderBy(team => team.City.Latitude).ToList();

            PutTeamsInTheCorners(latitudalTeams);

            while (!Enumerable.SequenceEqual(Divisions.Select(division => division.Teams.Count).ToArray(), _maxDivisionTeamCounts))
            {
                (Team team, Division division)bestPair = (null, null);
                var furthestNeighbour = double.MinValue;

                for (var i = 0; i < latitudalTeams.Count; i++)
                {
                    var team = latitudalTeams[i];
                    (Team team, Division division)pair = (null, null);

                    if (Divisions.Any(division => division.Teams.Contains(team)))
                    {
                        continue;
                    }

                    var closestDistance = double.MaxValue;

                    for (var j = 0; j < Divisions.Count; j++)
                    {
                        var division        = Divisions[j];
                        var divisionHasRoom = division.Teams.Count < _maxDivisionTeamCounts[j];
                        var squaredDistance = division.SquaredDistanceTo(team.City);

                        if (divisionHasRoom && squaredDistance < closestDistance)
                        {
                            closestDistance = squaredDistance;
                            pair            = (team, division);
                        }
                    }

                    if (closestDistance > furthestNeighbour)
                    {
                        furthestNeighbour = closestDistance;
                        bestPair          = pair;
                    }
                }

                bestPair.division.Teams.Add(bestPair.team);
                Divisions = Divisions.OrderBy(division => division.Teams.Count).ToList();
            }
        }
Ejemplo n.º 2
0
        public static bool ParseFromArgs(string[] args)
        {
            if (!args.Any())
            {
                ShowHelp = true;
            }

            try
            {
                var rem = OptionSet.Parse(args);

                if (!Divisions.Any())
                {
                    Divisions.Add(new List <int> {
                        4
                    });
                }

                if (rem.Any())
                {
                    throw new OptionException();
                }
            }
            catch (Exception ex) when(ex is OptionException || ex is InvalidOperationException)
            {
                Console.WriteLine("Invalid Arguments.");
                PrintHelp();
                Environment.Exit(1);
            }

            if (ShowHelp)
            {
                PrintHelp();
                return(false);
            }

            return(true);
        }