public Round GetRound(int idx)
        {
            Round r = new Round();

            if (idx == 0)
            {
                Match match1 = new Match();
                match1.FirstOpponent  = new Team("The Valyrians");
                match1.SecondOpponent = new Team("The Spartans");
                match1.Winner         = new Team("The Valyrians");
                r.AddMatch(match1);


                Match match2 = new Match();
                match2.FirstOpponent  = new Team("The Cretans");
                match2.SecondOpponent = new Team("The Thereans");
                match2.Winner         = new Team("The Thereans");
                r.AddMatch(match2);

                Match match3 = new Match();
                match3.FirstOpponent  = new Team("The Coans");
                match3.SecondOpponent = new Team("The Cnideans");
                match3.Winner         = new Team("The Coans");
                r.AddMatch(match3);

                Match match4 = new Match();
                match4.FirstOpponent  = new Team("The Megareans");
                match4.SecondOpponent = new Team("The Corinthians");
                match4.Winner         = new Team("The Corinthians");
                r.AddMatch(match4);
            }
            else if (idx == 1)
            {
                Match match1 = new Match();
                match1.FirstOpponent  = new Team("The Valyrians");
                match1.SecondOpponent = new Team("The Thereans");
                match1.Winner         = new Team("The Valyrians");
                r.AddMatch(match1);

                Match match2 = new Match();
                match2.FirstOpponent  = new Team("The Coans");
                match2.SecondOpponent = new Team("The Corinthians");
                match2.Winner         = new Team("The Coans");
                r.AddMatch(match2);
            }
            else if (idx == 2)
            {
                Match match1 = new Match();
                match1.FirstOpponent  = new Team("The Valyrians");
                match1.SecondOpponent = new Team("The Coans");
                match1.Winner         = new Team("The Coans");
                r.AddMatch(match1);
            }


            return(r);
        }
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            Tournament t             = tournamentRepo.GetTournament(tournamentName);
            int        numberOfRound = t.GetNumberOfRounds();

            if (numberOfRound == 0)
            {
                List <Team> teams = t.GetTeams();
            }
            else
            {
                Round lastRound       = t.GetRound(numberOfRound - 1);
                bool  isRoundFinished = lastRound.IsRoundFinished();

                if (isRoundFinished == true)
                {
                    List <Team> teams = lastRound.GetWinningTeams();
                    if (teams.Count >= 2)
                    {
                        var rnd = new Random();
                        rnd.NextDouble();
                        Dictionary <Team, double> RandomList = new Dictionary <Team, double>();

                        foreach (Team team in lastRound.GetWinningTeams())
                        {
                            RandomList.Add(team, rnd.NextDouble());
                        }
                        RandomList.OrderByDescending(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
                        List <Team> randomList = RandomList.Keys.ToList();

                        Round newRound = new Round();
                        if (teams.Count % 2 == 1)
                        {
                            Team newFreeRider = randomList.Min();
                            Team oldFreeRider = newRound.GetFreeRider();
                            do
                            {
                                newFreeRider = randomList.Min();

                                randomList.Remove(newFreeRider);
                            }while (oldFreeRider == newFreeRider);

                            newRound.NewFreeRider = newFreeRider;
                        }
                        int noMatches = teams.Count / 2;

                        for (int i = 1; i <= noMatches; i++)
                        {
                            Match match = new Match();
                            foreach (Team team in randomList)
                            {
                                Team first;
                                Team second;



                                first = team;
                                randomList.Remove(team);
                                second = team;
                                randomList.Remove(team);
                                match.FirstOpponent  = first;
                                match.SecondOpponent = second;
                                newRound.AddMatch(match);
                            }
                        }

                        t.addRound(newRound);

                        Console.WriteLine("Ny runde tilføjet");
                        Console.ReadKey();
                    }
                    else
                    {
                        t.SetStatusFinished(true);
                    }
                    Console.WriteLine("Turneringen er overstået");
                    Console.ReadKey();
                }
            }
        }
Beispiel #3
0
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            Tournament  CurrentTournament = tournamentRepository.GetTournament(tournamentName);
            int         NoR = CurrentTournament.GetNumberOfRounds();
            bool        isRoundFinished;
            List <Team> teams     = new List <Team>();
            Round       LastRound = new Round();

            if (NoR == 0)
            {
                teams = CurrentTournament.GetTeams();


                if (teams.Count > 1)
                {
                    //shuffle
                    int n = teams.Count;
                    while (n > 1)
                    {
                        Random rng = new Random();
                        n--;
                        int  k    = rng.Next(n + 1);
                        Team team = teams[k];
                        teams[k] = teams[n];
                        teams[n] = team;
                    }
                    //end of shuffle
                    Round NewRound = new Round();
                    if (teams.Count % 2 == 1)
                    {
                        Team newFreeRider = new Team("newFreeRider");
                        newFreeRider = teams[teams.Count - 1];
                        teams.Remove(newFreeRider);
                        NewRound.AddFreeRider(newFreeRider);
                    }

                    while (teams.Count > 0)
                    {
                        Match match = new Match();
                        Team  first = teams[0];
                        teams.Remove(teams[0]);
                        Team second = teams[0];
                        teams.Remove(teams[0]);

                        match.FirstOpponent  = first;
                        match.SecondOpponent = second;
                        NewRound.AddMatch(match);
                    }
                    CurrentTournament.AddRound(NewRound);
                    Console.WriteLine("New round: " + (NoR + 1) + " was added to " + CurrentTournament.Name + "\n" + "with the following matches");
                    foreach (Match match in NewRound.GetMatches())
                    {
                        Console.WriteLine(match.FirstOpponent.Name + " VS " + match.SecondOpponent.Name);
                    }
                }
            }
            else
            {
                LastRound       = CurrentTournament.GetRound(NoR - 1);
                isRoundFinished = LastRound.IsMatchesFinished();
                if (isRoundFinished)
                {
                    teams = LastRound.GetWinningTeams();
                    if (teams.Count > 1)
                    {
                        //shuffle
                        int n = teams.Count;
                        while (n > 1)
                        {
                            Random rng = new Random();
                            n--;
                            int  k    = rng.Next(n + 1);
                            Team team = teams[k];
                            teams[k] = teams[n];
                            teams[n] = team;
                        }
                        //end of shuffle

                        Round NewRound = new Round();

                        if (teams.Count % 2 == 1)
                        {
                            Team oldFreeRider = LastRound.GetFreeRider();
                            Team newFreeRider = new Team("newFreeRider");
                            for (int x = 0; oldFreeRider != newFreeRider; x++)
                            {
                                newFreeRider = teams[x];
                            }
                            teams.Remove(newFreeRider);
                            teams.Add(oldFreeRider);
                            NewRound.AddFreeRider(newFreeRider);
                        }

                        for (int i = 0; i < teams.Count / 2; i++)
                        {
                            Match match = new Match();
                            Team  first = teams[0];
                            teams.Remove(teams[0]);
                            Team second = teams[0];
                            teams.Remove(teams[0]);

                            match.FirstOpponent  = first;
                            match.SecondOpponent = second;
                            NewRound.AddMatch(match);
                        }
                        CurrentTournament.AddRound(NewRound);
                        Console.WriteLine("New round: " + (NoR + 1) + " was added to " + CurrentTournament.Name + "\n" + "with the following matches");
                        foreach (Match match in NewRound.GetMatches())
                        {
                            Console.WriteLine(match.FirstOpponent.Name + " VS " + match.SecondOpponent.Name);
                        }
                    }
                    else
                    {
                        CurrentTournament.SetStatus("Finished");
                    }
                }
                else
                {
                    Console.WriteLine("Error round not finished");
                }
            }
        }
Beispiel #4
0
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            {
                Tournament tournament = tournamentRepo.GetTournament(tournamentName);

                int numberOfRound = tournament.GetNumberOfRounds();
                if (numberOfRound == 0)

                {
                    List <Team> teams = tournament.GetTeams();
                }
                else
                {
                    Round lastRound       = tournament.GetRound(numberOfRound - 1);
                    bool  isRoundFinished = lastRound.IsMatchesFinished();
                    if (isRoundFinished)
                    {
                        List <Team> teams = lastRound.GetWinningTeams();
                        if (teams.Count >= 2)
                        {
                            teams = ShuffleList(teams);                       // iFixit later
                            Round newRound = new Round();
                            if (teams.Count % 2 == 1)                         // If uneven number of teams
                            {
                                Team oldFreeRider = lastRound.GetFreeRider(); // Fix later
                                Team newFreeRider = teams[0];
                                while (newFreeRider == oldFreeRider)
                                {
                                    newFreeRider = teams[1];
                                }
                                teams.Remove(newFreeRider);
                                newRound.Add(newFreeRider);
                            }
                            while (teams.Count > 0) // Så længe der er én eller flere hold i teams listen
                            {
                                Match match = new Match();
                                match.FirstOpponent = teams[0];
                                teams.RemoveAt(0);
                                match.SecondOpponent = teams[0];
                                teams.RemoveAt(0);
                                newRound.AddMatch(match);
                            }
                            tournament.Add(newRound);
                        }
                        else
                        {
                            tournament.SetStatus("finished");//SetSatus metode fix later
                        }
                    }
                    else
                    {
                        Console.WriteLine("Round is not finished");
                    }
                }
            }

            //Tournament t = tournamentRepo.GetTournament(tournamentName);
            //if(t == null)
            //{
            //    Console.WriteLine("Turnering fandtes ikke");
            //    return;
            //}
            //int numberOfRounds = t.GetNumberOfRounds();

            //List<Team> teams = new List<Team>();
            //Round r = new Round();
            //bool isRoundFinished = r.IsMatchesFinished();
            //for(int i = 0;i < numberOfRounds;i++)
            //{
            //    if(i == 0)
            //    {
            //        t.GetRound(i);
            //        teams = t.GetTeams();
            //    }
            //    if(isRoundFinished)
            //    {
            //        teams = r.GetWinningTeams();
            //        Random rnd = new Random();
            //        if(teams.Count >= 2)
            //        {
            //            var result = teams.OrderBy(team => rnd.Next());
            //        }
            //    }
            //}

            //////List<Team> teams = new List<Team>();
            //Round r = new Round();
            //bool isRoundFinished = r.IsMatchesFinished();
            //if(numberOfRounds == 3)
            //{
            //    //teams = t.GetTeams();
            //    r = t.GetRound(numberOfRounds - 1);

            //}
            //else
            //{
            //    r = t.GetRound(numberOfRounds - 1);

            //}

            //if(isRoundFinished)
            //{
            //    teams = r.GetWinningTeams();
            //    Random rnd = new Random();
            //    if(teams.Count >= 2)
            //    {
            //        var result = teams.OrderBy(team => rnd.Next());
            //    }
            //}
        }