コード例 #1
0
        /// <summary>
        /// Takes the ordered rankings from a *finished* Bracket,
        /// and adds those Players to a new Bracket.
        /// Moves the amount of players specified by the first bracket's data.
        /// If the first bracket is not finished, an exception is thrown.
        /// If the first bracket's "AdvancingPlayers" value is invalid, an exception is thrown.
        /// </summary>
        /// <param name="_firstBracket">Finished Bracket</param>
        /// <param name="_secondBracket">New Bracket</param>
        public void AdvancePlayersByRanking(IBracket _firstBracket, IBracket _secondBracket)
        {
            if (!(_firstBracket.IsFinished))
            {
                throw new BracketException
                          ("Can't retrieve seeds from an unfinished bracket!");
            }
            if (_firstBracket.AdvancingPlayers <= 0 ||
                _firstBracket.AdvancingPlayers > _firstBracket.NumberOfPlayers())
            {
                throw new BracketException
                          ("Invalid value for advancing player!");
            }

            // How many Players are we advancing?
            List <IPlayer> pList = new List <IPlayer>();

            pList.Capacity = _firstBracket.AdvancingPlayers;
            foreach (IPlayerScore pScore in _firstBracket.Rankings)
            {
                // For each (ordered) Rankings entry, add the relevant Player to a list:
                pList.Add(_firstBracket.Players
                          .Find(p => p.Id == pScore.Id));

                if (pList.Count == _firstBracket.AdvancingPlayers)
                {
                    break;
                }
            }

            // Apply the playerlist to the new Bracket.
            // This also clears the new Bracket's playerlist, if it isn't empty:
            _secondBracket.SetNewPlayerlist(pList);
        }
コード例 #2
0
 public Bracket(IService services, IBracket bracket, BracketModel model)
 {
     this.services     = services;
     this.bracket      = bracket;
     this.model        = model;
     this.groupBracket = bracket as IGroupStage;
     IsLocked          = model.IsLocked;
     Init();
 }
コード例 #3
0
ファイル: IBracket.cs プロジェクト: simonl/PracticalCompiler
 public bool Equals(IBracket <B> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(EqualityComparer <B> .Default.Equals(Type, other.Type) && Boundary == other.Boundary);
 }
コード例 #4
0
        /// <summary>
        /// (Re)creates a Bracket object from the given BracketModel.
        /// Determines the BracketType from the Model's data,
        /// and calls the appropriate constructor.
        /// If the type is not identifiable, an exception is thrown.
        /// </summary>
        /// <param name="_model">Model of an existing Bracket</param>
        /// <returns>Recreated Bracket</returns>
        public IBracket RestoreBracket(BracketModel _model)
        {
            if (null == _model)
            {
                throw new ArgumentNullException("_model");
            }

            IBracket ret = null;

            switch (_model.BracketType.Type)
            {
            case (BracketType.SINGLE):
                ret = new SingleElimBracket(_model);
                break;

            case (BracketType.DOUBLE):
                ret = new DoubleElimBracket(_model);
                break;

            case (BracketType.STEP):
                ret = new StepladderBracket(_model);
                break;

            case (BracketType.ROUNDROBIN):
                ret = new RoundRobinBracket(_model);
                break;

            case (BracketType.SWISS):
                ret = new SwissBracket(_model);
                break;

            case (BracketType.RRGROUP):
                ret = new RoundRobinGroups(_model);
                break;

            case (BracketType.GSLGROUP):
                throw new NotImplementedException();

            //ret = new GSLGroups(_model);
            //break;
            default:
                throw new NotImplementedException();
            }
            if (0 == ret.NumberOfMatches)
            {
                // If the Model has no Matches,
                // use the data we have to generate them:
                ret.CreateBracket();
            }

            return(ret);
        }
コード例 #5
0
 /// <summary>
 /// Removes a Bracket from the bracketlist.
 /// If the given Bracket is not in the list, an exception is thrown.
 /// </summary>
 /// <param name="_bracket">Bracket to remove</param>
 public void RemoveBracket(IBracket _bracket)
 {
     if (null == _bracket)
     {
         throw new ArgumentNullException("_bracket");
     }
     if (null == Brackets)
     {
         throw new NullReferenceException
                   ("Bracket list is null; this shouldn't happen...");
     }
     if (false == Brackets.Remove(_bracket))
     {
         throw new BracketNotFoundException
                   ("Bracket not found in this tournament!");
     }
 }
コード例 #6
0
        /// <summary>
        /// Adds a Bracket object to the list of Brackets.
        /// If the list already contains this Bracket, an exception is thrown.
        /// </summary>
        /// <param name="_bracket">Bracket to add</param>
        public void AddBracket(IBracket _bracket)
        {
            if (null == _bracket)
            {
                throw new ArgumentNullException("_bracket");
            }
            if (null == Brackets)
            {
                throw new NullReferenceException
                          ("Bracket list is null; this shouldn't happen...");
            }
            if (Brackets.Contains(_bracket))
            {
                throw new DuplicateObjectException
                          ("Tournament already contains this Bracket!");
            }

            Brackets.Add(_bracket);
        }
コード例 #7
0
        public static bool AreBracketsCorrect(ICollection <IExpressionElement> elements)
        {
            int bracketsLevel = 0;

            foreach (var elem in elements)
            {
                if (!(elem is IBracket))
                {
                    continue;
                }
                IBracket bracket = (IBracket)elem;

                bracketsLevel += (int)bracket.Type;
                if (bracketsLevel < 0)
                {
                    return(false);
                }
            }
            return(bracketsLevel == 0);
        }
コード例 #8
0
        public static bool ZEqualsIBracket(IBracket ip1, IBracket ip2)
        {
            if (!ZEqualsIBracketCount(ip1, ip2))
            {
                return(false);
            }
            int size = ip1.GetParametersCount();

            IParameter[] parameters1 = ip1.GetParameters();
            IParameter[] parameters2 = ip2.GetParameters();
            for (int i = 0; i < size; i++)
            {
                var p1 = parameters1[i];
                var p2 = parameters2[i];

                ZTypeCompareEnum eqResult = ZEquals(p1, p2);
                if (!(eqResult == ZTypeCompareEnum.EQ || eqResult == ZTypeCompareEnum.SuperOf))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #9
0
 public static bool ZEqualsIBracketCount(IBracket ip1, IBracket ip2)
 {
     return(ip1.GetParametersCount() == ip2.GetParametersCount());
 }
コード例 #10
0
ファイル: GroupRound.cs プロジェクト: LOxy-Dev/LTH
        public void Init()
        {
            var participants   = new List <Player>();
            var type           = Objectives.BestOf;
            var scoreObjective = 3;

            foreach (UIElement generatorChild in _generator.Children) // Each WrapPanel in Grid
            {
                if (generatorChild.GetType() != typeof(WrapPanel))
                {
                    continue;
                }

                switch ((generatorChild as WrapPanel).Name)
                {
                // If selector box
                // If objective selector
                case "SelectorBox":
                {
                    foreach (var selectorItem in (generatorChild as WrapPanel).Children
                             ) // Each player selector (checkBox + label)
                    {
                        if (selectorItem.GetType() != typeof(WrapPanel))
                        {
                            continue;
                        }
                        var playerSelector = (WrapPanel)selectorItem;

                        foreach (var playerSelectorChild in playerSelector.Children)
                        {
                            if (playerSelectorChild.GetType() != typeof(CheckBox))
                            {
                                continue;
                            }
                            var checkBox = (CheckBox)playerSelectorChild;

                            if (checkBox.IsChecked != true)
                            {
                                continue;
                            }
                            var idOfBox = int.Parse(checkBox.Name.Replace("P", ""));

                            var player = App.Tournament.Players[idOfBox];
                            participants.Add(player);
                        }
                    }

                    break;
                }

                case "ObjectiveSelector":
                {
                    foreach (var child in (generatorChild as WrapPanel).Children)
                    {
                        if (child.GetType() == typeof(ComboBox))
                        {
                            var comboBox = (ComboBox)child;

                            // get all element in resource
                            var t  = (Array)Application.Current.FindResource("ScoreObjective");
                            var fo = t?.GetValue(0)?.ToString();
                            var bo = t?.GetValue(1)?.ToString();

                            if (comboBox.SelectedItem.Equals(bo))
                            {
                                type = Objectives.BestOf;
                            }
                            else if (comboBox.SelectedItem.Equals(fo))
                            {
                                type = Objectives.FirstTo;
                            }
                        }

                        else if (child.GetType() == typeof(IntegerUpDown))
                        {
                            var integerBox = (IntegerUpDown)child;

                            if (integerBox.Value != null)
                            {
                                scoreObjective = (int)integerBox.Value;
                            }
                        }
                    }

                    break;
                }
                }
            }

            Players = participants;
            Bracket = new Groups(Players, type, scoreObjective);
        }
コード例 #11
0
ファイル: Tokens.cs プロジェクト: simonl/PracticalCompiler
 public Bracket(IBracket <Brackets> content)
     : base(Tokens.Bracket)
 {
     Content = content;
 }