Пример #1
0
        public TournamentBracket(int teams, bool flat)
        {
            this.Teams = teams;
            Root       = new Collection <Bracket>();

            if (flat)
            {
                maxDepth = 0;
                for (int i = 1; i < teams + 1; i++)
                {
                    Bracket rootBracket = new Bracket();
                    rootBracket.BuildTree(0, i, i, null);
                    Root.Add(rootBracket);
                }
            }
            else
            {
                Bracket rootBracket = new Bracket();
                maxDepth = rootBracket.BuildTree(0, 0, teams, null);
                Root.Add(rootBracket);
            }
        }
Пример #2
0
        public int BuildTree(int deepth, int min, int max, Bracket parent)
        {
            Deepth = deepth;
            Parent = parent;

            int diff   = max - min;
            int middle = min + Convert.ToInt32(Math.Ceiling(diff / 2.0));

            int deepth1 = deepth, deepth2 = deepth;

            if (middle > min && middle < max)
            {
                Left    = new Bracket();
                deepth1 = Left.BuildTree(deepth + 1, min, middle, this);
            }
            if (middle < max)
            {
                Right   = new Bracket();
                deepth2 = Right.BuildTree(deepth + 1, middle, max, this);
            }

            if (Left == null && Right == null)
            {
                Current = middle;
            }

            if (deepth1 > deepth2)
            {
                Round = deepth1 - deepth + 1;                 // Starting with 1
                return(deepth1);
            }
            else
            {
                Round = deepth2 - deepth + 1;                 // Starting with 1
                return(deepth2);
            }
        }