コード例 #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;
                }
            }
        }
コード例 #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));
            }
        }
コード例 #3
0
ファイル: StayDecider.cs プロジェクト: otac0n/tournaments
        /// <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));
            }
        }
コード例 #4
0
ファイル: StayDecider.cs プロジェクト: otac0n/tournaments
        /// <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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        //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));
        }
コード例 #7
0
        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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #10
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.Id];
                }
                else
                {
                    return;
                }
            }

            this.RenderTextBox(g, x, y, textHeight, teamName, score);
        }
コード例 #11
0
        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));
        }
コード例 #12
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.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);
            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
ファイル: TeamDecider.cs プロジェクト: Rychard/TournamentApi
 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.");
 }
コード例 #15
0
 public override NodeMeasurement MeasureLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
コード例 #16
0
 public void Render(IGraphics graphics, TournamentNameTable teamNames)
 {
     throw new NotImplementedException();
 }
コード例 #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);
            }
        }
コード例 #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);
 }
コード例 #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;
 }
コード例 #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.");
 }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #23
0
ファイル: TeamDecider.cs プロジェクト: Rychard/TournamentApi
 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);
 }
コード例 #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);
 }
コード例 #25
0
 public override NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     throw new InvalidOperationException("Cannot determine a loser from a pass through.");
 }
コード例 #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;
 }
コード例 #27
0
ファイル: WinnerNode.cs プロジェクト: Rychard/TournamentApi
 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);
 }
コード例 #28
0
 public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight)
 {
     return(this.decider.MeasureWinner(g, names, textHeight, this.Score));
 }
コード例 #29
0
 public abstract NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score);
コード例 #30
0
 public abstract NodeMeasurement Measure(IGraphics g, TournamentNameTable names, float textHeight);
コード例 #31
0
ファイル: WinnerNode.cs プロジェクト: Rychard/TournamentApi
 public override NodeMeasurement Measure(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight)
 {
     return this.decider.MeasureWinner(g, names, textHeight, this.Score);
 }
コード例 #32
0
ファイル: StayDecider.cs プロジェクト: otac0n/tournaments
 /// <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.");
 }
コード例 #33
0
 public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     return(this.MeasureTextBox(g, textHeight, names[this.team.Id], score));
 }
コード例 #34
0
 public SizeF Measure(IGraphics graphics, TournamentNameTable teamNames)
 {
     throw new NotImplementedException();
 }
コード例 #35
0
 public abstract NodeMeasurement MeasureLoser(IGraphics g, TournamentNameTable names, float textHeight, Score score);
コード例 #36
0
 public override void RenderLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
コード例 #37
0
ファイル: TeamDecider.cs プロジェクト: Rychard/TournamentApi
 public override NodeMeasurement MeasureWinner(IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     return this.MeasureTextBox(g, textHeight, names[this.team.TeamId], score);
 }
コード例 #38
0
 public abstract NodeMeasurement Measure(IGraphics g, TournamentNameTable names, float textHeight);
コード例 #39
0
 public override NodeMeasurement MeasureLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
コード例 #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);
            }
        }
コード例 #41
0
 public override void RenderLoser(Tournaments.Graphics.IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score)
 {
     throw new NotImplementedException();
 }
コード例 #42
0
 public abstract void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score);
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
 }
コード例 #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);
            }
        }
コード例 #48
0
 public abstract void RenderLoser(IGraphics g, TournamentNameTable names, float x, float y, float textHeight, Score score);
コード例 #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);
            }
        }
コード例 #50
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);
            }
        }
コード例 #51
0
        //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);
        }
コード例 #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.");
 }
コード例 #53
0
        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);
        }
コード例 #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.");
 }
コード例 #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;
 }