public void SingleEliminationHandlesManyCompetitorsWell() { IPairingsGenerator pg = new EliminationTournament(1); for (int i = 30; i <= 40; i++) { List <TournamentTeam> teams = new List <TournamentTeam>(CreateTeams(i)); List <TournamentRound> rounds = new List <TournamentRound>(); Dictionary <long, string> teamNames = new Dictionary <long, string>(); foreach (var team in teams) { teamNames.Add(team.TeamId, "Team#" + team.TeamId); } TournamentNameTable nameTable = new TournamentNameTable(teamNames); try { RunTournament(pg, teams, rounds, false, nameTable); DisplayTournamentRounds(rounds); DisplayTournamentRankings(pg.GenerateRankings()); } catch (InvalidTournamentStateException) { throw; } } }
protected NodeMeasurement MeasureTree(IGraphics g, TournamentNameTable names, float textHeight, EliminationNode nodeA, EliminationNode nodeB) { var mA = nodeA == null ? null : nodeA.Measure(g, names, textHeight); var mB = nodeB == null ? null : nodeB.Measure(g, names, textHeight); if (mA == null && mB == null) { return(null); } else if (mA != null && mB != null) { return(new NodeMeasurement( Math.Max(mA.Width, mB.Width) + BracketPreIndent + BracketPostIndent, mA.Height + mB.Height + BracketVSpacing, (mA.CenterLine + (mA.Height + BracketVSpacing + mB.CenterLine)) / 2)); } else if (mA != null) { return(new NodeMeasurement( mA.Width + BracketPreIndent + BracketPostIndent, mA.Height, mA.CenterLine)); } else { return(new NodeMeasurement( mB.Width + BracketPreIndent + BracketPostIndent, mB.Height, mB.CenterLine)); } }
/// <inheritdoc /> public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { if (!(this.PreviousWinnerNode.IsDecided && this.StayNode.IsDecided) || (this.StayNode.Team == null || this.PreviousWinnerNode.Team == null) || this.PreviousWinnerNode.Team.TeamId == this.StayNode.Team.TeamId) { return(this.PreviousWinnerNode.Measure(g, names, textHeight)); } else { var m = this.MeasureTree(g, names, textHeight, this.PreviousWinnerNode, this.StayNode); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var t = this.MeasureTextBox(g, textHeight, teamName, score); return(new NodeMeasurement(m.Width + t.Width, m.Height, m.CenterLine)); } }
/// <inheritdoc /> public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { if (!(this.PreviousWinnerNode.IsDecided && this.StayNode.IsDecided) || (this.StayNode.Team == null || this.PreviousWinnerNode.Team == null) || this.PreviousWinnerNode.Team.TeamId == this.StayNode.Team.TeamId) { this.PreviousWinnerNode.Render(g, names, x, y, textHeight); } else { var m = this.MeasureWinner(g, names, textHeight, score); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var r = this.MeasureTextBox(g, textHeight, teamName, score); this.RenderTextBox(g, x + m.Width - r.Width, y + m.CenterLine - r.CenterLine, textHeight, teamName, score); this.RenderTree(g, names, x, y, textHeight, this.PreviousWinnerNode, this.StayNode); } }
public void Render(IGraphics graphics, TournamentNameTable teamNames) { if (this.loadedRootNode == null) { return; } var textHeight = GetTextHeight(graphics); var size = this.Measure(graphics, teamNames); this.loadedRootNode.Render(graphics, teamNames, 0, 0, textHeight); }
//private EliminationNode FindTeamsHighestNode(long teamId) //{ // return (from n in this.loadedNodes // let d = n.Decider as ContinuationDecider // where d != null // where ChildAMatches(d, teamId) || ChildBMatches(d, teamId) // orderby n.Level // select n).FirstOrDefault(); //} public SizeF Measure(IGraphics graphics, TournamentNameTable teamNames) { if (this.loadedRootNode == null) { return(new Size(0, 0)); } var textHeight = GetTextHeight(graphics); var size = this.loadedRootNode.Measure(graphics, teamNames, textHeight); return(new SizeF(size.Width + 10, size.Height + 10)); }
public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } return this.MeasureTextBox(g, textHeight, teamName, score); }
/// <inheritdoc /> public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } return(this.MeasureTextBox(g, textHeight, teamName, score)); }
/// <inheritdoc /> public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } this.RenderTextBox(g, x, y, textHeight, teamName, score); }
public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var loser = this.GetLoser(); if (loser != null) { teamName = names[loser.Id]; } else { return; } } this.RenderTextBox(g, x, y, textHeight, teamName, score); }
public override NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var loser = this.GetLoser(); if (loser != null) { teamName = names[loser.Id]; } else { return(null); } } return(this.MeasureTextBox(g, textHeight, teamName, score)); }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { var m = this.MeasureWinner(g, names, textHeight, score); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.Id]; } else { teamName = "bye"; } } var t = this.MeasureTextBox(g, textHeight, teamName, score); this.RenderTextBox(g, x + m.Width - t.Width, y + m.CenterLine - t.CenterLine, textHeight, teamName, score); var mA = this.nodeA.Measure(g, names, textHeight); var mB = this.nodeB.Measure(g, names, textHeight); if (mA == null || mB == null) { return; } else { this.RenderTree(g, names, x, y, textHeight, this.nodeA, this.nodeB); } }
protected NodeMeasurement MeasureTree(IGraphics g, TournamentNameTable names, float textHeight, EliminationNode nodeA, EliminationNode nodeB) { var mA = nodeA == null ? null : nodeA.Measure(g, names, textHeight); var mB = nodeB == null ? null : nodeB.Measure(g, names, textHeight); if (mA == null && mB == null) { return null; } else if (mA != null && mB != null) { return new NodeMeasurement( Math.Max(mA.Width, mB.Width) + BracketPreIndent + BracketPostIndent, mA.Height + mB.Height + BracketVSpacing, (mA.CenterLine + (mA.Height + BracketVSpacing + mB.CenterLine)) / 2); } else if (mA != null) { return new NodeMeasurement( mA.Width + BracketPreIndent + BracketPostIndent, mA.Height, mA.CenterLine); } else { return new NodeMeasurement( mB.Width + BracketPreIndent + BracketPostIndent, mB.Height, mB.CenterLine); } }
public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { throw new InvalidOperationException("Cannot determine a loser from an individual team entry."); }
public override NodeMeasurement MeasureLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score) { throw new NotImplementedException(); }
public void Render(IGraphics graphics, TournamentNameTable teamNames) { throw new NotImplementedException(); }
private void UpdateState() { bool roundsPlayed = this.rounds.Count > 0; bool nextRoundAvailable = false; bool validState = false; try { this.generator.Reset(); this.generator.LoadState(this.teams, this.rounds); validState = true; this.TournamentStatus.Text = "Ready."; this.TournamentStatus.BackColor = Color.Transparent; } catch (InvalidTournamentStateException ex) { this.Visualization.Image = null; this.TournamentStatus.Text = "Error: " + ex.Message; this.TournamentStatus.BackColor = Color.Red; } if (validState) { try { this.StandingsList.Items.Clear(); var standings = this.generator.GenerateRankings(); foreach (var standing in standings) { var item = new ListViewItem(new string[] { standing.Rank.ToString(), this.teamNames[standing.Team.TeamId], standing.ScoreDescription }); this.StandingsList.Items.Add(item); } } catch (InvalidTournamentStateException) { } try { if (this.visualizer != null) { var names = new TournamentNameTable(this.teamNames); var size = this.visualizer.Measure(this.measureGraphics, names); if (size.Height > 0 && size.Width > 0) { var rendered = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height)); this.visualizer.Render(new SystemGraphics(rendered), names); this.Visualization.Image = rendered; } else { this.Visualization.Image = null; } } } catch (InvalidTournamentStateException) { } try { var round = this.generator.CreateNextRound(null); if (round != null) { nextRoundAvailable = true; } } catch (InvalidTournamentStateException) { } } this.AddTeam.Enabled = !roundsPlayed; this.RollBack.Enabled = roundsPlayed; this.StartNext.Enabled = nextRoundAvailable; foreach(ColumnHeader col in this.TeamsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } foreach (ColumnHeader col in this.StandingsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } foreach (ColumnHeader col in this.RoundsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } }
public override void Render(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight) { this.decider.RenderWinner(g, names, x, y, textHeight, this.Score); }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { //this.RenderTextBox(g, x, y, textHeight, "bye", score); return; }
public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { throw new InvalidOperationException("Rendering the loser node of a stay decider is invalid."); }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { if (!(this.previousWinnerNode.IsDecided && this.stayNode.IsDecided) || (this.stayNode.Team == null || this.previousWinnerNode.Team == null) || this.previousWinnerNode.Team.TeamId == this.stayNode.Team.TeamId) { this.previousWinnerNode.Render(g, names, x, y, textHeight); } else { var m = this.MeasureWinner(g, names, textHeight, score); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var r = this.MeasureTextBox(g, textHeight, teamName, score); this.RenderTextBox(g, x + m.Width - r.Width, y + m.CenterLine - r.CenterLine, textHeight, teamName, score); this.RenderTree(g, names, x, y, textHeight, this.previousWinnerNode, this.stayNode); } }
public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { if (!(this.previousWinnerNode.IsDecided && this.stayNode.IsDecided) || (this.stayNode.Team == null || this.previousWinnerNode.Team == null) || this.previousWinnerNode.Team.TeamId == this.stayNode.Team.TeamId) { return this.previousWinnerNode.Measure(g, names, textHeight); } else { var m = this.MeasureTree(g, names, textHeight, this.previousWinnerNode, this.stayNode); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var t = this.MeasureTextBox(g, textHeight, teamName, score); return new NodeMeasurement(m.Width + t.Width, m.Height, m.CenterLine); } }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { this.RenderTextBox(g, x, y, textHeight, names[this.team.TeamId], score); }
/// <inheritdoc /> public override NodeMeasurement MeasureWinner(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score) { //return this.MeasureTextBox(g, textHeight, "bye", score); return(null); }
public override NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score) { throw new InvalidOperationException("Cannot determine a loser from a pass through."); }
/// <inheritdoc /> public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { //this.RenderTextBox(g, x, y, textHeight, "bye", score); return; }
public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight) { return(this.decider.MeasureWinner(g, names, textHeight, this.Score)); }
public abstract NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score);
public abstract NodeMeasurement Measure(IGraphics g, TournamentNameTable names, float textHeight);
public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight) { return this.decider.MeasureWinner(g, names, textHeight, this.Score); }
/// <inheritdoc /> public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { throw new InvalidOperationException("Rendering the loser node of a stay decider is invalid."); }
public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { return(this.MeasureTextBox(g, textHeight, names[this.team.Id], score)); }
public SizeF Measure(IGraphics graphics, TournamentNameTable teamNames) { throw new NotImplementedException(); }
public override void RenderLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { throw new NotImplementedException(); }
public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score) { return this.MeasureTextBox(g, textHeight, names[this.team.TeamId], score); }
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 abstract void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score);
public override NodeMeasurement MeasureWinner(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var t = this.MeasureTextBox(g, textHeight, teamName, score); var mA = this.nodeA.Measure(g, names, textHeight); var mB = this.nodeB.Measure(g, names, textHeight); if (mA == null && mB == null) { return null; } else if (mB == null) { return t; } else if (mA == null) { return t; } else { var m = this.MeasureTree(g, names, textHeight, this.nodeA, this.nodeB); return new NodeMeasurement(m.Width + t.Width, m.Height, m.CenterLine); } }
protected void RenderTree(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, EliminationNode nodeA, EliminationNode nodeB) { var m = this.MeasureTree(g, names, textHeight, nodeA, nodeB); var mA = nodeA == null ? null : nodeA.Measure(g, names, textHeight); var mB = nodeB == null ? null : nodeB.Measure(g, names, textHeight); if (mA == null && mB == null) { return; } else if (mA != null && mB != null) { // Preline g.DrawLine( BracketPen, new PointF( x + (m.Width - BracketPreIndent), y + m.CenterLine), new PointF( x + m.Width, y + m.CenterLine)); // V-Line g.DrawLine( BracketPen, new PointF( x + (m.Width - BracketPreIndent), y + mA.CenterLine), new PointF( x + (m.Width - BracketPreIndent), y + mA.Height + BracketVSpacing + mB.CenterLine)); // Post-Line-A g.DrawLine( BracketPen, new PointF( x + (m.Width - BracketPreIndent - BracketPostIndent), y + mA.CenterLine), new PointF( x + (m.Width - BracketPreIndent), y + mA.CenterLine)); // Post-Line-B g.DrawLine( BracketPen, new PointF( x + (m.Width - BracketPreIndent - BracketPostIndent), y + mA.Height + BracketVSpacing + mB.CenterLine), new PointF( x + (m.Width - BracketPreIndent), y + mA.Height + BracketVSpacing + mB.CenterLine)); nodeA.Render(g, names, x + (m.Width - (mA.Width + BracketPreIndent + BracketPostIndent)), y, textHeight); nodeB.Render(g, names, x + (m.Width - (mB.Width + BracketPreIndent + BracketPostIndent)), y + mA.Height + BracketVSpacing, textHeight); } else if (mA != null) { // TODO: Render Lines? nodeA.Render(g, names, x, y, textHeight); } else { // TODO: Render Lines? nodeB.Render(g, names, x, y, textHeight); } }
public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { string teamName = ""; if (this.IsDecided) { var loser = this.GetLoser(); if (loser != null) { teamName = names[loser.TeamId]; } else { return; } } this.RenderTextBox(g, x, y, textHeight, teamName, score); }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { this.RenderTextBox(g, x, y, textHeight, names[this.team.Id], score); }
public override void RenderWinner(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { var m = this.MeasureWinner(g, names, textHeight, score); string teamName = ""; if (this.IsDecided) { var winner = this.GetWinner(); if (winner != null) { teamName = names[winner.TeamId]; } else { teamName = "bye"; } } var t = this.MeasureTextBox(g, textHeight, teamName, score); this.RenderTextBox(g, x + m.Width - t.Width, y + m.CenterLine - t.CenterLine, textHeight, teamName, score); var mA = this.nodeA.Measure(g, names, textHeight); var mB = this.nodeB.Measure(g, names, textHeight); if (mA == null || mB == null) { return; } else { this.RenderTree(g, names, x, y, textHeight, this.nodeA, this.nodeB); } }
private void UpdateState() { bool roundsPlayed = this.rounds.Count > 0; bool nextRoundAvailable = false; bool validState = false; try { this.generator.Reset(); this.generator.LoadState(this.teams, this.rounds); validState = true; this.TournamentStatus.Text = "Ready."; this.TournamentStatus.BackColor = Color.Transparent; } catch (InvalidTournamentStateException ex) { this.Visualization.Image = null; this.TournamentStatus.Text = "Error: " + ex.Message; this.TournamentStatus.BackColor = Color.Red; } if (validState) { try { this.StandingsList.Items.Clear(); var standings = this.generator.GenerateRankings(); foreach (var standing in standings) { var item = new ListViewItem(new string[] { standing.Rank.ToString(), this.teamNames[standing.Team.TeamId], standing.ScoreDescription }); this.StandingsList.Items.Add(item); } } catch (InvalidTournamentStateException) { } try { if (this.visualizer != null) { var names = new TournamentNameTable(this.teamNames); var size = this.visualizer.Measure(this.measureGraphics, names); if (size.Height > 0 && size.Width > 0) { var rendered = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height)); this.visualizer.Render(new SystemGraphics(rendered), names); this.Visualization.Image = rendered; } else { this.Visualization.Image = null; } } } catch (InvalidTournamentStateException) { } try { var round = this.generator.CreateNextRound(null); if (round != null) { nextRoundAvailable = true; } } catch (InvalidTournamentStateException) { } } this.AddTeam.Enabled = !roundsPlayed; this.RollBack.Enabled = roundsPlayed; this.StartNext.Enabled = nextRoundAvailable; foreach (ColumnHeader col in this.TeamsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } foreach (ColumnHeader col in this.StandingsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } foreach (ColumnHeader col in this.RoundsList.Columns) { col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); } }
//private EliminationNode FindTeamsHighestNode(long teamId) //{ // return (from n in this.loadedNodes // let d = n.Decider as ContinuationDecider // where d != null // where ChildAMatches(d, teamId) || ChildBMatches(d, teamId) // orderby n.Level // select n).FirstOrDefault(); //} public SizeF Measure(IGraphics graphics, TournamentNameTable teamNames) { if (this.loadedRootNode == null) { return new Size(0, 0); } var textHeight = GetTextHeight(graphics); var size = this.loadedRootNode.Measure(graphics, teamNames, textHeight); return new SizeF(size.Width + 10, size.Height + 10); }
/// <inheritdoc /> public override NodeMeasurement MeasureLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score) { throw new InvalidOperationException("Cannot determine a loser from a bye entry."); }
/// <inheritdoc /> public override void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score) { throw new InvalidOperationException("Cannot determine a loser from a bye entry."); }
public override NodeMeasurement MeasureWinner(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score) { //return this.MeasureTextBox(g, textHeight, "bye", score); return null; }