コード例 #1
0
 public void ApplyTournamentMatchupChanges(LiteDatabase db, ref Tournament t)
 {
     for (int i = t.bracket.Rounds.Count - 1; i >= 0; i--)
     {
         Round r = t.bracket.Rounds[i];
         for (int j = 0; j < r.Matchups.Count; j++)
         {
             Matchup m = r.Matchups[j];
             UpdateMatchup(db, m);
         }
     }
 }
コード例 #2
0
 public void ApplyTournamentMatchupChanges(MySqlConnection conn, ref Tournament t)
 {
     for (int i = t.bracket.Rounds.Count - 1; i >= 0; i--)
     {
         Round r = t.bracket.Rounds[i];
         for (int j = 0; j < r.Matchups.Count; j++)
         {
             Matchup m = r.Matchups[j];
             ApplySingleMatchupUpdate(conn, m, ref t);
         }
     }
 }
コード例 #3
0
        //Bracket

        public void registerBracket(LiteDatabase db, ref Tournament t)
        {
            var collection = db.GetCollection <Matchup>("matchups");

            //t.bracket.MatchupTree.UID = collection.Insert(t.bracket.MatchupTree);
            for (int i = t.bracket.Rounds.Count - 1; i >= 0; i--)
            {
                Round r = t.bracket.Rounds[i];
                for (int j = 0; j < r.Matchups.Count; j++)
                {
                    Matchup m = r.Matchups[j];
                    collection.Insert(m);
                }
            }
            collection.EnsureIndex(x => x.UID);
        }
コード例 #4
0
        public void getTournamentBracket(LiteDatabase db, ref Tournament tourney)
        {
            tourney.CreateBracket();

            var collection = db.GetCollection <Matchup>("matchups");

            long           tourn_id = tourney.info.UID;
            List <Matchup> ms       = collection.Find(Query.All("_id", Query.Descending), 0, 100).Where(x => x.TournamentID == tourn_id).ToList();

            foreach (Matchup m in ms)
            {
                Matchup mat = tourney.bracket.Matchups[m.ID];
                //Override info
                mat.UID          = m.UID;
                mat.TournamentID = m.TournamentID;
                mat.RoundID      = m.RoundID;
                mat.LobbyName    = m.LobbyName;
                mat.LobbyPass    = m.LobbyPass;
                if (m.Team1ID > 0)
                {
                    mat.Team1 = tourney.getTeamByUID(m.Team1ID);
                }
                mat.Team1 = tourney.getTeamByUID(m.Team1ID);
                if (m.Team2ID > 0)
                {
                    mat.Team2 = tourney.getTeamByUID(m.Team2ID);
                }
                mat.Team2 = tourney.getTeamByUID(m.Team2ID);
                if (m.Team1ReportedWinnerID > 0)
                {
                    mat.Team1ReportedWinner = tourney.getTeamByUID(m.Team1ReportedWinnerID);
                }
                if (m.Team2ReportedWinnerID > 0)
                {
                    mat.Team2ReportedWinner = tourney.getTeamByUID(m.Team2ReportedWinnerID);
                }
                if (m.WinnerID > 0)
                {
                    mat.Winner = tourney.getTeamByUID(m.WinnerID);
                }
                if (m.NextMatchupID > 0)
                {
                    mat.Next = tourney.getmatchupByUID(m.NextMatchupID);
                }
                mat.InProgress = m.InProgress;
            }
        }
コード例 #5
0
ファイル: Bracket.cs プロジェクト: gregkwaste/RLTournamentBot
        public void GenerateMatchups(Matchup matchup, int round_num)
        {
            if (round_num < 0)
            {
                return;
            }

            //Generate 2 matchups per matchup
            Matchup m1 = new Matchup()
            {
                ID           = _matchups.Count,
                Team1        = null,
                Team2        = null,
                Winner       = null,
                Next         = matchup,
                IsFinished   = false,
                TournamentID = TournamentID,
                RoundID      = round_num
            };

            Matchup m2 = new Matchup()
            {
                ID           = _matchups.Count + 1,
                Team1        = null,
                Team2        = null,
                Winner       = null,
                IsFinished   = false,
                TournamentID = TournamentID,
                Next         = matchup,
                RoundID      = round_num
            };

            //Save Matchups
            _matchups.Add(m1);
            _matchups.Add(m2);

            //Add Matchups to round
            Rounds[round_num].Matchups.Add(m1);
            Rounds[round_num].Matchups.Add(m2);

            //Recursively generate previous rounds
            GenerateMatchups(m1, round_num - 1);
            GenerateMatchups(m2, round_num - 1);
        }
コード例 #6
0
ファイル: Bracket.cs プロジェクト: gregkwaste/RLTournamentBot
        public void GenerateSVG()
        {
            SvgDocument doc = new SvgDocument();

            doc.FontSize = 16;

            SvgColourServer blackPainter = new SvgColourServer(Color.Black);
            SvgColourServer whitePainter = new SvgColourServer(Color.White);
            SvgColourServer grayPainter  = new SvgColourServer(Color.Gray);
            SvgColourServer greenPainter = new SvgColourServer(Color.LightGreen);


            int round_gap              = 50;
            int matchup_width          = 400;
            int matchup_height         = 150;
            int matchup_team_x_offset  = 20;
            int matchup_team_y_offset  = 50;
            int matchup_team_font_size = 36;
            int matchup_vs_font_size   = 24;

            int matchup_offset_y = 0;
            int matchup_gap_y    = 10;

            for (int r_i = 0; r_i < Rounds.Count; r_i++)
            {
                Round r = Rounds[r_i];
                Console.WriteLine("Round {0} Matches: ", r.ID);

                //Calculate matchup gap
                int round_x_offset = r_i * (matchup_width + round_gap);

                for (int m_i = 0; m_i < r.Matchups.Count; m_i++)
                {
                    Matchup m = r.Matchups[m_i];

                    int round_y_offset = m_i * (matchup_height + matchup_gap_y) + matchup_offset_y;

                    //Draw Rectangle per Matchup

                    SvgRectangle rec = new SvgRectangle();
                    rec.X           = round_x_offset;
                    rec.Y           = round_y_offset;
                    rec.Width       = matchup_width;
                    rec.Height      = matchup_height;
                    rec.Stroke      = blackPainter;
                    rec.StrokeWidth = 2;


                    if (!m.IsFinished)
                    {
                        rec.Fill = whitePainter;
                    }
                    else
                    {
                        rec.Fill = greenPainter;
                    }

                    doc.Children.Add(rec);

                    //Team 1 Text
                    string team_text = "TBD";
                    string team_id   = "";
                    if (m.Team1 != null)
                    {
                        if (m.Team1.IsDummy)
                        {
                            team_text = "-";
                        }
                        else
                        {
                            team_text = m.Team1.Name;
                            team_id   = m.Team1.ID.ToString("00");
                        }
                    }

                    //Add Text
                    //Τeam ID
                    SvgText t1 = new SvgText(team_id);
                    t1.FontSize = matchup_team_font_size;
                    t1.X.Add(round_x_offset + matchup_team_x_offset - 10);
                    t1.Y.Add(round_y_offset + matchup_team_y_offset);
                    doc.Children.Add(t1);

                    //Τeam Name
                    t1 = new SvgText(team_text);
                    if (m.Team1 == m.Winner && m.Winner != null)
                    {
                        t1.FontWeight = SvgFontWeight.Bold;
                    }
                    t1.FontSize = matchup_team_font_size;
                    t1.X.Add(round_x_offset + 50 + matchup_team_x_offset);
                    t1.Y.Add(round_y_offset + matchup_team_y_offset);
                    doc.Children.Add(t1);

                    SvgText t3 = new SvgText("vs");
                    t3.FontSize = matchup_vs_font_size;
                    t3.X.Add(round_x_offset + matchup_team_x_offset);
                    t3.Y.Add(round_y_offset + 5 + matchup_height / 2.0f);
                    doc.Children.Add(t3);

                    //Horizontal Matchup Splitter Line Part 1
                    //Add horizontal line
                    SvgLine hl1 = new SvgLine();
                    hl1.Stroke        = blackPainter;
                    hl1.StrokeWidth   = 5;
                    hl1.StrokeOpacity = 1.0f;
                    hl1.FillOpacity   = 1.0f;
                    hl1.StartX        = round_x_offset + matchup_team_x_offset + 40;
                    hl1.StartY        = round_y_offset + matchup_height / 2.0f;
                    hl1.EndX          = round_x_offset + matchup_width;
                    hl1.EndY          = hl1.StartY;
                    doc.Children.Add(hl1);


                    //Vertical Line on the splitter
                    SvgLine vl1 = new SvgLine();
                    vl1.Stroke        = blackPainter;
                    vl1.StrokeWidth   = 5;
                    vl1.StrokeOpacity = 1.0f;
                    vl1.FillOpacity   = 1.0f;
                    vl1.StartX        = hl1.StartX;
                    vl1.StartY        = hl1.StartY;
                    vl1.EndX          = vl1.StartX;
                    vl1.EndY          = hl1.StartY - matchup_height / 2.0f;
                    doc.Children.Add(vl1);

                    SvgLine vl2 = new SvgLine();
                    vl2.Stroke        = blackPainter;
                    vl2.StrokeWidth   = 5;
                    vl2.StrokeOpacity = 1.0f;
                    vl2.FillOpacity   = 1.0f;
                    vl2.StartX        = hl1.StartX;
                    vl2.StartY        = hl1.StartY;
                    vl2.EndX          = vl1.StartX;
                    vl2.EndY          = hl1.StartY + matchup_height / 2.0f;
                    doc.Children.Add(vl2);


                    //Team 2 Text
                    team_text = "TBD";
                    team_id   = "";
                    if (m.Team2 != null)
                    {
                        if (m.Team2.IsDummy)
                        {
                            team_text = "-";
                        }
                        else
                        {
                            team_text = m.Team2.Name;
                            team_id   = m.Team2.ID.ToString("00");
                        }
                    }

                    //Τeam ID
                    SvgText t2 = new SvgText(team_id);
                    t2.FontSize = matchup_team_font_size;
                    t2.X.Add(round_x_offset + matchup_team_x_offset - 10);
                    t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset);
                    doc.Children.Add(t2);

                    t2 = new SvgText(team_text);
                    if (m.Team2 == m.Winner && m.Winner != null)
                    {
                        t2.FontWeight = SvgFontWeight.Bold;
                    }
                    t2.FontSize = matchup_team_font_size;
                    t2.X.Add(round_x_offset + 50 + matchup_team_x_offset);
                    t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset);
                    doc.Children.Add(t2);

                    //Draw Matchup Connector to next Matchup
                    if (r_i != Rounds.Count - 1)
                    {
                        //Add horizontal line
                        SvgLine l = new SvgLine();
                        l.Stroke        = grayPainter;
                        l.StrokeWidth   = 5;
                        l.StrokeOpacity = 1.0f;
                        l.FillOpacity   = 1.0f;
                        l.StartX        = round_x_offset + matchup_width;
                        l.StartY        = round_y_offset + matchup_height / 2.0f;
                        l.EndX          = l.StartX + round_gap / 2.0f;
                        l.EndY          = l.StartY;
                        doc.Children.Add(l);

                        //Vertical Line
                        SvgLine l1 = new SvgLine();
                        l1.Stroke        = grayPainter;
                        l1.StrokeWidth   = 5;
                        l1.StrokeOpacity = 1.0f;
                        l1.FillOpacity   = 1.0f;
                        l1.StartX        = l.EndX;
                        l1.StartY        = l.EndY;
                        l1.EndX          = l.EndX;

                        if (m_i % 2 == 0)
                        {
                            l1.EndY = l.StartY + (matchup_height + matchup_gap_y) / 2.0f;
                        }
                        else
                        {
                            l1.EndY = l.StartY - (matchup_height + matchup_gap_y) / 2.0f;
                        }
                        doc.Children.Add(l1);

                        //Last horizontal line
                        SvgLine l2 = new SvgLine();
                        l2.Stroke        = grayPainter;
                        l2.StrokeWidth   = 5;
                        l2.StrokeOpacity = 1.0f;
                        l2.FillOpacity   = 1.0f;
                        l2.StartX        = l1.EndX;
                        l2.StartY        = l1.EndY;
                        l2.EndX          = l1.EndX + round_gap / 2.0f;
                        l2.EndY          = l1.EndY;
                        doc.Children.Add(l2);
                    }
                }

                //Update Matchup gaps and offsets
                matchup_offset_y += (matchup_height + matchup_gap_y) / 2;
                matchup_gap_y     = 2 * (matchup_gap_y + matchup_height) - matchup_height;
            }

            Bitmap img = doc.Draw();

            img.Save("bracket.png");
            img.Dispose();
        }
コード例 #7
0
        //Matchups
        public void UpdateMatchup(LiteDatabase db, Matchup m)
        {
            var collections = db.GetCollection <Matchup>("matchups");

            collections.Update(m);
        }
コード例 #8
0
        //Bracket
        public void registerBracket(MySqlConnection conn, Tournament t, ulong tourn_id)
        {
            setTournamentBracketGeneratedStatus(conn, tourn_id, true);
            setTournamentRoundNumber(conn, tourn_id, t.bracket.Rounds.Count);

            for (int i = t.bracket.Rounds.Count - 1; i >= 0; i--)
            {
                Round r = t.bracket.Rounds[i];
                for (int j = 0; j < r.Matchups.Count; j++)
                {
                    Matchup m = r.Matchups[j];
                    //Register Matchup to DB
                    string q   = "INSERT INTO matchups (tournament_id, team1_id, team2_id, next_matchup_id, round_id, team1_reported_winner_id, team2_reported_winner_id) VALUES (@tournament_id, @team1_id, @team2_id, @next_matchup_id, @round_id, @team1_reported_winner_id, @team2_reported_winner_id)";
                    var    cmd = GenerateCommand(conn, q);
                    cmd.Parameters.AddWithValue("@tournament_id", tourn_id);
                    cmd.Parameters.AddWithValue("@round_id", i);

                    //Team1
                    if (m.Team1 != null)
                    {
                        if (m.Team1.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team1_id", m.Team1.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                    }

                    //Team2
                    if (m.Team2 != null)
                    {
                        if (m.Team2.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team2_id", m.Team2.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                    }


                    //Team1 reported winner
                    if (m.Team1ReportedWinner != null)
                    {
                        if (m.Team1ReportedWinner.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team1_reported_winner_id", m.Team1ReportedWinner.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                    }

                    //Team2 reported winner
                    if (m.Team2ReportedWinner != null)
                    {
                        if (m.Team2ReportedWinner.IsDummy)
                        {
                            cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@team2_reported_winner_id", m.Team2ReportedWinner.UID);
                        }
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                    }

                    //Next Match
                    if (m.Next != null)
                    {
                        cmd.Parameters.AddWithValue("@next_matchup_id", m.Next.UID);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@next_matchup_id", DBNull.Value);
                    }

                    MySqlDataReader rdr         = cmd.ExecuteReader();
                    long            matchup_uid = cmd.LastInsertedId;
                    m.UID = matchup_uid;
                    rdr?.Close();
                }
            }
        }
コード例 #9
0
        public void getTournamentBracket(MySqlConnection conn, ref Tournament tourney, long tourn_id)
        {
            string q = string.Format("SELECT * FROM matchups WHERE tournament_id = '{0}' ORDER BY ID DESC", tourn_id);

            MySqlDataReader rdr = ExecuteQuery(conn, q);

            //Populate Rounds
            tourney.CreateBracket();

            while (rdr.Read())
            {
                long _uid    = rdr.GetInt64(rdr.GetOrdinal("ID"));
                int  ordinal = rdr.GetOrdinal("team1_id");

                ordinal = rdr.GetOrdinal("team1_id");
                long _team1_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                ordinal = rdr.GetOrdinal("team2_id");
                long _team2_id          = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                bool status_in_progress = rdr.GetBoolean(rdr.GetOrdinal("status_in_progress"));
                ordinal = rdr.GetOrdinal("next_matchup_id");
                long _next_matchup_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetInt64(ordinal);
                ordinal = rdr.GetOrdinal("winner_id");
                ulong _winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                int   _round_Id  = rdr.GetInt32(rdr.GetOrdinal("round_id"));
                ordinal = rdr.GetOrdinal("team1_reported_winner_id");
                ulong _team1_reported_winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                ordinal = rdr.GetOrdinal("team2_reported_winner_id");
                ulong  _team2_reported_winner_id = rdr.IsDBNull(ordinal) ? 0 : rdr.GetUInt64(ordinal);
                string lobby_name = rdr.GetString(rdr.GetOrdinal("lobby_name"));
                string lobby_pass = rdr.GetString(rdr.GetOrdinal("lobby_pass"));

                Matchup m = new Matchup();
                m.UID       = _uid;
                m.RoundID   = _round_Id;
                m.LobbyName = lobby_name;
                m.LobbyPass = lobby_pass;

                if (_team1_id > 0)
                {
                    m.Team1 = tourney.getTeamByUID(_team1_id);
                }
                else
                {
                    m.Team1 = null;
                }
                if (_team2_id > 0)
                {
                    m.Team2 = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Team2 = null;
                }

                //Reported Winners
                if (_team1_reported_winner_id > 0)
                {
                    m.Team1ReportedWinner = tourney.getTeamByUID(_team1_id);
                }
                else
                {
                    m.Team1ReportedWinner = null;
                }
                if (_team2_reported_winner_id > 0)
                {
                    m.Team2ReportedWinner = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Team2ReportedWinner = null;
                }

                if (_winner_id > 0)
                {
                    m.Winner = tourney.getTeamByUID(_team2_id);
                }
                else
                {
                    m.Winner = null;
                }

                if (_next_matchup_id > 0)
                {
                    m.Next = tourney.getmatchupByUID(_next_matchup_id);
                }

                m.InProgress = status_in_progress; //Winner setting can mess up stuff
                tourney.bracket.Rounds[_round_Id].Matchups.Add(m);
            }
            rdr.Close();
        }
コード例 #10
0
        public void ApplySingleMatchupUpdate(MySqlConnection conn, Matchup m, ref Tournament t)
        {
            //Update Matchup to DB
            string q   = "UPDATE matchups SET status_in_progress = @status_in_progress, team1_id=@team1_id, team2_id=@team2_id, winner_id=@winner_id, team1_reported_winner_id=@team1_reported_winner_id, team2_reported_winner_id=@team2_reported_winner_id, lobby_name=@lobby_name, lobby_pass=@lobby_pass WHERE tournament_id = @tournament_id AND ID = @uid";
            var    cmd = GenerateCommand(conn, q);

            cmd.Parameters.AddWithValue("@tournament_id", t.info.UID);
            cmd.Parameters.AddWithValue("@uid", m.UID);
            cmd.Parameters.AddWithValue("@status_in_progress", m.InProgress);
            cmd.Parameters.AddWithValue("@lobby_name", m.LobbyName);
            cmd.Parameters.AddWithValue("@lobby_pass", m.LobbyPass);

            //Team1
            if (m.Team1 != null)
            {
                if (m.Team1.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team1_id", m.Team1.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team1_id", DBNull.Value);
            }

            //Team2
            if (m.Team2 != null)
            {
                if (m.Team2.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team2_id", m.Team2.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team2_id", DBNull.Value);
            }

            //Team1 reported winner
            if (m.Team1ReportedWinner != null)
            {
                if (m.Team1ReportedWinner.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team1_reported_winner_id", m.Team1ReportedWinner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team1_reported_winner_id", DBNull.Value);
            }

            //Team2 reported winner
            if (m.Team2ReportedWinner != null)
            {
                if (m.Team2ReportedWinner.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@team2_reported_winner_id", m.Team2ReportedWinner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@team2_reported_winner_id", DBNull.Value);
            }

            //Winner
            if (m.Winner != null)
            {
                if (m.Team2.IsDummy)
                {
                    cmd.Parameters.AddWithValue("@winner_id", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@winner_id", m.Winner.UID);
                }
            }
            else
            {
                cmd.Parameters.AddWithValue("@winner_id", DBNull.Value);
            }

            //Next Match
            if (m.Next != null)
            {
                cmd.Parameters.AddWithValue("@next_matchup_id", m.Next.UID);
            }
            else
            {
                cmd.Parameters.AddWithValue("@next_matchup_id", DBNull.Value);
            }

            //Lobby Info

            MySqlDataReader rdr = cmd.ExecuteReader();

            rdr?.Close();
        }