Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        /// <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));
            }
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 8
0
        /// <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));
        }
Esempio n. 9
0
        /// <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);
            }
        }
Esempio n. 14
0
 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();
 }
Esempio n. 16
0
 public void Render(IGraphics graphics, TournamentNameTable teamNames)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
 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);
 }
Esempio n. 19
0
 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;
 }
Esempio n. 20
0
 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.");
 }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
 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);
 }
Esempio n. 24
0
 /// <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.");
 }
Esempio n. 26
0
 /// <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;
 }
Esempio n. 27
0
 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);
 }
Esempio n. 28
0
 public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight)
 {
     return(this.decider.MeasureWinner(g, names, textHeight, this.Score));
 }
Esempio n. 29
0
 public abstract NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score);
 public abstract NodeMeasurement Measure(IGraphics g, TournamentNameTable names, float textHeight);
Esempio n. 31
0
 public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight)
 {
     return this.decider.MeasureWinner(g, names, textHeight, this.Score);
 }
Esempio n. 32
0
 /// <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.");
 }
Esempio n. 33
0
 public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     return(this.MeasureTextBox(g, textHeight, names[this.team.Id], score));
 }
Esempio n. 34
0
 public SizeF Measure(IGraphics graphics, TournamentNameTable teamNames)
 {
     throw new NotImplementedException();
 }
 public abstract NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score);
 public override void RenderLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
Esempio n. 37
0
 public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     return this.MeasureTextBox(g, textHeight, names[this.team.TeamId], score);
 }
 public abstract NodeMeasurement Measure(IGraphics g, TournamentNameTable names, float textHeight);
Esempio n. 39
0
 public override NodeMeasurement MeasureLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
Esempio n. 40
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. 41
0
 public override void RenderLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
Esempio n. 42
0
 public abstract void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score);
Esempio n. 43
0
        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);
            }
        }
Esempio n. 44
0
        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);
            }
        }
Esempio n. 45
0
        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);
        }
Esempio n. 46
0
 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);
 }
Esempio n. 47
0
        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);
            }
        }
 public abstract void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score);
Esempio n. 49
0
        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);
            }
        }
        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);
            }
        }
        //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);
        }
Esempio n. 52
0
 /// <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.");
 }
        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);
        }
Esempio n. 54
0
 /// <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.");
 }
Esempio n. 55
0
 public override NodeMeasurement MeasureWinner(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     //return this.MeasureTextBox(g, textHeight, "bye", score);
     return null;
 }