コード例 #1
0
        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);
            //    }
            //}
        }
コード例 #2
0
        public void OneWinnerInLastRound()
        {
            // Verifies there is exactly one winner in last round
            int   numberOfRounds       = currentTournament.GetNumberOfRounds();
            Round currentRound         = currentTournament.GetRound(numberOfRounds - 1);
            int   numberOfWinningTeams = currentRound.GetWinningTeams().Count;

            Assert.AreEqual(1, numberOfWinningTeams);
        }
コード例 #3
0
        public void EqualNumberOfWinnersAndLosersPerRound()
        {
            int numberOfRounds = currentTournament.GetNumberOfRounds();

            for (int round = 0; round < numberOfRounds; round++)
            {
                Round currentRound         = currentTournament.GetRound(round);
                int   numberOfWinningTeams = currentRound.GetWinningTeams().Count;
                int   numberOfLosingTeams  = currentRound.GetLosingTeams().Count;
                Assert.AreEqual(numberOfWinningTeams, numberOfLosingTeams);
            }
        }
コード例 #4
0
        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();
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: Controller.cs プロジェクト: Fred128e/DragonsLair
        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!");
        }
コード例 #6
0
ファイル: Controller.cs プロジェクト: Biest1155/DragonsLair
        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");
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
ファイル: Controller.cs プロジェクト: Biest1155/DragonsLair
        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");
                }
            }
        }
コード例 #9
0
        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();
                }
            }
        }
コード例 #10
0
ファイル: Controller.cs プロジェクト: Fred128e/DragonsLair
        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());
            //    }
            //}
        }