Exemplo n.º 1
0
        private bool SetNextDepthInLoosers(tournamentMatchBracket baseMatch, bool recursive)
        {
            bool ret = false;

            if ((baseMatch.Opponent1PreviousMatch != null) &&
                (loosersBracketMatchesIds.Contains(baseMatch.Opponent1PreviousMatch.MatchId)))
            {
                ((tournamentMatchBracket)_matches[baseMatch.Opponent1PreviousMatch.MatchId]).Depth = baseMatch.Depth + 1;
                if (recursive)
                {
                    SetNextDepthInLoosers(((tournamentMatchBracket)_matches[baseMatch.Opponent1PreviousMatch.MatchId]), recursive);
                }
                ret = true;
            }
            if ((baseMatch.Opponent2PreviousMatch != null) &&
                (loosersBracketMatchesIds.Contains(baseMatch.Opponent2PreviousMatch.MatchId)))
            {
                ((tournamentMatchBracket)_matches[baseMatch.Opponent2PreviousMatch.MatchId]).Depth = baseMatch.Depth + 1;
                if (recursive)
                {
                    SetNextDepthInLoosers(((tournamentMatchBracket)_matches[baseMatch.Opponent2PreviousMatch.MatchId]), recursive);
                }
                ret = true;
            }
            _tournamentLoosersDepth = Math.Max(baseMatch.Depth, _tournamentLoosersDepth);

            return(ret);
        }
Exemplo n.º 2
0
        private bool AddMatch(tournamentMatchBracket newMatch)
        {
            if (!_matches.ContainsKey(newMatch.MatchId))
            {
                _matches.Add(newMatch.MatchId, newMatch);
            }

            return(true);
        }
Exemplo n.º 3
0
        private void AddParentMatchesControls(Panel panelBracket, TournamentMatchControl currentMatchControl, tournamentMatchBracket match, int tournamentHeight, bool winnersBracket)
        {
            int verticalMargin   = 5;
            int horizontalMargin = 10;

            bool addOpponent1PreviousMatch = (match.Opponent1PreviousMatch != null) &&
                                             (((match.Opponent1PreviousMatch.InWinnersBracket) && winnersBracket) ||
                                              ((!match.Opponent1PreviousMatch.InWinnersBracket) && !winnersBracket));
            bool addOpponent2PreviousMatch = (match.Opponent2PreviousMatch != null) &&
                                             (((match.Opponent2PreviousMatch.InWinnersBracket) && winnersBracket) ||
                                              ((!match.Opponent2PreviousMatch.InWinnersBracket) && !winnersBracket));
            Point opp1PreviousMatchLocation = new Point(currentMatchControl.Location.X - currentMatchControl.Width - horizontalMargin,
                                                        currentMatchControl.Location.Y);
            Point opp2PreviousMatchLocation = new Point(currentMatchControl.Location.X - currentMatchControl.Width - horizontalMargin,
                                                        currentMatchControl.Location.Y);
            bool samePreviousMatch = (match.Opponent1PreviousMatch != null) && (match.Opponent2PreviousMatch != null) &&
                                     (match.Opponent1PreviousMatch.MatchId == match.Opponent2PreviousMatch.MatchId);

            if (addOpponent1PreviousMatch && addOpponent2PreviousMatch &&
                !samePreviousMatch)
            {
                opp1PreviousMatchLocation = new Point(currentMatchControl.Location.X - currentMatchControl.Width - horizontalMargin,
                                                      currentMatchControl.Location.Y - Math.Max((currentMatchControl.Height + verticalMargin) / 2, tournamentHeight / (int)Math.Pow(2, (match.Opponent1PreviousMatch.Depth - 1))));
                opp2PreviousMatchLocation = new Point(currentMatchControl.Location.X - currentMatchControl.Width - horizontalMargin,
                                                      currentMatchControl.Location.Y + Math.Max((currentMatchControl.Height + verticalMargin) / 2, tournamentHeight / (int)Math.Pow(2, (match.Opponent2PreviousMatch.Depth - 1))));
            }

            if (addOpponent1PreviousMatch)
            {
                TournamentMatchControl opp1PreviousMatchControl = new TournamentMatchControl();
                opp1PreviousMatchControl.MatchId   = match.Opponent1PreviousMatch.MatchIdentifierInt;
                opp1PreviousMatchControl.Opponent1 = match.Opponent1PreviousMatch.Opponent1 != null ? match.Opponent1PreviousMatch.Opponent1.Name : "";
                opp1PreviousMatchControl.Opponent2 = match.Opponent1PreviousMatch.Opponent2 != null ? match.Opponent1PreviousMatch.Opponent2.Name : "";
                opp1PreviousMatchControl.SetTooltip(match.Opponent1PreviousMatch.MatchRoundAlias);
                opp1PreviousMatchControl.Location = opp1PreviousMatchLocation;

                panelBracket.Controls.Add(opp1PreviousMatchControl);
                AddParentMatchesControls(panelBracket, opp1PreviousMatchControl, match.Opponent1PreviousMatch, tournamentHeight, winnersBracket);
            }

            if (addOpponent2PreviousMatch && !samePreviousMatch)
            {
                TournamentMatchControl opp2PreviousMatchControl = new TournamentMatchControl();
                opp2PreviousMatchControl.MatchId   = match.Opponent2PreviousMatch.MatchIdentifierInt;
                opp2PreviousMatchControl.Opponent1 = match.Opponent2PreviousMatch.Opponent1 != null ? match.Opponent2PreviousMatch.Opponent1.Name : "";
                opp2PreviousMatchControl.Opponent2 = match.Opponent2PreviousMatch.Opponent2 != null ? match.Opponent2PreviousMatch.Opponent2.Name : "";
                opp2PreviousMatchControl.SetTooltip(match.Opponent2PreviousMatch.MatchRoundAlias);
                opp2PreviousMatchControl.Location = opp2PreviousMatchLocation;

                panelBracket.Controls.Add(opp2PreviousMatchControl);
                AddParentMatchesControls(panelBracket, opp2PreviousMatchControl, match.Opponent2PreviousMatch, tournamentHeight, winnersBracket);
            }
        }
Exemplo n.º 4
0
        private void FillWinnersAndLoosersMatches()
        {
            // Fill main structure
            foreach (KeyValuePair <int, tournamentMatch> item in _matches)
            {
                if (((tournamentMatchBracket)item.Value).Opponent1PreviousMatch != null)
                {
                    if (((tournamentMatchBracket)item.Value).Opponent1LoosePreviousMatch)
                    {
                        ((tournamentMatchBracket)item.Value).Opponent1PreviousMatch.LooserNextMatch = (tournamentMatchBracket)item.Value;
                    }
                    else
                    {
                        ((tournamentMatchBracket)item.Value).Opponent1PreviousMatch.WinnerNextMatch = (tournamentMatchBracket)item.Value;
                    }
                }

                if (((tournamentMatchBracket)item.Value).Opponent2PreviousMatch != null)
                {
                    if (((tournamentMatchBracket)item.Value).Opponent2LoosePreviousMatch)
                    {
                        ((tournamentMatchBracket)item.Value).Opponent2PreviousMatch.LooserNextMatch = (tournamentMatchBracket)item.Value;
                    }
                    else
                    {
                        ((tournamentMatchBracket)item.Value).Opponent2PreviousMatch.WinnerNextMatch = (tournamentMatchBracket)item.Value;
                    }
                }
            }
            foreach (KeyValuePair <int, tournamentMatch> item in _matches)
            {
                if (((tournamentMatchBracket)item.Value).WinnerNextMatch != null)
                {
                    ((tournamentMatchBracket)item.Value).WinnerNextMatch = _matches[((tournamentMatchBracket)item.Value).WinnerNextMatch.MatchId] as tournamentMatchBracket;
                }
                if (((tournamentMatchBracket)item.Value).LooserNextMatch != null)
                {
                    ((tournamentMatchBracket)item.Value).LooserNextMatch = _matches[((tournamentMatchBracket)item.Value).LooserNextMatch.MatchId] as tournamentMatchBracket;
                }
            }

            // Update winner's bracket structure
            foreach (int item in WinnersBracketMatchesIds)
            {
                ((tournamentMatchBracket)_matches[item]).MatchRoundAlias = String.Format("Winner's bracket, round {0}", _tournamentWinnersDepth - ((tournamentMatchBracket)_matches[item]).Depth);
            }

            // Update looser's bracket structure
            // First remove final matches (grand final and bracket reset) from looser's bracket
            LoosersBracketMatchesIds.Remove(FinalMatch.MatchId);
            foreach (int item in LoosersBracketMatchesIds)
            {
                if (((tournamentMatchBracket)_matches[item]).WinnerNextMatch.MatchId == FinalMatch.Opponent1PreviousMatch.MatchId)
                {
                    _loosersFinalMatch       = ((tournamentMatchBracket)_matches[item]);
                    _loosersFinalMatch.Depth = 0;
                    _tournamentLoosersDepth  = 1;
                    SetNextDepthInLoosers(_loosersFinalMatch, true);
                }
            }
            if (_loosersFinalMatch == null)
            {
                if (!FinalMatch.Opponent1PreviousMatch.InWinnersBracket && FinalMatch.Opponent2PreviousMatch.InWinnersBracket)
                {
                    _loosersFinalMatch       = (FinalMatch.Opponent1PreviousMatch);
                    _loosersFinalMatch.Depth = 0;
                    _tournamentLoosersDepth  = 1;
                    SetNextDepthInLoosers(_loosersFinalMatch, true);
                }
                if (FinalMatch.Opponent1PreviousMatch.InWinnersBracket && !FinalMatch.Opponent2PreviousMatch.InWinnersBracket)
                {
                    _loosersFinalMatch       = (FinalMatch.Opponent2PreviousMatch);
                    _loosersFinalMatch.Depth = 0;
                    _tournamentLoosersDepth  = 1;
                    SetNextDepthInLoosers(_loosersFinalMatch, true);
                }
            }
            foreach (int item in LoosersBracketMatchesIds)
            {
                ((tournamentMatchBracket)_matches[item]).MatchRoundAlias = String.Format("Looser's bracket, round {0}", _tournamentLoosersDepth - ((tournamentMatchBracket)_matches[item]).Depth);
            }
        }
Exemplo n.º 5
0
        private tournamentMatchBracket AddMatchToTournament(Dictionary <int, wr_Match> matchPool, int baseMatchId, int matchDepth, bool isInLoosersBracket)
        {
            int opponent1Id;
            int opponent2Id;

            int.TryParse(matchPool[baseMatchId].Player1Id, out opponent1Id);
            int.TryParse(matchPool[baseMatchId].Player2Id, out opponent2Id);

            tournamentMatchBracket currentMatch = new tournamentMatchBracket(baseMatchId,
                                                                             matchPool[baseMatchId].Identifier,
                                                                             GetParticipantFromId(opponent1Id),
                                                                             GetParticipantFromId(opponent2Id),
                                                                             new matchStation(),
                                                                             matchPool[baseMatchId].Player1Points,
                                                                             matchPool[baseMatchId].Player2Points,
                                                                             matchPool[baseMatchId].Player1IsPrereqMatchLooserField == "true",
                                                                             matchPool[baseMatchId].Player2IsPrereqMatchLooserField == "true",
                                                                             tournamentMatch.MatchStatus.NotRunYet);

            currentMatch.Depth = matchDepth;

            bool player1PrevMatchLoose = false;
            bool player2PrevMatchLoose = false;

            int player1PreviousMatchId = -1;
            int player2PreviousMatchId = -1;

            // In looser's bracket, consider previous match only if winning
            if (matchPool[baseMatchId].Player1PrereqMatchIdField != null)
            {
                player1PreviousMatchId = int.Parse(matchPool[baseMatchId].Player1PrereqMatchIdField);
                if (matchPool[baseMatchId].Player1IsPrereqMatchLooserField == "true")
                {
                    player1PrevMatchLoose = true;
                }

                //    if (matchPool[baseMatchId].Player1PrereqMatchIdField == matchPool[baseMatchId].Player2PrereqMatchIdField)
                //{
                //    tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, matchId, matchDepth + 1, false);
                //    currentMatch.Opponent1PreviousMatch = player1PrereqMatch;
                //    ((tournamentMatchBracket)_matches[matchId]).WinnerNextMatch = currentMatch;
                //}
                //else if (matchPool[baseMatchId].Player1IsPrereqMatchLooserField == "false")
                //{
                //    tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, matchId, matchDepth + 1, isInLoosersBracket);
                //    currentMatch.Opponent1PreviousMatch = player1PrereqMatch;
                //    ((tournamentMatchBracket)_matches[matchId]).LooserNextMatch = currentMatch;
                //}
                //else if(matchPool[baseMatchId].Player1IsPrereqMatchLooserField == "true")
                //{
                //    tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, matchId, matchDepth + 1, false);
                //    currentMatch.Opponent1PreviousMatch = player1PrereqMatch;
                //    ((tournamentMatchBracket)_matches[matchId]).LooserNextMatch = currentMatch;
                //    player1PrevMatchLoose = true;
                //}
            }

            if (matchPool[baseMatchId].Player2PrereqMatchIdField != null)
            {
                player2PreviousMatchId = int.Parse(matchPool[baseMatchId].Player2PrereqMatchIdField);
                if (matchPool[baseMatchId].Player2IsPrereqMatchLooserField == "true")
                {
                    player2PrevMatchLoose = true;
                }

                //if ((matchPool[baseMatchId].Player2PrereqMatchIdField == matchPool[baseMatchId].Player2PrereqMatchIdField) ||
                //    (matchPool[baseMatchId].Player2IsPrereqMatchLooserField == "false"))
                //{
                //    tournamentMatchBracket player2PrereqMatch = AddMatchToTournament(matchPool, matchId, matchDepth + 1, false);
                //    currentMatch.Opponent1PreviousMatch = player2PrereqMatch;
                //    ((tournamentMatchBracket)_matches[matchId]).WinnerNextMatch = currentMatch;
                //}
                //else if (matchPool[baseMatchId].Player2IsPrereqMatchLooserField == "true")
                //{
                //    if (!isInLoosersBracket)
                //    {
                //        tournamentMatchBracket player2PrereqMatch = AddMatchToTournament(matchPool, matchId, matchDepth + 1, true);
                //        currentMatch.Opponent1PreviousMatch = player2PrereqMatch;
                //        ((tournamentMatchBracket)_matches[matchId]).LooserNextMatch = currentMatch;
                //    }
                //    player2PrevMatchLoose = true;
                //}
            }

            isInLoosersBracket = isInLoosersBracket || (player1PrevMatchLoose && player2PrevMatchLoose);

            if (isInLoosersBracket)
            {
                if (player1PreviousMatchId != -1)
                {
                    if (!player1PrevMatchLoose)
                    {
                        tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, player1PreviousMatchId, matchDepth + 1, true);
                        currentMatch.Opponent1PreviousMatch = player1PrereqMatch;
                    }
                    else
                    {
                        //tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, player1PreviousMatchId, matchDepth + 1, false);
                        currentMatch.Opponent1PreviousMatch = (tournamentMatchBracket)_matches[player1PreviousMatchId];
                    }
                    ((tournamentMatchBracket)_matches[player1PreviousMatchId]).WinnerNextMatch = currentMatch;
                }

                if (player2PreviousMatchId != -1)
                {
                    if (!player2PrevMatchLoose)
                    {
                        tournamentMatchBracket player2PrereqMatch = AddMatchToTournament(matchPool, player2PreviousMatchId, matchDepth + 1, true);
                        currentMatch.Opponent2PreviousMatch = player2PrereqMatch;
                    }
                    else
                    {
                        //tournamentMatchBracket player2PrereqMatch = AddMatchToTournament(matchPool, player2PreviousMatchId, matchDepth + 1, false);
                        currentMatch.Opponent2PreviousMatch = (tournamentMatchBracket)_matches[player2PreviousMatchId];
                    }
                    ((tournamentMatchBracket)_matches[player2PreviousMatchId]).WinnerNextMatch = currentMatch;
                }
            }
            else
            {
                if (player1PreviousMatchId != -1)
                {
                    bool previousMatchInLoosers = false;
                    if (!player1PrevMatchLoose)
                    {
                        // if 2 matches before, player1 loosed, its previous match is in looser's
                        if (matchPool[player1PreviousMatchId].Player1IsPrereqMatchLooserField == "true")
                        {
                            previousMatchInLoosers = true;
                        }
                    }
                    tournamentMatchBracket player1PrereqMatch = AddMatchToTournament(matchPool, player1PreviousMatchId, matchDepth + 1, previousMatchInLoosers);
                    currentMatch.Opponent1PreviousMatch = player1PrereqMatch;
                    ((tournamentMatchBracket)_matches[player1PreviousMatchId]).WinnerNextMatch = currentMatch;
                }

                if (player2PreviousMatchId != -1)
                {
                    bool previousMatchInLoosers = false;
                    if (!player2PrevMatchLoose)
                    {
                        // if 2 matches before, player1 loosed, its previous match is in looser's
                        if (matchPool[player2PreviousMatchId].Player1IsPrereqMatchLooserField == "true")
                        {
                            previousMatchInLoosers = true;
                        }
                    }
                    tournamentMatchBracket player2PrereqMatch = AddMatchToTournament(matchPool, player2PreviousMatchId, matchDepth + 1, previousMatchInLoosers);
                    currentMatch.Opponent2PreviousMatch = player2PrereqMatch;
                    ((tournamentMatchBracket)_matches[player2PreviousMatchId]).WinnerNextMatch = currentMatch;
                }
            }

            AddMatch(currentMatch);
            if (isInLoosersBracket)
            {
                if (!LoosersBracketMatchesIds.Contains(currentMatch.MatchId))
                {
                    LoosersBracketMatchesIds.Add(currentMatch.MatchId);
                    ((tournamentMatchBracket)_matches[currentMatch.MatchId]).InWinnersBracket = false;
                    _tournamentLoosersDepth = Math.Max(matchDepth, _tournamentLoosersDepth);
                }
            }
            else
            {
                if (!WinnersBracketMatchesIds.Contains(currentMatch.MatchId))
                {
                    WinnersBracketMatchesIds.Add(currentMatch.MatchId);
                    ((tournamentMatchBracket)_matches[currentMatch.MatchId]).InWinnersBracket = true;
                    _tournamentWinnersDepth = Math.Max(matchDepth, _tournamentWinnersDepth);
                }
            }

            _finalMatch = currentMatch;
            return(currentMatch);
        }