public void ScheduleNewRound(string tournamentName, bool printNewMatches = true) { TournamentRepo tr = new TournamentRepo(); Tournament t = tr.GetTournament(tournamentName); int numberOfRounds = t.GetNumberOfRounds() - 1; List <Team> teams = new List <Team>(); Team oldFreeRider; Round lastRound; lastRound = t.GetRound(numberOfRounds - 1); if (numberOfRounds == 0) { teams = t.GetTeams(); } else { bool isRoundFinished = lastRound.IsRoundFinished(); if (isRoundFinished) { teams = lastRound.GetWinningTeams(); } else { Console.WriteLine("Runden er endnu ikke afsluttet"); } } if (teams.Count > 1) { //fundet på stackoverflow skal undersøges nærmere. Random rng = new Random(); int n = teams.Count; while (n > 1) { n--; int k = rng.Next(n + 1); Team value = teams[k]; teams[k] = teams[n]; teams[n] = value; } Round newRound = new Round(); if (teams.Count % 2 == 1) { oldFreeRider = lastRound.GetFreeRider(); Team newFreeRider; //freerider holdet springer runden over int i = 0; do { newFreeRider = teams[i]; i++; } while (oldFreeRider.Equals(teams[i])); teams.Remove(newFreeRider); newRound.Add(newFreeRider); } int numberOfMatches = teams.Count / 2; for (int i = 0; i < numberOfMatches; i++) { Match newMatch = new Match(); Team first = teams[0]; teams.Remove(teams[0]); Team second = teams[0]; teams.Remove(teams[0]); newMatch.FirstOpponent = first; newMatch.SecondOpponent = second; newRound.Add(newMatch); } // Jesper har tilføjet herfra t.Add(newRound); if (printNewMatches) { Console.Clear(); Console.WriteLine("Kommende Runde:"); Console.WriteLine("---------------"); List <Match> matches = newRound.GetMatches(); int i = 1; foreach (Match match in matches) { Console.WriteLine(i + ". " + match.FirstOpponent.Name + " vs. " + match.SecondOpponent.Name); i++; } Console.ReadKey(); } } else { // SetStatusFinished() er tilføjet til tournament-klassen t.SetStatusFinished(); Console.WriteLine("Turneringen " + t.Name + " er afsluttet"); Console.ReadKey(); Console.Clear(); } // Jesper out. }
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()); // } //} }