예제 #1
0
        public override LispOperator <TBb> CreateOperator(
            TBb blackboard,
            LispParser.Node node,
            LispParser.ICompiler <TBb> compiler)
        {
            LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode;
            if (identifierNode == null)
            {
                return(null);
            }

            Func <bool> func = blackboard.GetBoolFunction(identifierNode.Value);

            if (func == null)
            {
                return(null);
            }

            return(new BlackboardBoolFunction <TBb>(identifierNode.Value, func));
        }
예제 #2
0
 protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     throw new NotImplementedException("Not implemented, use NamedCoroutine instead?");
 }
예제 #3
0
        public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.MethodNode methodNode = node as LispParser.MethodNode;
            if (methodNode == null || methodNode.Identifier.Value != Name)
            {
                return(null);
            }

            LispMethod <TBb> method = CreateMethod(blackboard, methodNode, compiler);

            if (method != null)
            {
                if (method.GetType() != GetType())
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Expected {0} but compiled to {1}!",
                                  TypeHelper.GetFriendlyTypeName(GetType()),
                                  TypeHelper.GetFriendlyTypeName(method.GetType())));
                }

                foreach (LispParser.Node child in methodNode.Children)
                {
                    method.Children.Add((LispOperator <TBb>)compiler.Compile(blackboard, child));
                }
            }
            return(method);
        }
예제 #4
0
 public abstract LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler);
예제 #5
0
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            ControlFlowNode <TBb> controlFlowNode = CreateControlFlow(blackboard, method, compiler);

            if (controlFlowNode == null)
            {
                return(null);
            }

            foreach (LispParser.Node child in method.Children)
            {
                bool handled =
                    child.NamedParamX <LispParser.StringNode>("Name", v => controlFlowNode.Name = v.Value) ||
                    child.ParamX <LispParser.MethodNode>(null, v => controlFlowNode.Children.Add((TreeTask <TBb>)compiler.Compile(blackboard, child)));

                if (!handled)
                {
                    LispParser.NamedParameterNode named = child as LispParser.NamedParameterNode;

                    if (named != null && named.Identifier.Value == "if")
                    {
                        controlFlowNode.Predicate = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, named.Value);
                        if (!(controlFlowNode.Predicate is ICanEvaluateToBool))
                        {
                            throw new InvalidOperationException(
                                      string.Format(
                                          "The if predicate must evaluate to a bool, {0} doesn't!",
                                          named.Value));
                        }
                        continue;
                    }

                    throw new InvalidOperationException(
                              string.Format(
                                  "Unhandled child {0} on {1}!",
                                  child,
                                  this));
                }
            }

            return(controlFlowNode);
        }
예제 #6
0
 public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     LispParser.StringNode stringNode = node as LispParser.StringNode;
     return(stringNode != null ? new StringConstant <TBb>(stringNode.Value) : null);
 }
예제 #7
0
 protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     return(new KeepRunning <TBb>());
 }
예제 #8
0
        LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.MethodNode method = node as LispParser.MethodNode;
            if (method == null)
            {
                return(null);
            }

            if (method.MethodName == GetClassName())
            {
                TreeTask <TBb> treeTask = CreateTreeTaskFromParseTree(blackboard, method, compiler);
                foreach (LispParser.Node child in method.Children)
                {
                    child.NamedParamX <LispParser.StringNode>("Name", v => treeTask.Name = v.Value);
                }
                return(treeTask);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            UtilityControlFlowNode <TBb> utilityControlFlowNode = CreateUtilityControlFlow(blackboard, method, compiler);

            if (utilityControlFlowNode == null)
            {
                return(null);
            }

            foreach (LispParser.Node child in method.Children)
            {
                child.NamedParamX <LispParser.StringNode>("Name", v => utilityControlFlowNode.Name = v.Value);
                child.ParamX <LispParser.MethodNode>(null, v => utilityControlFlowNode.Children.Add((TaskUtility <TBb>)compiler.Compile(blackboard, child)));
            }

            return(utilityControlFlowNode);
        }
예제 #10
0
        public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode;

            return(identifierNode != null && identifierNode.Value == "False" ? new FalseConstant <TBb>() : null);
        }
예제 #11
0
 public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     LispParser.IntegerNode integerNode = node as LispParser.IntegerNode;
     return(integerNode != null ? new IntConstant <TBb>(integerNode.Value) : null);
 }
예제 #12
0
 protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     throw new InvalidOperationException("Not implemented!");
 }
예제 #14
0
 protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler)
 {
     return(new LessThanOrEqualTo <TBb>());
 }
예제 #15
0
파일: Debug.cs 프로젝트: mfagerlund/Beehive
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            DebugLog <TBb> debugLog = new DebugLog <TBb>(null);

            debugLog.StringComputer = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, method.Children[0]);
            if (!(debugLog.StringComputer is ICanEvaluateToString))
            {
                throw new InvalidOperationException("The string computer must evaluate to a string!");
            }
            return(debugLog);
        }
예제 #16
0
 protected override UtilityControlFlowNode <TBb> CreateUtilityControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     return(new UtilitySelector <TBb>());
 }
예제 #17
0
        public LispParser.ICanCreateFromLispParseTree <TBb> CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.MethodNode method = node as LispParser.MethodNode;
            if (method == null)
            {
                throw new InvalidOperationException("Expected BehaviourTree but found: null");
            }

            if (method.MethodName != "BehaviourTree")
            {
                throw new InvalidOperationException("Expected BehaviourTree but found: " + method);
            }

            BehaviourTree <TBb> behaviourTree = new BehaviourTree <TBb>(null, null);

            foreach (LispParser.Node child in method.Children)
            {
                child.NamedParamX <LispParser.NumberNode>("RunningTaskHysterisis", v => behaviourTree.RunningTaskHysterisis = (int)v.FloatValue);
                child.NamedParamX <LispParser.StringNode>("Name", v => behaviourTree.Name = v.Value);
                child.ParamX <LispParser.MethodNode>(null, v => behaviourTree.RootTask    = (TreeTask <TBb>)compiler.Compile(blackboard, v));
            }

            return(behaviourTree);
        }
예제 #18
0
        public LispParser.ICanCreateFromLispParseTree <TBb> CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.MethodNode method = node as LispParser.MethodNode;

            if (method == null || method.MethodName != "TaskUtility")
            {
                return(null);
            }

            TaskUtility <TBb> taskUtility = new TaskUtility <TBb>(null, null);

            taskUtility.UtilityComputer = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, method.Children[0]);
            if (!(taskUtility.UtilityComputer is ICanEvaluateToFloat))
            {
                throw new InvalidOperationException("The utility computer must evaluate to a float!");
            }
            taskUtility.Task = (TreeTask <TBb>)compiler.Compile(blackboard, method.Children[1]);
            return(taskUtility);
        }
예제 #19
0
 protected abstract TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
예제 #20
0
        protected override Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            RunNTimes <TBb> runNTimes = new RunNTimes <TBb>(null);

            foreach (LispParser.Node child in method.Children)
            {
                child.NamedParamX <LispParser.IntegerNode>("MaxRunTimes", x => runNTimes.MaxRunTimes = x.Value);
            }
            return(runNTimes);
        }
예제 #21
0
 protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler)
 {
     return(new Format <TBb>());
 }
예제 #22
0
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            Decorator <TBb> decorator = CreateDecoratorFromParseTree(blackboard, method, compiler);

            if (decorator != null)
            {
                if (decorator.GetType() != GetType())
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Expected {0} but compiled to {1}!",
                                  TypeHelper.GetFriendlyTypeName(GetType()),
                                  TypeHelper.GetFriendlyTypeName(decorator.GetType())));
                }

                decorator.DecoratedTask = (TreeTask <TBb>)compiler.Compile(blackboard, method.Children.OfType <LispParser.MethodNode>().Single());
            }
            return(decorator);
        }
예제 #23
0
 protected override ControlFlowNode <TBb> CreateControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     return(new Sequence <TBb>());
 }
예제 #24
0
 protected abstract Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
예제 #25
0
 protected abstract ControlFlowNode <TBb> CreateControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
예제 #26
0
 protected override Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
 {
     return(new Counter <TBb>(null));
 }
예제 #27
0
 LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     return(CreateOperator(blackboard, node, compiler));
 }
예제 #28
0
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            FixedResultState <TBb> fixedResultState = new FixedResultState <TBb>(ResultState);

            foreach (LispParser.Node child in method.Children)
            {
                child.NamedParamX <LispParser.StringNode>("ResultState", v => fixedResultState.ResultState = (TaskState)Enum.Parse(typeof(TaskState), v.Value));
            }
            return(fixedResultState);
        }
예제 #29
0
 protected abstract LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler);
예제 #30
0
        protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler)
        {
            NamedCoroutine <TBb> namedCoroutine = new NamedCoroutine <TBb>(null, null);

            foreach (LispParser.Node child in method.Children)
            {
                LispParser.IdentifierNode identifier = child as LispParser.IdentifierNode;
                if (identifier != null)
                {
                    Func <IEnumerator <TaskState> > func = blackboard.GetCoRoutineFunc(identifier.Value);

                    if (func == null)
                    {
                        throw new InvalidOperationException("Unrecognized couroutine creator: " + identifier.Value);
                    }

                    namedCoroutine.NamedCoroutineCreator = new NamedCoroutineCreator(identifier.Value, func);
                }
            }

            return(namedCoroutine);
        }