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> team = lastRound.GetWinningTeams(); if (team.Count >= 2) { var rnd = new Random(); rnd.NextDouble(); Dictionary <Team, double> RandomList = new Dictionary <Team, double>(); foreach (Team item in lastRound.GetWinningTeams()) { RandomList.Add(item, rnd.NextDouble()); } RandomList.OrderByDescending(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value); Round newRound = new Round(); if (team.Count % 2 == 1) { int oldFreeRider = newRound.GetFreeRider(); } } } } }
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"); } } }
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(); } } }
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()); // } //} }