Exemplo n.º 1
0
 static Action <Action <string> > WriteClass(Message message) =>
 f =>
 {
     if (message.Parent != string.Empty)
     {
         f($"public class {message.Name} : {message.Parent}");
     }
     else
     {
         f($"public class {message.Name}");
     }
     Bracket(f)(g =>
     {
         if (message.Fields == null)
         {
             message.Fields = new Field[0];
         }
         foreach (var field in message.Fields)
         {
             WriteField(field, g);
         }
         WriteSerialize(message.Parent, message.Fields, g);
         WriteDeserialize(message.Parent, message.Fields, g);
     });
 };
Exemplo n.º 2
0
 static Action <Action <string> > WriteEnum(Enum e) =>
 f =>
 {
     f($"public enum {e.Name}");
     Bracket(f)(g =>
     {
         foreach (var constant in e.Values)
         {
             g($"{constant.Name} = {constant.Value},");
         }
     });
 };
Exemplo n.º 3
0
        public BTA(string name, string division)
        {
            Name     = name;
            Division = division;
            Buyin    = 200;
            Prize    = 1000;
            IsOver   = false;

            using (var context = new TourneyContext())
            {
                Players = context.Players.Where(p => p.Division == division).Include(p => p.Histories).Include(p => p.Accomplishments).ToList();
            }
            Players.Shuffle();
            foreach (var player in Players)
            {
                player.Bankroll -= Buyin;
            }

            Brackets = new Bracket[8];


            Brackets[0] = new Bracket($"Div {Division} - {Name} Round 1A", Players[0], Players[1], 4, 0);
            Brackets[1] = new Bracket($"Div {Division} - {Name} Round 1B", Players[2], Players[3], 4, 1);

            Brackets[2] = new Bracket($"Div {Division} - {Name} Round 1C", Players[4], Players[5], 5, 0);
            Brackets[3] = new Bracket($"Div {Division} - {Name} Round 1D", Players[6], Players[7], 5, 1);

            Brackets[4] = new Bracket($"Div {Division} - {Name} Semi-Final A", Brackets[0].Winner, Brackets[1].Winner, 6, 0);
            Brackets[5] = new Bracket($"Div {Division} - {Name} Semi-Final B", Brackets[2].Winner, Brackets[3].Winner, 6, 1);

            Brackets[6] = new Bracket($"Div {Division} - {Name} Final", Brackets[4].Winner, Brackets[5].Winner, 7, 0);

            Brackets[7] = new Bracket($"Div {Division} - {Name} Champion", Brackets[6].Winner, null, 0, 0);
        }
Exemplo n.º 4
0
 private void OnSelectedChanged(object sender, GraphicController selected)
 {
     if (selected != null && selected.Graphic is Bracket)
     {
         Visibility = Visibility.Visible;
         Validators.ClearAllErrors(grid);
         Bracket bracket = (Bracket)selected.Graphic;
         competitorSelect.Text = bracket.Competitors.ToString();
         bracketX.Text         = bracket.OriginX.ToString();
         bracketY.Text         = bracket.OriginY.ToString();
         bracketWidth.Text     = bracket.BracketWidth.ToString();
         bracketHeight.Text    = bracket.BracketHeight.ToString();
         thickness.Text        = bracket.Thickness.ToString();
         offsetX.Text          = bracket.OffsetX.ToString();
         offsetY.Text          = bracket.OffsetY.ToString();
         SolidColorBrush brush = bracket.Color as SolidColorBrush;
         red.Text   = brush.Color.R.ToString();
         green.Text = brush.Color.G.ToString();
         blue.Text  = brush.Color.B.ToString();
         if (bracket.HideHorizontal)
         {
             hideHorizontal.IsChecked = true;
         }
         if (bracket.HideVertical)
         {
             hideVertical.IsChecked = true;
         }
     }
     else
     {
         Visibility = Visibility.Collapsed;
     }
 }
Exemplo n.º 5
0
        public async Task <ActionResult <Bracket> > PostBracket(Bracket bracket)
        {
            _context.Bracket.Add(bracket);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBracket", new { id = bracket.Id }, bracket));
        }
Exemplo n.º 6
0
        private void BracketHelper(
            Stack <IPrecedenceMember> precedenceStack,
            Queue <IEquationMember> outputQueue,
            Stack <Function> functionStack, Bracket bracket)
        {
            if (bracket.Equals(Bracket.LeftBracket))
            {
                precedenceStack.Push(bracket);
            }
            else if (precedenceStack.Count == 0)
            {
                throw new ArgumentException();
            }
            else if (bracket.Equals(Bracket.RightBracket))
            {
                while (!precedenceStack.Peek().Equals(Bracket.LeftBracket))
                {
                    if (precedenceStack.Count < 1)
                    {
                        throw new ArgumentException("Unbalanced parentheses");
                    }
                    outputQueue.Enqueue(precedenceStack.Pop());
                }
                precedenceStack.Pop();
            }
            else
            {
                throw new NotImplementedException();
            }

            if (precedenceStack.Count() > 0 && precedenceStack.Peek() is Function)
            {
                functionStack.Pop();
            }
        }
Exemplo n.º 7
0
    //make a one sided bracket. Returns winner
    public GameObject MakeBracket(List <GameObject> nodes, float xDist, float yDist, float startX, int nodeStart)
    {
        List <GameObject> currentBracket = new List <GameObject>();

        for (int i = 0; i < nodes.Count; i++)
        {
            GameObject go = new GameObject();

            go.transform.SetParent(this.gameObject.transform);

            Bracket b = go.AddComponent <Bracket>();
            b.loseCurveX       = this.xDie;
            b.loseCurveY       = this.yDie;
            b.number           = nodeStart + i;
            b.singleContestant = true;
            Vector3 pos = new Vector3(startX, -yDist * i, 0);
            go.transform.localPosition = pos;
            go.name = b.ToString();
            this.allBaseBrackets.Add(go);
            currentBracket.Add(go);
        }

        List <GameObject> expanded = currentBracket;
        int counter = 0;

        while (expanded.Count > 1)
        {
            expanded = ExpandBracket(expanded, xDist);
            counter++;
        }
        return(expanded[0]);
    }
Exemplo n.º 8
0
        private bool TryParse(char c, out Bracket bracket)
        {
            bracket = null;
            switch (c)
            {
            case '{':
                bracket = new Bracket(BracketType.Brace, BracketDirection.Opening);
                break;

            case '(':
                bracket = new Bracket(BracketType.Parenthesis, BracketDirection.Opening);
                break;

            case '[':
                bracket = new Bracket(BracketType.SquareBracket, BracketDirection.Opening);
                break;

            case '}':
                bracket = new Bracket(BracketType.Brace, BracketDirection.Closing);
                break;

            case ')':
                bracket = new Bracket(BracketType.Parenthesis, BracketDirection.Closing);
                break;

            case ']':
                bracket = new Bracket(BracketType.SquareBracket, BracketDirection.Closing);
                break;

            default:
                return(false);
            }
            return(true);
        }
Exemplo n.º 9
0
        private void defineFields()
        {
            Thickness1     = Block.GetPropValue <int>(PropNameThickness1);
            Thickness2     = Block.GetPropValue <int>(PropNameThickness2);
            Height         = Block.GetPropValue <int>(PropNameHeight);
            Outline        = Block.GetPropValue <int>(PropNameOutline);
            ArmVerticCount = Block.GetPropValue <int>(PropNameArmVerticCount);
            var    concrete = Block.GetPropValue <string>(PropNameConcrete);
            double volume   = getVolume();

            Concrete = new ConcreteH(concrete, volume, this);
            Concrete.Calc();
            // Определние вертикальной арматуры
            ArmVertic = defineVerticArm(ArmVerticCount, PropNameArmVerticDiam, PropNameArmVerticPos);
            // Определние горизонтальной арматуры
            ArmHor = defineArmHor(Thickness1 + Thickness2, PropNameArmHorDiam, PropNameArmHorPos, PropNameArmHorStep);
            // Скоба 1
            Bracket1Length = Block.GetPropValue <int>(PropNameBracket1Len, false);
            Bracket1       = defineEndBracket(PropNameBracket1Diam, PropNamePosBracket1, PropNameBracket1Step,
                                              Bracket1Length, Thickness1, ArmVertic.Diameter);
            // Скоба 2
            Bracket2Length = Block.GetPropValue <int>(PropNameBracket2Len, false);
            Bracket2       = defineEndBracket(PropNameBracket2Diam, PropNamePosBracket2, PropNameBracket2Step,
                                              Bracket2Length, Thickness2, ArmVertic.Diameter);

            // Если диам вертик арм >= 20, то 4 стержня гнутся.
            checkBentBarDirect(ArmVertic, 4);
        }
Exemplo n.º 10
0
        public FootballPoolViewModel saveBracket([FromBody] Bracket bracket)
        {
            List <Alert> errors = matchupService.validateBracket(bracket).ToList();

            if (errors.Count == 0)
            {
                matchupService.saveBracket(bracket, true);
            }
            else
            {
                bool hasErrors = false;
                foreach (Alert a in errors)
                {
                    if (Alert.DANGER_TYPE.Equals(a.type))
                    {
                        hasErrors = true;
                        break;
                    }
                }
                if (!hasErrors)
                {
                    matchupService.saveBracket(bracket, true);
                }
            }
            FootballPoolViewModel vm = new FootballPoolViewModel();

            vm.errors  = errors;
            vm.bracket = bracket;
            return(vm);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Edit(int id, [Bind("id,BracketName,CreatedAt,TotalRounds")] Bracket bracket)
        {
            if (id != bracket.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bracket);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BracketExists(bracket.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemplo n.º 12
0
        public void Execute()
        {
            foreach (IndentSquareBracket Bracket in Children)
            {
                //向下一行,[ 不需要缩进,后续子Bracket的缩进是建立在 [ 的缩进深度的基础上
                Bracket.Start.LineDown();

                EditPoint CurrentEditLintPoint = Bracket.Start.CreateEditPoint();
                if (CurrentEditLintPoint == null)
                {
                    continue;
                }

                //循环本区间的每行,删除空白,后面根据层级深度,添加缩进
                do
                {
                    //检查是否在在括号内,子括号内的内容,交给子括号处理
                    if (Bracket.EditLineIsInChildren(CurrentEditLintPoint))
                    {
                        CurrentEditLintPoint.LineDown();
                        continue;
                    }

                    //处理缩进,对比应该的缩进深度,大于缩进深度,则剔除,小于则添加
                    HandleIndent(Bracket, CurrentEditLintPoint);

                    CurrentEditLintPoint.LineDown();
                } while (CurrentEditLintPoint.Line <= Bracket.End.Line);//同时处理最后一个 ] 跟 [ 的深度保持一致

                //遍历执行所有的子Bracket
                Bracket.Execute();
            }
        }
Exemplo n.º 13
0
        public IEnumerable <Alert> validateBracket(Bracket b)
        {
            HashSet <Alert> errors    = new HashSet <Alert>();
            HashSet <int>   weights   = new HashSet <int>();
            int             maxWeight = b.picks.ToArray().Length;

            foreach (Pick p in b.picks)
            {
                if (0 != p.weight && weights.Contains(p.weight))
                {
                    errors.Add(new Alert(Alert.DANGER_TYPE, "Duplicate score: " + p.weight));
                }
                else
                {
                    weights.Add(p.weight);
                }
                p.matchup = getMatchupByNflId(p.nfl_id);
                if (p.matchup.game_has_started)
                {
                    errors.Add(new Alert(Alert.WARNING_TYPE, p.matchup.homeTeam.short_name + " game cant be saved b/c it already started."));
                }
                if (p.weight > maxWeight)
                {
                    errors.Add(new Alert(Alert.DANGER_TYPE, "Invalid weight: " + p.weight));
                }
            }
            return(errors);
        }
Exemplo n.º 14
0
        public void TestLoadTeams()
        {
            File.WriteAllText(TestFileName,
                              "Name,Seed,Region\n" +
                              "UCLA,1,West\n" +
                              "USC,2,South\n" +
                              "California,3,North\n");

            var bracket = new Bracket();

            bracket.LoadTeams(TestFileName);

            Assert.AreEqual(0, bracket.RoundNumber);
            Assert.AreEqual(3, bracket.Teams.Count);
            Assert.AreEqual(0, bracket.Rounds.Count);
            Assert.AreEqual(false, bracket.IsComplete());

            var teams = bracket.AllTeams.OrderBy(team => team.Seed).ToList();

            Assert.AreEqual("UCLA", teams[0].Name);
            Assert.AreEqual(1, teams[0].Seed);
            Assert.AreEqual("West", teams[0].Region);

            Assert.AreEqual("USC", teams[1].Name);
            Assert.AreEqual(2, teams[1].Seed);
            Assert.AreEqual("South", teams[1].Region);

            Assert.AreEqual("California", teams[2].Name);
            Assert.AreEqual(3, teams[2].Seed);
            Assert.AreEqual("North", teams[2].Region);
        }
Exemplo n.º 15
0
        public override bool Visit(Bracket node)
        {
            // SQLをもたないかっこはそのまま
            if (!node.HasQuery)
            {
                AddResultSql(node.OriginalValue);
                return(base.Visit(node));
            }

            if (node.Value[0] == '(')
            {
                //TODO 外だしする
                Regex regex = new Regex("(?<target>\\t*,?)\\t");
                Match match = regex.Match(_currentLine);
                if (match.Success)
                {
                    // カンマのあとのタブを消す
                    _currentLine = match.Groups["target"].Value;
                }
                AddResultSql(node.Value);
                // +3はPadが切り捨て処理なので切り上げになる
                _Indents.Push(_tabTool.Pad(string.Empty, _currentLine.Length + 3));
                AddNewLineResultSql();
            }
            else
            {
                _Indents.Pop();
                _LeftIndentSize.Pop();
                AddNewLineResultSql();
                AddResultSql(node.Value);
            }
            return(base.Visit(node));
        }
Exemplo n.º 16
0
        private void defineFields()
        {
            Length         = Block.GetPropValue <int>(PropNameLength);
            Height         = Block.GetPropValue <int>(PropNameHeight);
            Thickness      = Block.GetPropValue <int>(PropNameThickness);
            Outline        = Block.GetPropValue <int>(PropNameOutline);
            ArmVerticCount = Block.GetPropValue <int>(PropNameArmVerticCount);
            var concrete = Block.GetPropValue <string>(PropNameConcrete);

            Concrete = new ConcreteH(concrete, Length, Thickness, Height, this);
            Concrete.Calc();
            // Определние вертикальной арматуры
            ArmVertic = defineVerticArm(ArmVerticCount, PropNameArmVerticDiam, PropNameArmVerticPos);
            // Определние горизонтальной арматуры1
            ArmHor = defineArmHor(Length, PropNameArmHorDiam, PropNamePosHorArm, PropNameArmHorStep);
            // Определние горизонтальной арматуры2
            ArmHor2 = defineArmHor(Thickness, PropNameArmHorDiam2, PropNamePosHorArm2, PropNameArmHorStep2);
            // Скоба
            BracketLength = Block.GetPropValue <int>(PropNameBracketLen, false);
            Bracket       = defineEndBracket(PropNameBracketDiam, PropNamePosBracket, PropNameBracketStep,
                                             BracketLength, Thickness, ArmVertic.Diameter);

            // Если диам вертик арм >= 20, то 2 стержня гнутся.
            checkBentBarDirect(ArmVertic, 2);
        }
Exemplo n.º 17
0
        public async Task <IActionResult> PutBracket(int id, Bracket bracket)
        {
            if (id != bracket.Id)
            {
                return(BadRequest());
            }

            _context.Entry(bracket).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BracketExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        private void UpdateBracketEntrants(string[] selectedEntrants, Bracket bracketToUpdate)
        {
            if (selectedEntrants == null)
            {
                bracketToUpdate.Contenders = new List <Contender>();
                return;
            }

            var selectedEntrantsHS = new HashSet <string>(selectedEntrants);
            var bracketEntrants    = new HashSet <int>(bracketToUpdate.Contenders.Select(c => c.Entrant.EntrantID));

            foreach (var entrant in _context.Entrants)
            {
                if (selectedEntrantsHS.Contains(entrant.EntrantID.ToString()))
                {
                    if (!bracketEntrants.Contains(entrant.EntrantID))
                    {
                        bracketToUpdate.Contenders.Add(new Contender {
                            BracketID = bracketToUpdate.BracketID, EntrantID = entrant.EntrantID, Eliminated = false, RoundsAlive = 0
                        });
                    }
                }
                else
                {
                    if (bracketEntrants.Contains(entrant.EntrantID))
                    {
                        Contender contenderToRemove = bracketToUpdate.Contenders.SingleOrDefault(i => i.EntrantID == entrant.EntrantID);
                        _context.Remove(contenderToRemove);
                    }
                }
            }
        }
Exemplo n.º 19
0
        public static void Initialize(TournamentContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Brackets.Any())
            {
                return;   // DB has been seeded
            }

// ID, NAME, ROUNDFORMAT, CREATEDAT, ACTIVE

            var brackets = new Bracket[]
            {
                new Bracket {
                    ID = 1, Name = "Test Bracket", RoundFormat = 1, CreatedAt = DateTime.Now, Active = 1
                },
                new Bracket {
                    ID = 2, Name = "Test Bracket 2", RoundFormat = 1, CreatedAt = DateTime.Now, Active = 1
                }
            };

            foreach (Bracket s in brackets)
            {
                context.Brackets.Add(s);
            }
            context.SaveChanges();
        }
Exemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        startTimer = Mathf.MoveTowards(startTimer, endTimer, Time.deltaTime);
        float perc = Mathf.InverseLerp(0.0f, endTimer, startTimer);

        Vector3 pos = new Vector3();

        pos.x = Lerp(startPos.x, targetBracket.transform.position.x, xCurve.Evaluate(perc));
        pos.y = Lerp(startPos.y, targetBracket.transform.position.y, yCurve.Evaluate(perc));
        if (perc >= 1.0f)
        {
            pos.x = targetBracket.transform.position.x;
            pos.y = targetBracket.transform.position.y;
        }
        this.transform.position = pos;
        if (perc >= 1.0f)
        {
            Bracket b = targetBracket.GetComponent <Bracket>();
            if (b != null)
            {
                b.RegisterContestant(this.gameObject);
            }
            else
            {
                RotateOverTime rot = this.GetComponent <RotateOverTime>();
                if (rot != null)
                {
                    Destroy(rot);
                }
            }
        }
    }
Exemplo n.º 21
0
        public Bracket MakeBracketMemento()
        {
            var bracketMemento = Bracket;

            Bracket = null;
            return(bracketMemento);
        }
Exemplo n.º 22
0
        private static Bracket NextBracket(string file, int currentIndex)
        {
            Bracket bracket         = new Bracket();
            int     nextCurlyOpen   = file.IndexOf("{", currentIndex);
            int     nextCurlyClose  = file.IndexOf("}", currentIndex);
            int     nextSquareOpen  = file.IndexOf("[", currentIndex);
            int     nextSquareClose = file.IndexOf("]", currentIndex);

            int    minIndex   = nextCurlyOpen;
            string minBracket = "{";

            if (nextCurlyClose < minIndex)
            {
                minIndex   = nextCurlyClose;
                minBracket = "}";
            }

            if (nextSquareOpen < minIndex)
            {
                minIndex   = nextSquareOpen;
                minBracket = "[";
            }

            if (nextSquareClose < minIndex)
            {
                minIndex   = nextSquareClose;
                minBracket = "]";
            }
            bracket.BracketType = minBracket;
            bracket.Index       = minIndex;
            return(bracket);
        }
        public void GetBracket(string latex, IList <Element> container, Marker marker)
        {
            if (marker.Position >= latex.Length)
            {
                return;
            }

            var brackets = new string[] { "(", ")", "{", "}", "[", "]" };

            foreach (var bracket in brackets)
            {
                if (latex.Substring(marker.Position, 1) == bracket)
                {
                    var b = new Bracket();

                    b.Content = bracket;

                    container.Add(b);

                    marker.Position += 1;

                    break;
                }
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ScoreTeam1,ScoreTeam2,TournamentId,ParentId")] Bracket bracket)
        {
            if (id != bracket.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bracket);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BracketExists(bracket.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParentId"]     = new SelectList(_context.Bracket, "Id", "Id", bracket.ParentId);
            ViewData["TournamentId"] = new SelectList(_context.Tournament, "Id", "Game", bracket.TournamentId);
            return(View(bracket));
        }
Exemplo n.º 25
0
    public void MakeBracket(List <GameObject> nodes)
    {
        enableOnMake.SetActive(true);
        if (LeftRightSplit)
        {
            List <GameObject> left = new List <GameObject>();
            for (int i = 0; i < nodes.Count / 2; i++)
            {
                left.Add(nodes[i]);
            }
            List <GameObject> right = new List <GameObject>();
            for (int i = nodes.Count / 2; i < nodes.Count; i++)
            {
                right.Add(nodes[i]);
            }
            GameObject LeftWinner  = MakeBracket(left, xDistance, yDistance, 0, 0);
            GameObject RightWinner = MakeBracket(right, -xDistance, yDistance, (Mathf.Log(nodes.Count / 2, 2) + 1) * xDistance * 2, nodes.Count / 2);

            List <GameObject> finalBranch = new List <GameObject>();
            finalBranch.Add(LeftWinner);
            finalBranch.Add(RightWinner);
            Bracket leftb  = LeftWinner.GetComponent <Bracket>();
            Bracket rightb = RightWinner.GetComponent <Bracket>();
            leftb.wait  = rightb;
            rightb.wait = leftb;
            List <GameObject> final = ExpandBracket(finalBranch, xDistance);
            final[0].GetComponent <Bracket>().fa = this.fa;
        }
        else
        {
        }
        bam.StartChain(nodes, this.allBaseBrackets);
    }
Exemplo n.º 26
0
        public async Task <IActionResult> Post([FromBody] Bracket bracket)
        {
            await _unitOfWork.BracketRepository.PostAsync(bracket);

            await _unitOfWork.SaveAsync();

            return(Ok());
        }
Exemplo n.º 27
0
        public void GetBracketFromUrl(string url, string bracketName, string bracketContains)
        {
            Console.WriteLine("GetBracketFromUrlTest\nUrl: " + url);
            Bracket bracket = Parser.GetBracketFromUrl(url);

            Xunit.Assert.Equal(bracketName, bracket.Name);
            Xunit.Assert.True(bracket.Html.Contains(bracketContains));
        }
 /// <summary>
 /// Gets the job arguments used by the RatingChangeJob execution. 
 /// Call this before running the job.
 /// </summary>
 /// <param name="bracket">The bracket to pull leadboard for.</param>
 /// <param name="region">The region to pull leadboard for, defaults to US.</param>
 /// <returns>Dictionary populated with job keys and properties for execution.</returns>
 public static Dictionary<string, object> GetRatingChangeJobArguments(Bracket bracket, Region region = Region.US)
 {
     return new Dictionary<string, object>
     {
         { BRACKET_KEY, bracket },
         { REGION_KEY, region }
     };
 }
 public CalcElement(CombinedOperation p_CacluteFieldOperation, string p_ConstantValue, CombinedOperation p_CacluteConstantOperation, object p_Field, Bracket p_Bracket)
 {
     _Bracket = p_Bracket;
     _Field   = p_Field;
     _CacluteConstantOperation = p_CacluteConstantOperation;
     _ConstantValue            = p_ConstantValue;
     _CacluteFieldOperation    = p_CacluteFieldOperation;
 }
Exemplo n.º 30
0
        async Task ICeaSubCommand.Run(SocketSlashCommand command, DiscordSocketClient client, IReadOnlyDictionary<SlashCommandOptions, string> options, Lazy<List<Team>> lazyTeams)
        {
            Bracket bracket = LeagueManager.League.Bracket.Brackets.First();
            string stage = StageMatcher.Lookup(bracket.Rounds.Last().RoundName);
            string rematches = StageRematchFinder.FindRematches(bracket, stage);

            await command.RespondAsync(rematches, ephemeral: true);
        }
Exemplo n.º 31
0
        public static Token NewBracket(Bracket bracket)
        {
            var token = new Token(TokenType.Bracket);

            token._br = bracket;

            return(token);
        }
Exemplo n.º 32
0
			public Position(KeyValuePair<int, Object> blob) {
				object o = blob;
				Cube cube;
				Sphere sphere;
				Cone cone;
				Pyrimad pyrimad;
				if (o != null) {
					if (o.GetType() == typeof(Cube)) {
						cube = (Cube)o;
						x = cube.Length;
						y = cube.Height;
						z = cube.Depth;
						line = cube.Values.GetBracket;
						sides = cube.GetSides;
						corners = cube.GetCorners;
					}
					else if (o.GetType() == typeof(Sphere)) {
						sphere = (Sphere)o;
						x = sphere.Length;
						y = sphere.Height;
						z = sphere.Depth;
						line = sphere.Values.GetBracket;
						sides = sphere.GetSides;
						corners = sphere.GetCorners;
					}
					else if (o.GetType() == typeof(Pyrimad)) {
						pyrimad = (Pyrimad)o;
						x = pyrimad.Length;
						y = pyrimad.Height;
						z = pyrimad.Depth;
						line = pyrimad.Values.GetBracket;
						sides = pyrimad.GetSides;
						corners = pyrimad.GetCorners;
					}
					else if (o.GetType() == typeof(Cone)) {
						cone = (Cone)o;
						x = cone.Length;
						y = cone.Height;
						z = cone.Depth;
						line = cone.Values.GetBracket;
						sides = cone.GetSides;
						corners = cone.GetCorners;
					}
				} else {
					x = 0.0;
					y = 0.0;
					z = 0.0;
				}
			}
Exemplo n.º 33
0
			public Pyrimad(double x, double y, double z) {
				o = new Objects(3, new Point(x, y, z));
				Point p1 = new Point(0.0, 0.0, 0.0);
				Point p2 = new Point(o.Length, 0.0, 0.0);
				Point p3 = new Point(0.0, 0.0, o.Depth);
				Point p4 = new Point(o.Length, 0.0, o.Depth);
				Point p5 = new Point(o.Length / 2, o.Height, o.Depth / 2);
				Line l1 = new Line(p1, p2);
				Line l2 = new Line(p2, p5);
				Line l3 = new Line(p5, p1);
				Line l4 = new Line(p3, p4);
				Line l5 = new Line(p4, p5);
				Line l6 = new Line(p5, p3);
				Line l7 = new Line(p1, p3);
				Line l8 = new Line(p2, p4);
				Point left = new Point(0.0, o.Height / 2, o.Depth / 1.5);
				Point right = new Point(o.Length, o.Height / 2, o.Depth / 1.5);
				Point top = p5;
				Point bottom = new Point(o.Length / 2, 0.0, o.Depth / 2);
				Point front = new Point(o.Length / 2, o.Height / 2, 0.0);
				Point back = new Point(o.Length / 2, o.Height / 2, o.Depth / 1.5);
				pyrimad = new Bracket(left, right, bottom, front, back, l1, l2, l3, l4, l5, l6, l7, l8);
				Point botleftfront = p1;
				Point botleftback = p3;
				Point botrightfront = p2;
				Point botrightback = p4;
				Point topmid = p5;
				pyrimad.AddRef(Direction.Sides.Left, left);
				pyrimad.AddRef(Direction.Sides.Right, right);
				pyrimad.AddRef(Direction.Sides.Top, top);
				pyrimad.AddRef(Direction.Sides.Bottom, bottom);
				pyrimad.AddRef(Direction.Sides.Front, front);
				pyrimad.AddRef(Direction.Sides.Back, back);
				pyrimad.AddRef(Direction.Corners.BotLeftX, botleftfront);
				pyrimad.AddRef(Direction.Corners.BotLeftY, botleftback);
				pyrimad.AddRef(Direction.Corners.BotRightX, botrightfront);
				pyrimad.AddRef(Direction.Corners.BotRightY, botrightback);
				pyrimad.AddRef(Direction.Corners.TopMiddle, topmid);
			}
Exemplo n.º 34
0
			public Triangle(double x, double y) {
				o = new Objects(2, new Point(x, y));
				Point p1 = new Point(0.0, 0.0);
				Point p2 = new Point(o.Length, 0.0);
				Point p3 = new Point(o.Length / 2.0, o.Height);
				Line l1 = new Line(p1, p2);
				Line l2 = new Line(p2, p3);
				Line l3 = new Line(p3, p1);
				triangle = new Bracket(l1, l2, l3);
			}
Exemplo n.º 35
0
			public Cube(double x, double y, double z) {
				o = new Objects(1, new Point(x, y, z));
				Point p1 = new Point(0.0, 0.0, 0.0);
				Point p2 = new Point(o.Length, 0.0, 0.0);
				Point p3 = new Point(o.Length, o.Height, 0.0);
				Point p4 = new Point(0.0, o.Height, 0.0);
				Point p5 = new Point(0.0, 0.0, o.Depth);
				Point p6 = new Point(o.Length, 0.0, o.Depth);
				Point p7 = new Point(o.Length, o.Height, o.Depth);
				Point p8 = new Point(0.0, o.Height, o.Depth);
				Line l1 = new Line(p1, p2);
				Line l2 = new Line(p2, p3);
				Line l3 = new Line(p3, p4);
				Line l4 = new Line(p4, p1);
				Line l5 = new Line(p1, p5);
				Line l6 = new Line(p2, p6);
				Line l7 = new Line(p3, p7);
				Line l8 = new Line(p4, p8);
				Line l9 = new Line(p5, p6);
				Line l10 = new Line(p6, p7);
				Line l11 = new Line(p7, p8);
				Line l12 = new Line(p8, p6);
				Point left = new Point(0.0, o.Height / 2, o.Depth / 2);
				Point right = new Point(o.Length, o.Height / 2, o.Depth / 2);
				Point top = new Point(o.Length / 2, o.Height, o.Depth / 2);
				Point bottom = new Point(o.Length / 2, 0.0, o.Depth / 2);
				Point back = new Point(o.Length / 2, o.Height / 2, o.Depth / 2);
				Point front = new Point(o.Length / 2, o.Height / 2, 0.0);
				cube = new Bracket(left, right, top, bottom, back, front, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12);
				Point topleftfront = p4;
				Point topleftback = p8;
				Point toprightfront = p3;
				Point toprightback = p7;
				Point botleftfront = p1;
				Point botleftback = p5;
				Point botrightfront = p2;
				Point botrightback = p6;
				cube.AddRef(Direction.Sides.Left, left);
				cube.AddRef(Direction.Sides.Right, right);
				cube.AddRef(Direction.Sides.Top, top);
				cube.AddRef(Direction.Sides.Bottom, bottom);
				cube.AddRef(Direction.Sides.Front, front);
				cube.AddRef(Direction.Sides.Bottom, bottom);
				cube.AddRef(Direction.Corners.TopLeftX, topleftfront);
				cube.AddRef(Direction.Corners.TopLeftY, topleftback);
				cube.AddRef(Direction.Corners.TopRightX, toprightfront);
				cube.AddRef(Direction.Corners.TopRightY, toprightback);
				cube.AddRef(Direction.Corners.BotLeftX, botleftfront);
				cube.AddRef(Direction.Corners.BotLeftY, botleftback);
				cube.AddRef(Direction.Corners.BotRightX, botrightfront);
				cube.AddRef(Direction.Corners.BotRightY, botrightback);
			}
Exemplo n.º 36
0
        static void Main(string[] args)
        {
            int teamsize = 2;

            string peopleFile = "people.txt";

            List<string> argsList = args.ToList<string>();

            if (argsList.Contains("-c"))
            {
                int index = argsList.IndexOf("-c") + 1;

                bool parseSucc = Int32.TryParse(argsList[index], out teamsize);

                if (!parseSucc)
                    teamsize = 2;
            }
            if (argsList.Contains("-p"))
            {
                int index = argsList.IndexOf("-p") + 1;

                peopleFile = argsList[index];
            }

            try
            {
                using (FileStream fStream = new FileStream(peopleFile, FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader reader = new StreamReader(fStream))
                    {
                        List<string> names = new List<string>();
                        List<Team> teams = new List<Team>();
                        Bracket bracket = new Bracket();
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            names.Add(line);
                        }

                        names = Shuffle(names);

                        string teamsFile = string.Format("teams-{0}.txt", teamsize);

                        using (FileStream oFStream = new FileStream(teamsFile, FileMode.Create, FileAccess.ReadWrite))
                        {
                            using (StreamWriter writer = new StreamWriter(oFStream))
                            {
                                int lastIndex = 0;
                                for (int i = 0; i < names.Count - (teamsize - 1); i += teamsize)
                                {
                                    Team tempTeam = new Team();

                                    for (int j = i; j < i + teamsize; j++)
                                    {
                                        tempTeam.players.Add(names[j]);
                                    }

                                    tempTeam.teamName = string.Format("Team {0}", names[i]);
            #if DEBUG
                                    Console.WriteLine(tempTeam.ToString());
            #endif

                                    writer.WriteLine(tempTeam.ToString());

                                    lastIndex = i;

                                    teams.Add(tempTeam);
                                }

                                Team lastTeam = new Team();

                                for (int i = lastIndex + teamsize; i < names.Count; i++)
                                {

                                    lastTeam.players.Add(names[i]);

                                    lastTeam.teamName = string.Format("Team {0}", names[lastIndex + teamsize]);

                                }

                                if (lastTeam.players.Count > 0)
                                {
            #if DEBUG
                                    Console.WriteLine(lastTeam.ToString());
            #endif

                                    writer.WriteLine(lastTeam.ToString());

                                    teams.Add(lastTeam);
                                }

                                bracket.teams = bracket.FisherYatesShuffle(teams);

                                writer.WriteLine();
                                writer.WriteLine("Team Matchups: ");

            #if DEBUG
                                Console.WriteLine();
                                Console.WriteLine("Team Matchups: ");
            #endif

                                for (int i = 0; i < bracket.teams.Count - 1; i += 2)
                                {
            #if DEBUG
                                    Console.WriteLine(string.Format("{0, 30} vs {1, 30}", bracket.teams[i].teamName, bracket.teams[i + 1].teamName));
            #endif
                                    writer.WriteLine(string.Format("{0, 30} vs {1, 30}", bracket.teams[i].teamName, bracket.teams[i + 1].teamName));

                                    lastIndex = i;

                                }

                                if (lastIndex + 2 < bracket.teams.Count)
                                {
                                    writer.WriteLine();
                                    writer.WriteLine("Teams starting with a bye: ");

            #if DEBUG
                                    Console.WriteLine();
                                    Console.WriteLine("Teams starting with a bye: ");
            #endif

                                    for (int i = lastIndex + 2; i < bracket.teams.Count; i++)
                                    {
            #if DEBUG
                                        Console.WriteLine(bracket.teams[i].teamName);
            #endif
                                        writer.WriteLine(bracket.teams[i].teamName);
                                    }
                                }
            #if !DEBUG

                                Console.WriteLine("Teams saved to " + teamsFile);

            #endif

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The specified people file was not found.");
            #if DEBUG
                Console.WriteLine(ex.ToString());
            #endif
            }
        }
Exemplo n.º 37
0
 public BracketOperand(Bracket bracket)
 {
     this._bracket = bracket;
 }
Exemplo n.º 38
0
			public Sphere(double x, double y, double z) {
				o = new Objects(6, new Point(x, y, z));
				Point p1 = new Point(0.0, 0.0, 0.0);
				Point p2 = new Point(o.Length / 2, o.Height / 4, 0.0);
				Point p3 = new Point(o.Length, o.Height / 2, 0.0);
				Point p4 = new Point(o.Length / 2, o.Height / 1.5, 0.0);
				Point p5 = new Point(0.0, o.Height, 0.0);
				Point p6 = new Point(-(o.Length / 2), o.Height / 1.5, 0.0);
				Point p7 = new Point(-(o.Length), o.Height / 2, 0.0);
				Point p8 = new Point(-(o.Length / 2), o.Height / 4, 0.0);
				Point p9 = new Point(0.0, 0.0, o.Depth);
				Point p10 = new Point(o.Length / 2, o.Height / 4, o.Depth);
				Point p11 = new Point(o.Length, o.Height / 2, o.Depth);
				Point p12 = new Point(o.Length / 2, o.Height / 1.5, o.Depth);
				Point p13 = new Point(0.0, o.Height, o.Depth);
				Point p14 = new Point(-(o.Length / 2), o.Height / 1.5, o.Depth);
				Point p15 = new Point(-(o.Length), o.Height / 2, o.Depth);
				Point p16 = new Point(-(o.Length / 2), o.Height / 4, o.Depth);
				Line l1 = new Line(p1, p2, p3);
				Line l2 = new Line(p3, p4, p5);
				Line l3 = new Line(p5, p6, p7);
				Line l4 = new Line(p7, p8, p1);
				Line l5 = new Line(p9, p10, p11);
				Line l6 = new Line(p11, p12, p13);
				Line l7 = new Line(p13, p14, p15);
				Line l8 = new Line(p15, p16, p9);
				Point top = new Point(o.Length / 2, o.Height, o.Depth / 2);
				Point bottom = new Point(o.Length / 2, 0.0, o.Depth / 2);
				Point left = new Point(0.0, o.Height / 2, o.Depth / 2);
				Point right = new Point(o.Length, o.Height / 2, o.Depth / 2);
				Point front = new Point(o.Length / 2, o.Height / 2, 0.0);
				Point back = new Point(o.Length / 2, o.Height / 2, o.Depth  / 2);
				sphere = new Bracket(l1, l2, l3, l4, l5, l6, l7, l8);
				sphere.AddRef(Direction.Sides.Top, top);
				sphere.AddRef(Direction.Sides.Bottom, bottom);
				sphere.AddRef(Direction.Sides.Left, left);
				sphere.AddRef(Direction.Sides.Right, right);
				sphere.AddRef(Direction.Sides.Front, front);
				sphere.AddRef(Direction.Sides.Back, back);
			}
        /// <summary>
        /// Executes the team clustering and db insert of this job:
        /// - Checks and resets the baseline stats 
        /// - Sorts pvp stats into team members by faction and winners/losers
        /// - Clusters the team members into team based off rating change and current rating
        /// - Inserts successful clusters into database
        /// </summary>
        /// <param name="stats">The current stats pull to cluster.</param>
        /// <param name="region">The region for this pull.</param>
        /// <param name="bracket">The arena bracket for this pull.</param>
        private void ExecuteCluster(List<PvpStats> stats, Region region, Bracket bracket)
        {
            var key = new Tuple<Region, Bracket>(region, bracket);
            var baselineStats = GetPvpStatsCache(region, bracket);
            if (baselineStats.Count == 0)  // first pass, no baseline yet
            {
                SetPvpStatsCache(key, stats);
                return;
            }

            var allyWinners = new List<TeamMember>();
            var allyLosers = new List<TeamMember>(); // faction = 0
            var hordeWinners = new List<TeamMember>();
            var hordeLosers = new List<TeamMember>(); // factionId = 1

            // sort by faction and into winners and losers
            foreach (var stat in stats)
            {
                var baseStat = baselineStats.FirstOrDefault(b => b.Name.Equals(stat.Name) &&
                                                                 b.RealmSlug.Equals(stat.RealmSlug));
                if (baseStat == null)
                    continue; // player isn't in the baseline, nothing to compare against

                if (stat.Rating == baseStat.Rating)
                    continue; // no change

                var ratingChange = stat.Rating - baseStat.Rating;
                //if (ratingChange == 0) continue; // no rating change, ignore

                var character = GetCharacter(stat, region);
                var teamMember = new TeamMember // create db model
                {
                    RatingChangeValue = ratingChange,
                    CurrentRating = stat.Rating,
                    CharacterID = character.CharacterID,
                    SpecID = character.SpecID,
                    RaceID = character.RaceID,
                    FactionID = character.FactionID,
                    GenderID = character.GenderID,
                    ModifiedDate = DateTime.Now,
                    ModifiedStatus = "I",
                    ModifiedUserID = 0,
                };

                var isAlly = stat.FactionId == 0;
                var wonGame = ratingChange > 0;

                if (isAlly)
                {
                    if (wonGame)
                        allyWinners.Add(teamMember);
                    else
                        allyLosers.Add(teamMember);
                }
                else // horde
                {
                    if (wonGame)
                        hordeWinners.Add(teamMember);
                    else
                        hordeLosers.Add(teamMember);
                }
            }

            // current stats are baseline for next pass
            SetPvpStatsCache(key, stats);

            // ensure that each group has enough players to fill at least 1 team
            var teamSize = GetTeamSize(bracket);

            if (allyWinners.Count >= teamSize)
                ClusterAndInsertDb(allyWinners, teamSize, bracket);

            if (allyLosers.Count >= teamSize)
                ClusterAndInsertDb(allyLosers, teamSize, bracket);

            if (hordeWinners.Count >= teamSize)
                ClusterAndInsertDb(hordeWinners, teamSize, bracket);

            if (hordeLosers.Count >= teamSize)
                ClusterAndInsertDb(hordeLosers, teamSize, bracket);
        }
        private void ClusterAndInsertDb(List<TeamMember> membersToCluster, int teamSize, Bracket bracket)
        {
            LoggingUtil.LogMessage(DateTime.Now, $"Executing team cluster on {bracket}...", LoggingUtil.LogType.Notice);

            var teams = LeaderboardKmeans.ClusterTeams(membersToCluster, teamSize);
            if (teams == null) return; // cluster failed, most likely uneven team members / team size

            foreach (var team in teams)
            {
                team.Bracket = bracket.ToString();
                team.ModifiedDate = DateTime.Now;
                team.ModifiedStatus = "I";
                team.ModifiedUserID = 0;
            }

            DbManager.InsertTeamsAndMembers(teams);
        }
 private int GetTeamSize(Bracket bracket)
 {
     switch (bracket)
     {
         case Bracket._2v2:
             return 2;
         case Bracket._3v3:
             return 3;
         case Bracket._5v5:
             return 5;
         default:
             throw new ArgumentOutOfRangeException(nameof(bracket));
     }
 }
Exemplo n.º 42
0
			public Sphere(Sphere sphere) {
				o = new Objects(sphere.Obj);
				this.sphere = new Bracket(sphere.Values);
			}
Exemplo n.º 43
0
			public Circle(Circle circle) {
				o = new Objects(circle.Obj);
				this.circle = new Bracket(circle.Values);
			}
Exemplo n.º 44
0
			public Cone(double x, double y, double z) {
				o = new Objects(4, new Point(x, y, z));
				Point p1 = new Point(0.0, 0.0, 0.0);
				Point p2 = new Point(o.Length / 2, 0.0, o.Depth / 4);
				Point p3 = new Point(o.Length, 0.0, o.Depth / 2);
				Point p4 = new Point(o.Length / 2, 0.0, o.Depth / 1.5);
				Point p5 = new Point(0.0, 0.0, o.Depth);
				Point p6 = new Point(-(o.Length / 2), 0.0, o.Depth / 1.5);
				Point p7 = new Point(-(o.Length), 0.0, o.Depth / 2);
				Point p8 = new Point(-(o.Length / 2), 0.0, o.Depth / 4);
				Point p9 = new Point(0.0, o.Height, o.Depth / 2);
				Line l1 = new Line(p1, p2, p3);
				Line l2 = new Line(p3, p4, p5);
				Line l3 = new Line(p5, p6, p7);
				Line l4 = new Line(p7, p8, p1);
				Line l5 = new Line(p1, p9);
				Line l6 = new Line(p2, p9);
				Line l7 = new Line(p3, p9);
				Line l8 = new Line(p4, p9);
				Line l9 = new Line(p5, p9);
				Line l10 = new Line(p6, p9);
				Line l11 = new Line(p7, p9);
				Line l12 = new Line(p8, p9);
				Point top = p9;
				Point bottom = new Point(0.0, o.Length / 2, o.Depth / 2);
				cone = new Bracket(bottom, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12);
				Point botleftfront = p2;
				Point botleftback = p4;
				Point botrightfront = p6;
				Point botrightback = p8;
				cone.AddRef(Direction.Sides.Top, top);
				cone.AddRef(Direction.Sides.Bottom, bottom);
				cone.AddRef(Direction.Corners.BotLeftX, botleftfront);
				cone.AddRef(Direction.Corners.BotLeftY, botleftback);
				cone.AddRef(Direction.Corners.BotRightX, botrightfront);
				cone.AddRef(Direction.Corners.BotRightY, botrightback);
			}
Exemplo n.º 45
0
			public Circle(double x, double y) {
				o = new Objects(5, new Point(x, y));
				Point p1 = new Point(0.0, 0.0);
				Point p2 = new Point(o.Length / 2, o.Height / 4);
				Point p3 = new Point(o.Length, o.Height / 2);
				Point p4 = new Point(o.Length / 2, o.Height / 1.5);
				Point p5 = new Point(0.0, o.Height);
				Point p6 = new Point(-(o.Length / 2), o.Height / 1.5);
				Point p7 = new Point(-(o.Length), o.Height / 2);
				Point p8 = new Point(-(o.Length / 2), o.Height / 4);
				Line l1 = new Line(p1, p2, p3);
				Line l2 = new Line(p3, p4, p5);
				Line l3 = new Line(p5, p6, p7);
				Line l4 = new Line(p7, p8, p1);
				circle = new Bracket(l1, l2, l3, l4);
			}
        /// <summary>
        /// Gets the cached baseline PvpStats list from the dictionary.
        /// </summary>
        private List<PvpStats> GetPvpStatsCache(Region region, Bracket bracket)
        {
            var key = new Tuple<Region, Bracket>(region, bracket);

            if (_baselineStatsDictionary.ContainsKey(key))
                return _baselineStatsDictionary[key];

            // key doesn't exist, add new pvp stats list
            try
            {
                if (!_baselineStatsDictionary.TryAdd(key, new List<PvpStats>()))
                {
                    LoggingUtil.LogMessage(DateTime.Now, $"Throwing new exception, unable to add {key} to stats cache.");
                    throw new Exception($"unable to add { key } to stats cache.");
                }
            }
            catch (ArgumentNullException e)
            {
                LoggingUtil.LogMessage(DateTime.Now, "Null argument exception caught: " + e);
            }
            catch (OverflowException ex)
            {
                LoggingUtil.LogMessage(DateTime.Now, "Overflow exception caught: " + ex);
            }

            return _baselineStatsDictionary[key];
        }
Exemplo n.º 47
0
 void CreateOperators()
 {
     // Only one of each operation Token needs to be created
     opAdd = new Add(workStack);
     opSubtract = new Subtract(workStack);
     opMultiply = new Multiply(workStack);
     opDivide = new Divide(workStack);
     opPower = new Power(workStack);
     opBracket = new Bracket();
     opUnaryMinus = new UnaryMinus(workStack);
     opUnaryPlus = new UnaryPlus();
     opSqrt = new Sqrt(workStack);
     opSin = new Sin(workStack);
     opCos = new Cos(workStack);
     opTan = new Tan(workStack);
     opLog = new Log(workStack);
     opAsin = new Asin(workStack);
     opAcos = new Acos(workStack);
     opAtan = new Atan(workStack);
     functions = new Dictionary<string, Function>
     {
         {"sqr", opSqrt },
         {"sin", opSin },
         {"cos", opCos },
         {"tan", opTan },
         {"log", opLog },
         {"asin", opAsin },
         {"acos", opAcos },
         {"atan", opAtan }
     };
     binaryOperators = new Dictionary<char, BinaryOperator>
     {
         {'+', opAdd },
         {'-', opSubtract },
         {'*', opMultiply },
         {'/', opDivide },
         {'^',opPower }
     };
 }
Exemplo n.º 48
0
    public static List<Token> ParseTokens(String expression) {
        var variable = new Regex(@"^\s*([a-zA-Z.]+)");
        var operation = new Regex(@"^\s*(&&|\|\||!=|==|<=|>=|!|<|>)");
        var bracket = new Regex(@"^\s*([\(\)]+)");
        var constant = new Regex(@"^\s*([0-9]*\.?[0-9]+)");

        List<Token> result = new List<Token>();
        String rest = expression;
        Match match = null;
        while (rest.Length > 0) {
            match = variable.Match(rest);
            if (match.Success) {
                var text = match.Groups[0].Value.Trim();
                Token token = new Variable {
                    Text = text
                };
                result.Add(token);
                rest = CutOutOccurence(rest, text);

                continue;
            }

            match = operation.Match(rest);
            if (match.Success) {
                var text = match.Groups[0].Value.Trim();
                if (!Operators.ContainsKey(text)) {
                    UnityEngine.Debug.LogError("Неизвестный оператор " + text);
                    return null;
                }
                var op = Operators[text];
                Token token = new Operator {
                    Text = text,
                    Type = op.Type,
                    NumArgs = op.NumArgs,
                    Priority = op.Priority
                };
                result.Add(token);
                rest = CutOutOccurence(rest, text);

                continue;
            }

            match = bracket.Match(rest);
            if (match.Success) {
                var text = match.Groups[0].Value.Trim();
                if (!BracketTypes.ContainsKey(text)) {
                    UnityEngine.Debug.LogError("Неизвестный символ " + text);
                    return null;
                }
                var type = BracketTypes[text];
                Token token = new Bracket {
                    Text = text,
                    Type = type
                };
                result.Add(token);
                rest = CutOutOccurence(rest, text);

                continue;
            }

            match = constant.Match(rest);
            if (match.Success) {
                var text = match.Groups[0].Value.Trim();
                float value = Convert.ToSingle(text);
                Token token = new Contant {
                    Text = text,
                    Value = (int)value
                };
                result.Add(token);
                rest = CutOutOccurence(rest, text);

                continue;
            }

            Debug.LogError("Ошибка распознавания токенов в строке " + rest);
            return null;
        }

        return result;
    }
Exemplo n.º 49
0
 /// <summary>
 /// Constructor which initializes the state of the home screen.
 /// </summary>
 public HomeModel()
 {
     ClassModel = new ClassModel();
     CurBracket = Bracket._3v3;
     CurRegion = Region.US;
     CurCharacterList = new List<string>();
     CurSelectedSpecList = new Dictionary<int, string>();
     CurFaction = Faction.Any;
     TeamModel = new TeamModel();
 }
Exemplo n.º 50
0
			public Square(double x, double y) {
				o = new Objects(0, new Point(x, y));
				Point p1 = new Point(0.0, 0.0);
				Point p2 = new Point(o.Length, 0.0);
				Point p3 = new Point(o.Length, o.Height);
				Point p4 = new Point(0.0, o.Height);
				Line l1 = new Line(p1, p2);
				Line l2 = new Line(p2, p3);
				Line l3 = new Line(p3, p4);
				Line l4 = new Line(p4, p1);
				square = new Bracket(l1, l2, l3, l4);
			}
Exemplo n.º 51
0
			public Pyrimad(Pyrimad pyrimad) {
				o = new Objects(pyrimad.Obj);
				this.pyrimad = new Bracket(pyrimad.Values);
			}
Exemplo n.º 52
0
 public Token(Bracket bracket)
 {
     value = bracket;
     Type = bracket == Bracket.Opening ? TokenType.OpeningBracket : TokenType.ClosingBracket;
 }
Exemplo n.º 53
0
			public Square(Square square) {
				o = new Objects(square.Obj);
				this.square = new Bracket(square.Values);
			}
Exemplo n.º 54
0
			public Cone(Cone cone) {
				o = new Objects(cone.Obj);
				this.cone = new Bracket(cone.Values);
			}
Exemplo n.º 55
0
 public static BracketOperand Bracket(Bracket bracket)
 {
     return new BracketOperand(bracket);
 }
Exemplo n.º 56
0
			public Cube(Cube cube) {
				o = new Objects(cube.Obj);
				this.cube = new Bracket(cube.Values);
			}
Exemplo n.º 57
0
			public Bracket (Bracket bracket) {
				Bracket _bracket = new Bracket(bracket.Values);
			}
Exemplo n.º 58
0
			public Triangle(Triangle triangle) {
				o = new Objects(triangle.Obj);
				this.triangle = new Bracket(triangle.Values);
			}