public void ShowScore(string tournamentName)
        {
            int        winnerPoint = 0;
            Tournament t           = tournamentRepo.GetTournament(tournamentName);

            for (int i = 0; i < t.GetNumberOfRounds(); i++)
            {
                Round       currentRound = t.GetRound(i);
                List <Team> winningTeams = currentRound.GetWinningTeams();
                //currentRound.GetWinningTeams().winnerPoint++;

                // Console.WriteLine(winningTeams);
                foreach (Team winningTeam in winningTeams)
                {
                    Console.WriteLine(winningTeam.name);
                }
            }
            //Dictionary<string, int> teamDictionary = new Dictionary<string, int>();
            //{
            //    foreach ( var item in currentRound.GetwTeams())
            //    {
            //        teamDictionary.Add(item, winnerPoint);
            //    }
            //}
        }
Beispiel #2
0
        public void ShowScore(string tournamentName)
        {
            Tournament t = tournamentRepo.GetTournament(tournamentName);

            if (t == null)
            {
                Console.WriteLine("Turnering fandtes ikke");
                return;
            }
            Dictionary <string, int> scoreList = new Dictionary <string, int>();

            for (int i = 0; i < t.GetNumberOfRounds(); i++)
            {
                Round       currentRound = t.GetRound(i);
                List <Team> winningTeams = currentRound.GetWinningTeams();
                foreach (Team winningTeam in winningTeams)
                {
                    int updateNumber = 1;
                    if (scoreList.ContainsKey(winningTeam.Name))
                    {
                        if (scoreList.TryGetValue(winningTeam.Name, out int number))
                        {
                            updateNumber = number + 1;
                            scoreList.Remove(winningTeam.Name);
                        }
                    }
                    scoreList.Add(winningTeam.Name, updateNumber);
                }
            }
            Console.WriteLine();
            Console.WriteLine("Status in round ");
            //sort scorelist
            var sortedList = scoreList.OrderByDescending(x => x.Value);

            foreach (var key in sortedList)
            {
                Console.WriteLine("Team: {0}: Won : {1}", key.Key, key.Value);
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("done");

            /*
             * TODO: Calculate for each team how many times they have won
             * Sort based on number of matches won (descending)
             */
            //Console.WriteLine("Implement this method!");
        }
Beispiel #3
0
        public void ShowScore(string tournamentName)
        {
            Tournament  CurrentTournament = tournamentRepository.GetTournament(tournamentName);
            List <Team> teams             = CurrentTournament.GetTeams();
            List <Team> Tsorted           = new List <Team>();

            int[] score   = new int[teams.Count];
            int[] Ssorted = new int[teams.Count];

            //creation of score array
            for (int i = 0; i < CurrentTournament.GetNumberOfRounds(); i++)
            {
                Round CurrentRound = CurrentTournament.GetRound(i);
                for (int y = 0; y < teams.Count; y++)
                {
                    foreach (Team t in CurrentRound.GetWinningTeams())
                    {
                        if (t != null)
                        {
                            if (teams[y].Name == t.Name)
                            {
                                score[y]++;
                            }
                        }
                    }
                }
            }

            //sorting
            for (int i = 0; i < teams.Count; i++)
            {
                int index = Array.IndexOf(score, score.Max());
                Tsorted.Add(teams[index]);
                Ssorted[i]   = score[index];
                score[index] = -1;
            }

            //print
            for (int i = 0; i < teams.Count; i++)
            {
                Console.WriteLine("Name: " + Tsorted[i].Name + " Score: " + Ssorted[i] + "\n");
            }
        }
Beispiel #4
0
        public void ShowScore(string tournamentName)
        {
            Tournament tournament = tournamentRepository.GetTournament(tournamentName);

            // starter en Dictionary til at indeholde holdnavn og score
            // se ressource: https://www.dotnetperls.com/dictionary
            Dictionary <string, int> score = new Dictionary <string, int>();

            // Henter alle vindere i alle runder og giver holdene et point per vunden kamp
            for (int team = 0; team < tournament.GetNumberOfRounds(); team++)
            {
                List <Team> winningTeams = tournament.GetRound(team).GetWinningTeams();
                foreach (Team winningTeam in winningTeams)
                {
                    int updateNumber = 1;
                    if (score.TryGetValue(winningTeam.Name, out int number))
                    {
                        updateNumber = number + 1;
                        score.Remove(winningTeam.Name);
                    }
                    score.Add(winningTeam.Name, updateNumber);
                }
            }

            // Her tilføjes de spillere som tabte i første runde - de har alle 0 point
            List <Team> losingTeams = tournament.GetRound(0).GetLosingTeams();

            foreach (Team losingTeam in losingTeams)
            {
                if (!score.TryGetValue(losingTeam.Name, out int number))
                {
                    score.Add(losingTeam.Name, 0);
                }
            }

            // sorterer dictionary "score" så holdene med flest point er i toppen
            // se ressourcen: https://www.dotnetperls.com/sort-dictionary
            var items = from pair in score
                        orderby pair.Value descending
                        select pair;

            // skriver rudimentært scoreboard til skærm
            Console.Clear();
            foreach (KeyValuePair <string, int> pair in items)
            {
                Console.WriteLine(pair.Key + ": " + pair.Value);
            }
            Console.ReadKey();
            Console.Clear();

            /*
             * TODO: Calculate for each team how many times they have won
             * Sort based on number of matches won (descending)
             */
        }
        public void ShowScore(string tournamentName)
        {
            int winnerPoint = 1;


            Tournament t = tournamentRepo.GetTournament(tournamentName);

            Dictionary <string, int> teamDictionary = new Dictionary <string, int>();

            for (int i = 0; i < t.GetNumberOfRounds(); i++)
            {
                Round       currentRound = t.GetRound(i);
                List <Team> winningTeams = currentRound.GetWinningTeams();


                foreach (Team winningTeam in winningTeams)
                {
                    if (teamDictionary.ContainsKey(winningTeam.name))
                    {
                        if (teamDictionary.TryGetValue(winningTeam.name, out int number))
                        {
                            winnerPoint = number + 1;
                            teamDictionary.Remove(winningTeam.name);
                        }
                    }
                    teamDictionary.Add(winningTeam.name, winnerPoint);
                }
            }



            Console.WriteLine("Scoreboard");
            var sortedList = teamDictionary.OrderByDescending(x => x.Value);

            foreach (var key in sortedList)
            {
                Console.WriteLine("{1}  {0}", key.Key, key.Value);
            }
        }
Beispiel #6
0
        public string SaveMatch(string tournamentName, int roundNumber, string winningTeam)
        {
            TournamentRepo tr = new TournamentRepo();
            Tournament     t  = tr.GetTournament(tournamentName);
            Round          r  = t.GetRound(roundNumber - 1);
            Match          m  = r.GetMatch(winningTeam);

            if (m != null && m.Winner == null)
            {
                Team w = t.GetTeam(winningTeam);
                m.SetWinner(w);
                return("Du har opdateret vinder");
            }
            else
            {
                return("Der er sket en fejl");
            }
        }
Beispiel #7
0
        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.
        }