public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var p = new StandardTournamentsPluginEnumerator(); var factories = from f in p.EnumerateFactories() let pf = f as IPairingsGeneratorFactory where pf != null select pf; var chosen = (new PairingsChooserView(factories)).Run(); if (chosen != null) { IPairingsGenerator pg = chosen.Create(); if (pg == null) { MessageBox.Show("There was an error creating an instance of the '" + chosen.Name + "' pairings generator. :("); return; } (new TournamentView(pg)).Run(); } }
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); } }
public TournamentView(IPairingsGenerator generator) { InitializeComponent(); this.generator = generator ?? throw new ArgumentNullException(nameof(generator)); this.generator.Reset(); this.visualizer = this.generator as ITournamentVisualizer; this.UpdateState(); }
private void IPairingsGeneratorThrowsExceptionOnNullParameters(IPairingsGenerator pg) { try { pg.LoadState(null, null); Assert.Fail(); } catch (ArgumentNullException) { return; } }
public TournamentView(IPairingsGenerator generator) { if (generator == null) { throw new ArgumentNullException("generator"); } InitializeComponent(); this.generator = generator; this.generator.Reset(); this.visualizer = this.generator as ITournamentVisualizer; this.UpdateState(); }
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; }
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; }
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); } }