Esempio n. 1
0
        public void RunTournament(IPairingsGenerator pg, List <TournamentTeam> teams, List <TournamentRound> rounds, bool allowTies, TournamentNameTable nameTable)
        {
            ITournamentVisualizer viz = null;

            if (nameTable != null)
            {
                viz = pg as ITournamentVisualizer;
            }

            while (true)
            {
                pg.LoadState(teams, rounds);
                TournamentRound newRound = pg.CreateNextRound(null);

                if (viz != null)
                {
                    var gfx = new SystemGraphics();
                    var q2  = viz.Measure(gfx, nameTable);
                    viz.Render(gfx, nameTable);
                }

                if (newRound == null)
                {
                    pg.LoadState(teams, rounds);
                    newRound = pg.CreateNextRound(null);
                    break;
                }

                if (allowTies)
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            teamScore.Score = new HighestPointsScore(r.Next(20));
                        }
                    }
                }
                else
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        List <double> scoresUsed = new List <double>();
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            double score;
                            do
                            {
                                score = r.NextDouble();
                            } while (scoresUsed.Where(s => s == score).Any());

                            teamScore.Score = new HighestPointsScore(score);
                        }
                    }
                }

                rounds.Add(newRound);
            }
        }
Esempio n. 2
0
        private IEnumerable <TournamentRound> RounRobinBuildAllPairings(IEnumerable <TournamentTeam> teams, IPairingsGenerator rrpg)
        {
            List <TournamentRound> rounds = new List <TournamentRound>();

            while (true)
            {
                rrpg.LoadState(teams, rounds);

                TournamentRound newRound = rrpg.CreateNextRound(null);

                if (newRound != null)
                {
                    rounds.Add(newRound);
                }
                else
                {
                    break;
                }
            }

            foreach (TournamentRound round in rounds)
            {
                yield return(round);
            }

            yield break;
        }
Esempio n. 3
0
 private void IPairingsGeneratorThrowsExceptionOnNullParameters(IPairingsGenerator pg)
 {
     try
     {
         pg.LoadState(null, null);
         Assert.Fail();
     }
     catch (ArgumentNullException)
     {
         return;
     }
 }
Esempio n. 4
0
        private IEnumerable<TournamentRound> RounRobinBuildAllPairings(IEnumerable<TournamentTeam> teams, IPairingsGenerator rrpg)
        {
            List<TournamentRound> rounds = new List<TournamentRound>();

            while (true)
            {
                rrpg.LoadState(teams, rounds);

                TournamentRound newRound = rrpg.CreateNextRound(null);

                if (newRound != null)
                {
                    rounds.Add(newRound);
                }
                else
                {
                    break;
                }
            }

            foreach (TournamentRound round in rounds)
            {
                yield return round;
            }

            yield break;
        }
Esempio n. 5
0
 private void IPairingsGeneratorThrowsExceptionOnNullParameters(IPairingsGenerator pg)
 {
     try
     {
         pg.LoadState(null, null);
         Assert.Fail();
     }
     catch (ArgumentNullException)
     {
         return;
     }
 }
Esempio n. 6
0
        public void RunTournament(IPairingsGenerator pg, List<TournamentTeam> teams, List<TournamentRound> rounds, bool allowTies, TournamentNameTable nameTable)
        {
            ITournamentVisualizer viz = null;
            if (nameTable != null)
            {
                viz = pg as ITournamentVisualizer;
            }

            while (true)
            {
                pg.LoadState(teams, rounds);
                TournamentRound newRound = pg.CreateNextRound(null);

                if (viz != null)
                {
                    var gfx = new SystemGraphics();
                    var q2 = viz.Measure(gfx, nameTable);
                    viz.Render(gfx, nameTable);
                }

                if (newRound == null)
                {
                    pg.LoadState(teams, rounds);
                    newRound = pg.CreateNextRound(null);
                    break;
                }

                if (allowTies)
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            teamScore.Score = new HighestPointsScore(r.Next(20));
                        }
                    }
                }
                else
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        List<double> scoresUsed = new List<double>();
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            double score;
                            do
                            {
                                score = r.NextDouble();
                            } while (scoresUsed.Where(s => s == score).Any());

                            teamScore.Score = new HighestPointsScore(score);
                        }
                    }
                }

                rounds.Add(newRound);
            }
        }