Ejemplo n.º 1
0
        protected void ParseSql()
        {
            string sql = _tokenizer.Token;

            if (IsElseMode())
            {
                sql = sql.Replace("--", string.Empty);
            }
            INode node = Peek();

            if ((node is InternalIfNode || node is ElseNode) && node.ChildSize == 0)
            {
                InternalSqlTokenizer st = new InternalSqlTokenizer(sql);
                st.SkipWhitespace();
                string token = st.SkipToken();
                st.SkipWhitespace();
                if ("AND".Equals(token.ToUpper()) || "OR".Equals(token.ToUpper()))
                {
                    node.AddChild(new PrefixSqlNode(st.Before, st.After));
                }
                else
                {
                    node.AddChild(new SqlNode(sql));
                }
            }
            else
            {
                node.AddChild(new SqlNode(sql));
            }
        }
Ejemplo n.º 2
0
 void BeginGroup(string name, Form form, string text, Rect rect)
 {
     if (currentItem == null)
     {
         currentItem = topItem.AddChild(new MenuItem(name, form, text, rect));
         //create window for this menu
     }
     else
     {
         currentItem = currentItem.AddChild(new MenuItem(name, form, text, rect));
     }
 }
Ejemplo n.º 3
0
        // Methods

        /// <summary>
        /// Adds a word to a word tree. Will not modify word lists.
        /// </summary>
        /// <param name="word">The word to add to the tree.</param>
        public virtual void AddWord(string word)
        {
            INode n = Root;

            word = word.ToLower();


            int len = word.Length;

            for (int i = 0; i < len; i++)
            {
                INode check = n.GetChild(word[i]);

                if (check != null)
                {
                    n = check;
                }
                else
                {
                    n = n.AddChild(word[i]);
                }
            }


            n.Accepting = true;
        }
        public void ShouldTransferChildrenAttributesToParentNode()
        {
            var pParagraphPropChild = new Node(KeywordToken.Color);

            _pParagraphProp.AddChild(pParagraphPropChild);
            pParagraphPropChild.SetAttribute("testAttr", "testAttrValue");
            _pParagraphProp.SetAttribute("testAttr2", "testAttr2Value");

            _paragraph.AddChild(_pParagraphProp);

            var attributeCopierAnalyzer = new AttributeCopierAnalyzer();

            attributeCopierAnalyzer.Analyze(_paragraph);

            Assert.AreEqual("testAttrValue", _paragraph.GetAttribute("testAttr"));
            Assert.AreEqual("testAttr2Value", _paragraph.GetAttribute("testAttr2"));
        }
Ejemplo n.º 5
0
        public static bool AddChild(this INode parent, string data)
        {
            INode node = new Node();

            parent.AddChild(node);
            node.Emitter(ref data);

            return(true);
        }
Ejemplo n.º 6
0
 private void AddChildNodeToParent(INode child)
 {
     if (ContainsItems())
     {
         INode parentNode = GetParentNode();
         parentNode.AddChild(child);
         mCurrent = child;
     }
 }
Ejemplo n.º 7
0
        public static bool AddChild <T>(this INode parent, string name, params string[] attributes) where T : INode
        {
            INode node = (INode)Activator.CreateInstance(typeof(T));

            parent.AddChild(node);
            node.Name = name;
            node.Features.AddRange(attributes);

            return(true);
        }
Ejemplo n.º 8
0
    private void DrawAddChildOption(INode node)
    {
        int i = EditorGUILayout.Popup(0, _addChildOptions, BehaviorTreeEditorSettings.Instance.AddButtonStyle);

        if (i == 0)
        {
            return;
        }

        switch (i)
        {
        case 1:
            Sequence newSequence = new Sequence();
            node.AddChild(newSequence);
            newSequence.SetParent(node);
            break;

        case 2:
            Selector newSelector = new Selector();
            node.AddChild(newSelector);
            newSelector.SetParent(node);
            break;

        case 3:
            Decorator newDecorator = new Decorator();
            node.AddChild(newDecorator);
            newDecorator.SetParent(node);
            break;

        case 4:
            Task t = new Task();
            node.AddChild(t);
            t.SetParent(node);
            break;

        default:
            break;
        }

        BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, _behaviorTree);
    }
        public void Setup()
        {
            /*
             * p->ppr(testAttr=testAttrValue, testAttr2=testAttr2Value)
             */
            _paragraph      = new Node(KeywordToken.Paragraph);
            _pParagraphProp = new Node(KeywordToken.PreviousParagraph);
            _pParagraphProp.SetAttribute("testAttr", "testAttrValue");
            _pParagraphProp.SetAttribute("testAttr2", "testAttr2Value");

            _paragraph.AddChild(_pParagraphProp);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// A definite node is constructed from a specified number of
 /// children.  That number of nodes are popped from the stack and
 /// made the children of the definite node.  Then the definite node
 /// is pushed on to the stack.
 /// </summary>
 internal void CloseNodeScope(INode parentNode, int num)
 {
     mark = marks.Pop();
     while(num-- > 0)
     {
         INode node = PopNode();
         node.Parent = parentNode;
         parentNode.AddChild(node, num);
     }
     parentNode.Close();
     PushNode(parentNode);
     nodeCreated = true;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// A definite node is constructed from a specified number of
 /// children.  That number of nodes are popped from the stack and
 /// made the children of the definite node.  Then the definite node
 /// is pushed on to the stack.
 /// </summary>
 internal void CloseNodeScope(INode parentNode, int num)
 {
     mark = marks.Pop();
     while (num-- > 0)
     {
         INode node = PopNode();
         node.Parent = parentNode;
         parentNode.AddChild(node, num);
     }
     parentNode.Close();
     PushNode(parentNode);
     nodeCreated = true;
 }
Ejemplo n.º 12
0
 internal void CloseNodeScope(INode n, int num)
 {
     this.mk = (int)this.marks.Pop();
     while (num-- > 0)
     {
         INode node = this.PopNode();
         node.Parent = n;
         n.AddChild(node, num);
     }
     n.Close();
     this.PushNode(n);
     this.node_created = true;
 }
Ejemplo n.º 13
0
 /* A definite node is constructed from a specified number of
  * children.  That number of nodes are popped from the stack and
  * made the children of the definite node.  Then the definite node
  * is pushed on to the stack. */
 public void CloseNodeScope(INode n, int num)
 {
     mk = marks.Pop();
     while (num-- > 0)
     {
         INode node = PopNode();
         node.Parent = n;
         n.AddChild(node, num);
     }
     n.Close();
     PushNode(n);
     nodeCreated = true;
 }
Ejemplo n.º 14
0
 private static bool Expand(INode node, IGameState state)
 {
     // Expand
     var result = node.GetRandomMoveOrIsFalse();
     if (result.Item1)
     {
         var move = result.Item2;
         state = move.DoMove();
         Func<INode> constructor = () => new SingleThreadedNode(node, move, state, node.UCTK);
         node = node.AddChild(constructor);
         return true;
     }
     return false;
 }
Ejemplo n.º 15
0
        private static bool Expand(INode node, IGameState state)
        {
            // Expand
            var result = node.GetRandomMoveOrIsFalse();

            if (result.Item1)
            {
                var move = result.Item2;
                state = move.DoMove();
                Func <INode> constructor = () => new SingleThreadedNode(node, move, state, node.UCTK);
                node = node.AddChild(constructor);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 16
0
        public static IMove ComputeSingleThreadedUCT(IGameState gameState, int itermax, bool verbose, Action <string> printfn, float uctk)
        {
            var rootNode = new SingleThreadedNode(null, null, gameState, uctk);

            for (var i = 0; i < itermax; i++)
            {
                INode node  = rootNode;
                var   state = gameState.Clone();

                // Select
                while (node.NodeIsFullyExpandedAndNonterminal)
                {
                    //if (verbose)
                    //{
                    //    printfn(node.DisplayUTC());
                    //}
                    node = node.UCTSelectChild();
                    state.DoMove(node.Move);
                }

                // Expand
                var result = node.GetRandomMoveOrIsFalse();
                if (result.Item1)
                {
                    var move = result.Item2;
                    state.DoMove(move);
                    Func <INode> constructor = () => new SingleThreadedNode(node, move, state, node.UCTK);
                    node = node.AddChild(constructor);
                }

                // Rollout
                state.PlayRandomlyUntilTheEnd();

                // Backpropagate
                while (node != null)
                {
                    node.Update(state.GetResult(node.PlayerJustMoved));
                    node = node.Parent;
                }
            }
            if (verbose)
            {
                //printfn(rootNode.DisplayTree(0));
                printfn(rootNode.DisplayMostVisistedChild());
            }

            return(rootNode.MostVisitedMove());
        }
Ejemplo n.º 17
0
 /// <summary>Resolves a content property.</summary>
 /// <param name="styles">the styles map</param>
 /// <param name="contentContainer">the content container</param>
 /// <param name="context">the CSS context</param>
 private void ResolveContentProperty(IDictionary <String, String> styles, INode contentContainer, CssContext
                                     context)
 {
     if (contentContainer is CssPseudoElementNode || contentContainer is PageMarginBoxContextNode)
     {
         IList <INode> resolvedContent = CssContentPropertyResolver.ResolveContent(styles, contentContainer, context
                                                                                   );
         if (resolvedContent != null)
         {
             foreach (INode child in resolvedContent)
             {
                 contentContainer.AddChild(child);
             }
         }
     }
 }
Ejemplo n.º 18
0
        void MakeGeneric(INode parent, CodeConstruct sourceFileCode, string typeName)
        {
            CodeConstruct sourceFileCodeClone;

            for (int paramCount = 1; paramCount <= MAX_PARAMS; paramCount++)
            {
                sourceFileCodeClone = sourceFileCode.Clone();

                TypeDeclaration type = new DownwardTreeWalk <INode>(sourceFileCodeClone.CompilationUnit, n => n.Children)
                                       .OfType <TypeDeclaration>().First(t => t.Name == typeName);

                parent.AddChild(type);

                List <string> genericTypeNames = new List <string>();
                List <string> paramNames       = new List <string>();
                for (int i = 1; i <= paramCount; i++)
                {
                    string templateName = "T";
                    string paramName    = "param";
                    if (paramCount > 1)
                    {
                        templateName += i;
                        paramName    += i;
                    }

                    genericTypeNames.Add(templateName);
                    paramNames.Add(paramName);
                }

                type.Templates.AddRange(genericTypeNames.Select(name => new TemplateDefinition(name, null)));

                MethodDeclaration invokeMethod = type.Children.OfType <MethodDeclaration>().First(method => method.Name == "Invoke");
                invokeMethod.Parameters.AddRange(genericTypeNames.Select((name, i) => new ParameterDeclarationExpression(new TypeReference(name), paramNames[i])));

                ExpressionStatement  statement  = invokeMethod.Body.Children.OfType <ExpressionStatement>().First();
                InvocationExpression invocation = (InvocationExpression)statement.Expression;
                invocation.Arguments.AddRange(paramNames.Select(name => new IdentifierExpression(name)));

                MethodDeclaration getInstanceMethod = type.Children.OfType <MethodDeclaration>().First(method => method.Name == "GetInstance");
                AddGenericTypes(getInstanceMethod.TypeReference, genericTypeNames);

                CastExpression cast = getInstanceMethod.Body.Children.OfType <ReturnStatement>().First().Expression.Cast <CastExpression>();
                AddGenericTypes(cast.CastTo, genericTypeNames);
                AddGenericTypes(cast.Expression.Cast <InvocationExpression>().Arguments.First().Cast <ObjectCreateExpression>().CreateType, genericTypeNames);
            }
        }
Ejemplo n.º 19
0
        public void StartSection(Section section)
        {
            try
            {
                INode parent = _nodes.Peek();
                if (section.Description.IsNotEmpty())
                {
                    parent.AddComment(section.Description);
                }

                INode element = parent.AddChild(section.FixtureName);
                _nodes.Push(element);
            }
            catch (Exception e)
            {
                throw new ApplicationException(
                          "Could not create element for Section '{0}'".ToFormat(section.FixtureName), e);
            }
        }
Ejemplo n.º 20
0
 private void Add(char value)
 {
     if (IsEmpty())
     {
         if (Char.IsDigit(value))
         {
             root = new Operand(value);
         }
         else if (IsOperation(value))
         {
             root    = new Operation(value);
             Current = (Operation)root;
         }
     }
     else
     {
         Current = root.AddChild(value, Current);
     }
 }
Ejemplo n.º 21
0
        public override void LinkNode(Generator generator)
        {
            string id = GetAttribute("file");

            if (id != null)
            {
                fileNode = generator.GetNodeByID(id);
                fileNode.AddChild(this);
            }

            id = GetAttribute("context");

            if (id != null)
            {
                contextNode = generator.GetNodeByID(id);
                contextNode.AddChild(this);
            }

            id = GetAttribute("type");

            if (id != null)
            {
                typeNode = generator.GetNodeByID(id);
                typeNode.AddChild(this);
            }


            string context_id = GetContextAttribute("type");

            if (context_id != null && id != context_id)
            {
                LinkBehavior linknode = generator.GetNodeByID(context_id) as LinkBehavior;

                if (linknode != null)
                {
                    linknode.typeNode = this;
                    this.AddChild(linknode);
                }
            }
        }
Ejemplo n.º 22
0
 internal void CloseNodeScope(INode n, bool condition)
 {
     if (condition)
     {
         int i = this.NodeArity();
         this.mk = (int)this.marks.Pop();
         while (i-- > 0)
         {
             INode node = this.PopNode();
             node.Parent = n;
             n.AddChild(node, i);
         }
         n.Close();
         this.PushNode(n);
         this.node_created = true;
     }
     else
     {
         this.mk           = (int)this.marks.Pop();
         this.node_created = false;
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// A conditional node is constructed if its condition is true.  All
 /// the nodes that have been pushed since the node was opened are
 /// made children of the the conditional node, which is then pushed
 /// on to the stack.  If the condition is false the node is not
 /// constructed and they are left on the stack.
 /// </summary>
 internal void CloseNodeScope(INode n, bool condition)
 {
     if (condition)
     {
         int arity = NodeArity();
         mark = marks.Pop();
         while (arity-- > 0)
         {
             INode node = PopNode();
             node.Parent = n;
             n.AddChild(node, arity);
         }
         n.Close();
         PushNode(n);
         nodeCreated = true;
     }
     else
     {
         mark        = marks.Pop();
         nodeCreated = false;
     }
 }
Ejemplo n.º 24
0
        /* A conditional node is constructed if its condition is true.  All
         * the nodes that have been pushed since the node was opened are
         * made children of the conditional node, which is then pushed
         * on to the stack.  If the condition is false the node is not
         * constructed and they are left on the stack. */
        public void closeNodeScope(INode n, bool condition)
        {
            if (condition)
            {
                int a = NodeArity();

                mk = marks.Pop();
                while (a-- > 0)
                {
                    INode c = PopNode();
                    c.Parent = n;
                    n.AddChild(c, a);
                }
                n.Close();
                PushNode(n);
                nodeCreated = true;
            }
            else
            {
                mk          = marks.Pop();
                nodeCreated = false;
            }
        }
Ejemplo n.º 25
0
        public override void LinkNode( Generator generator )
        {
            string id = GetAttribute( "file" );

            if ( id != null )
            {
                fileNode = generator.GetNodeByID( id );
                fileNode.AddChild( this );
            }

            id = GetAttribute( "context" );

            if ( id != null )
            {
                contextNode = generator.GetNodeByID( id );
                contextNode.AddChild( this );
            }

            id = GetAttribute( "type" );

            if (id != null)
            {
                typeNode = generator.GetNodeByID(id);
                typeNode.AddChild(this);
            }


            string context_id = GetContextAttribute("type");

            if (context_id != null && id != context_id)
            {
                LinkBehavior linknode = generator.GetNodeByID(context_id) as LinkBehavior;
                linknode.typeNode = this;

                this.AddChild(linknode);
            }
        }
Ejemplo n.º 26
0
		/* A definite node is constructed from a specified number of
	children.  That number of nodes are popped from the stack and
	made the children of the definite node.  Then the definite node
	is pushed on to the stack. */

		internal void CloseNodeScope(INode n, int num)
		{
			mk = ((Int32) marks.Pop());
			while(num-- > 0)
			{
				INode c = PopNode();
				c.Parent = n;
				n.AddChild(c, num);
			}
			n.Close();
			PushNode(n);
			node_created = true;
		}
Ejemplo n.º 27
0
        private void _addChildWords(ref INode<int> node, ref List<SentenceWord> sentenceWordList, int[] excludeIds, bool checkLinkType = true)
        {
            var localNode = node;
            foreach (var word in sentenceWordList.FindAll(x => x.DOM == localNode.Data))
            {

                if (!excludeIds.Contains(word.Id))
                {
                    if (checkLinkType)
                    {
                        if (
                           !(word.Link.Value == LinkType.SentSoch.Value
                          || word.Link.Value == LinkType.PodchSouz.Value
                          || word.Link.Value == LinkType.InfSouz.Value
                          || word.Link.Value == LinkType.Eksplet.Value
                          || word.Link.Value == LinkType.Relyat.Value))
                        {
                            var newNode = node.AddChild(word.Id);
                            _addChildWords(ref newNode, ref sentenceWordList, excludeIds);
                        }
                    }
                    else
                    {
                        var newNode = node.AddChild(word.Id);
                        _addChildWords(ref newNode, ref sentenceWordList, excludeIds);
                    }
                }
            }
            node = localNode;
        }
Ejemplo n.º 28
0
        public static IMove ComputeSingleThreadedUCT(IGameState gameState, bool verbose, Action <string> printfn, float uctk, int secs)
        {
            var      rootNode       = new SingleThreadedNode(null, null, gameState, uctk);
            DateTime time           = DateTime.Now;
            DateTime end            = time.AddSeconds(secs);
            bool     exitEarlyCheck = true;

            int i = 0;

            for (; time < end; i++)
            {
                time = DateTime.Now;

                INode node = rootNode;

                // Exit early if we're not learning anything --> Go straight to tiebreak/playout
                if (exitEarlyCheck && ((SingleThreadedNode)node).Childs.Count() >= ((SingleThreadedNode)node).numMoves)
                {
                    bool atLeastOneWin = false;
                    foreach (INode c in ((SingleThreadedNode)node).Childs)
                    {
                        if (c.Wins > 0)
                        {
                            atLeastOneWin = true;
                            break;
                        }
                    }
                    if (!atLeastOneWin)
                    {
                        Console.WriteLine("No Wins, Quit Early With this long left: " + (end - time).ToString());
                        break;
                    }
                    else
                    {
                        exitEarlyCheck = false;
                    }
                }

                var state = ((Level)gameState).Clone();

                // Select
                while (node.NodeIsFullyExpandedAndNonterminal)
                {
                    //if (verbose)
                    //{
                    //    printfn(node.DisplayUTC());
                    //}
                    node  = node.UCTSelectChild();
                    state = node.Move.DoMove(state);
                }

                // Expand
                var result = node.GetRandomMoveOrIsFalse();
                if (result.Item1)
                {
                    var move = result.Item2;
                    state = move.DoMove(state);
                    Func <INode> constructor = () => new SingleThreadedNode(node, move, state, node.UCTK);
                    node = node.AddChild(constructor);
                }

                // Rollout
                state.PlayRandomlyUntilTheEnd();

                // Backpropagate
                while (node != null)
                {
                    node.Update(state.GetResult(node.PlayerJustMoved));
                    node = node.Parent;
                }
            }
            Game1.world.level.IterationsPerTurn.Add(i);

            if (verbose)
            {
                //printfn(rootNode.DisplayTree(0));
                printfn(rootNode.DisplayMostVisistedChild());
            }

            //return rootNode.MostVisitedMove();
            return(rootNode.MostVisitedMoveTieBreakWithPlayoutHybrid());
        }
Ejemplo n.º 29
0
        private void _addSyntacticChildWord(ref INode<string> node, ref List<SentenceElement> sentenceWordList, string[] excludeGUIDs)
        {
            var localNode = node;
            foreach (var word in sentenceWordList.FindAll(x => x.SyntacticParentWordGUID == localNode.Data))
            {
                if (excludeGUIDs.Contains(word.GUID)) continue;

                var newNode = node.AddChild(word.GUID);
                _addSyntacticChildWord(ref newNode, ref sentenceWordList, excludeGUIDs);
            }
            node = localNode;
        }
Ejemplo n.º 30
0
 public void AddNode(INode parent, INode node)
 {
     parent.AddChild(node);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// A conditional node is constructed if its condition is true.  All
 /// the nodes that have been pushed since the node was opened are
 /// made children of the the conditional node, which is then pushed
 /// on to the stack.  If the condition is false the node is not
 /// constructed and they are left on the stack.
 /// </summary>
 internal void CloseNodeScope(INode n, bool condition)
 {
     if (condition)
     {
         int arity = NodeArity();
         mark = marks.Pop();
         while(arity-- > 0)
         {
             INode node = PopNode();
             node.Parent = n;
             n.AddChild(node, arity);
         }
         n.Close();
         PushNode(n);
         nodeCreated = true;
     }
     else
     {
         mark = marks.Pop();
         nodeCreated = false;
     }
 }
Ejemplo n.º 32
0
        private void _addChildWords(ref INode<string> node, ref List<SentenceElement> sentenceWordList, string[] excludeIds)
        {
            var localNode = node;
            foreach (var word in sentenceWordList.FindAll(x => x.SyntacticParentWordId == localNode.Data))
            {
                if (!excludeIds.Contains(word.Id))
                {
                    var newNode = node.AddChild(word.Id);
                    _addChildWords(ref newNode, ref sentenceWordList, excludeIds);

                }
            }
            node = localNode;
        }
Ejemplo n.º 33
0
		/* A conditional node is constructed if its condition is true.  All
	the nodes that have been pushed since the node was opened are
	made children of the the conditional node, which is then pushed
	on to the stack.  If the condition is false the node is not
	constructed and they are left on the stack. */

		internal void CloseNodeScope(INode n, bool condition)
		{
			if (condition)
			{
				int a = NodeArity();
				mk = ((Int32) marks.Pop());
				while(a-- > 0)
				{
					INode c = PopNode();
					c.Parent = n;
					n.AddChild(c, a);
				}
				n.Close();
				PushNode(n);
				node_created = true;
			}
			else
			{
				mk = ((Int32) marks.Pop());
				node_created = false;
			}
		}
Ejemplo n.º 34
0
    private void DrawAddChildOption(INode node)
    {
        int i = EditorGUILayout.Popup(0, _addChildOptions, BehaviorTreeEditorSettings.Instance.AddButtonStyle);
        if(i == 0)
        {
            return;
        }

        switch(i)
        {
            case 1:
                Sequence newSequence = new Sequence();
                node.AddChild(newSequence);
                newSequence.SetParent(node);
                break;
            case 2:
                Selector newSelector = new Selector();
                node.AddChild(newSelector);
                newSelector.SetParent(node);
                break;
            case 3:
                Decorator newDecorator = new Decorator();
                node.AddChild(newDecorator);
                newDecorator.SetParent(node);
                break;
            case 4:
                Task t = new Task();
                node.AddChild(t);
                t.SetParent(node);
                break;
            default:
                break;
        }

        BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, _behaviorTree);
    }