Exemplo n.º 1
0
        /// <summary>
        /// Get list of fixtures when the precedent round is a group round and no random drawing is performed
        /// TODO: Currently only work when there is two qualified teams by group
        /// </summary>
        /// <param name="round">The round to draw</param>
        /// <param name="previousRound">The previous round</param>
        /// <returns></returns>
        public static List <Match> DrawNoRandomDrawing(KnockoutRound round, GroupsRound previousRound)
        {
            //We assume teams are added in round in the order of ranking and group
            List <Match> res = new List <Match>();

            RoundProgrammation programmation = round.programmation;

            for (int i = 0; i < round.clubs.Count / 2; i++)
            {
                Club home = i < round.clubs.Count / 4 ? round.clubs[i * 4] : round.clubs[((i - (round.clubs.Count / 4)) * 4) + 2];
                Club away = i < round.clubs.Count / 4 ? round.clubs[(i * 4) + 3] : round.clubs[((i - (round.clubs.Count / 4)) * 4) + 1];

                DateTime day = GetRoundProgrammationDate(round, programmation);

                if (round.rules.Contains(Rule.AtHomeIfTwoLevelDifference))
                {
                    Club[] switchedTeams = SwitchTeams(home, away);
                    home = switchedTeams[0];
                    away = switchedTeams[1];
                }
                res.Add(new Match(home, away, day, !round.twoLegs));
            }

            TVSchedule(res, round.programmation.tvScheduling, 0);
            if (round.twoLegs)
            {
                CreateSecondLegKnockOutRound(res, round, programmation);
            }

            return(res);
        }
Exemplo n.º 2
0
        public override void Initialise()
        {
            if (!Tournament.IsInternational())
            {
                AddTeamsToRecover();
            }
            //If it's an international tournament (national teams or continental cup eg), we add all teams to recover for all rounds now because ranking can fluctuate after and the same team could be selected for 2 differents rounds
            else if (Tournament.rounds[0] == this)
            {
                foreach (Round r in Tournament.rounds)
                {
                    r.AddTeamsToRecover();
                }
            }

            if (_noRandomDrawing)
            {
                Round previousRound = Tournament.rounds[Tournament.rounds.IndexOf(this) - 1];
                if (previousRound as KnockoutRound != null)
                {
                    KnockoutRound previousRoundKO = previousRound as KnockoutRound;
                    _matches = Calendar.DrawNoRandomDrawing(this, previousRoundKO);
                }
                else if (previousRound as GroupsRound != null)
                {
                    GroupsRound previousRoundG = previousRound as GroupsRound;
                    _matches = Calendar.DrawNoRandomDrawing(this, previousRoundG);
                }
            }
            else
            {
                _matches = Calendar.Draw(this);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The drawing for direct-elimination round
        /// </summary>
        /// <param name="round">The round to draw</param>
        /// <returns>The list of games of this round</returns>
        public static List <Match> Draw(KnockoutRound round)
        {
            List <Match> res = new List <Match>();


            List <Club>[] hats = new List <Club>[] { new List <Club>(), new List <Club>() };

            if (round.randomDrawingMethod == RandomDrawingMethod.Ranking)
            {
                GroupsRound   previousRound       = round.Tournament.rounds[round.Tournament.rounds.IndexOf(round) - 1] as GroupsRound;
                List <Club>[] clubsByRankPosition = new List <Club> [previousRound.maxClubsInGroup];
                List <Club>   allClubs            = new List <Club>();

                for (int i = 0; i < clubsByRankPosition.Length; i++)
                {
                    clubsByRankPosition[i] = new List <Club>();
                }

                for (int i = 0; i < previousRound.groupsCount; i++)
                {
                    List <Club> ranking = previousRound.Ranking(i);
                    for (int j = 0; j < ranking.Count; j++)
                    {
                        clubsByRankPosition[j].Add(ranking[j]);
                    }
                }

                for (int i = 0; i < clubsByRankPosition.Length; i++)
                {
                    clubsByRankPosition[i].Sort(new ClubRankingComparator(previousRound.matches));
                    allClubs.AddRange(clubsByRankPosition[i]);
                }

                allClubs = new List <Club>(allClubs.GetRange(0, round.clubs.Count));
                hats[0].AddRange(allClubs.GetRange(0, round.clubs.Count / 2));
                hats[1].AddRange(allClubs.GetRange(round.clubs.Count / 2, round.clubs.Count / 2));
            }
            else if (round.randomDrawingMethod == RandomDrawingMethod.Coefficient)
            {
                List <Club> allClubs = new List <Club>(round.clubs);
                allClubs.Sort(new ClubComparator(ClubAttribute.CONTINENTAL_COEFFICIENT));
                hats[0].AddRange(allClubs.GetRange(0, round.clubs.Count / 2));
                hats[1].AddRange(allClubs.GetRange(round.clubs.Count / 2, round.clubs.Count / 2));
            }
            else if (round.randomDrawingMethod == RandomDrawingMethod.Geographic)
            {
                List <Club> allClubs             = new List <Club>(round.clubs);
                int         currentClubsByGroups = allClubs.Count;
                int         groupsNumber         = 1;
                while ((currentClubsByGroups / 2) % 2 == 0 && (allClubs.Count / groupsNumber) > 20)
                {
                    currentClubsByGroups /= 2;
                    groupsNumber         *= 2;
                }
                KMeansClustering kmeans = new KMeansClustering(allClubs, groupsNumber);
                hats = kmeans.CreateClusters();
            }
            //Random
            else
            {
                List <Club> allClubs = new List <Club>(round.clubs);
                allClubs.Shuffle();
                for (int i = 0; i < allClubs.Count; i++)
                {
                    hats[i < allClubs.Count / 2 ? 0 : 1].Add(allClubs[i]);
                }
            }


            RoundProgrammation programmation = round.programmation;
            int currentGeographicHat         = 0;

            for (int i = 0; i < round.clubs.Count / 2; i++)
            {
                Club home;
                Club away;
                if (round.randomDrawingMethod != RandomDrawingMethod.Geographic)
                {
                    int hat = Session.Instance.Random(0, 2);
                    home = DrawClub(hats[hat]);
                    away = DrawClub(hats[hat == 1 ? 0 : 1]);
                }
                else
                {
                    if (hats[currentGeographicHat].Count < 2)
                    {
                        currentGeographicHat++;
                    }
                    home = DrawClub(hats[currentGeographicHat]);
                    away = DrawClub(hats[currentGeographicHat]);
                }

                DateTime day = GetRoundProgrammationDate(round, programmation);

                if (round.rules.Contains(Rule.AtHomeIfTwoLevelDifference))
                {
                    Club[] switchedTeams = SwitchTeams(home, away);
                    home = switchedTeams[0];
                    away = switchedTeams[1];
                }
                res.Add(new Match(home, away, day, !round.twoLegs));
            }

            TVSchedule(res, round.programmation.tvScheduling, 0);
            if (round.twoLegs)
            {
                CreateSecondLegKnockOutRound(res, round, programmation);
            }
            return(res);
        }
 public RandomDrawingGeographic(GroupsRound tour)
 {
     _round = tour;
 }
Exemplo n.º 5
0
 public RandomDrawingLevel(GroupsRound tour, ClubAttribute attribute)
 {
     _round     = tour;
     _attribute = attribute;
 }