Exemplo n.º 1
0
 /**
  * Constructs an ExecutionLeaf to run a specific ModelLeaf.
  *
  * @param modelTask
  *            the ModelLeaf to run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionLeaf.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 protected ExecutionLeaf(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelLeaf))
     {
         throw new ArgumentException("The ModelTask must subclass ModelLeaf but it inherits from " + modelTask.GetType().Name);
     }
 }
 /**
  * Constructs an ExecutionRandomSelector to run a specific ModelRandomSelector.
  *
  * @param modelTask
  *            the ModelRandomSelector to run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionRandomSelector.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionRandomSelector(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelRandomSelector))
     {
         throw new ArgumentException("The ModelTask must subclass ModelRandomSelector but it inherits from " + modelTask.GetType().Name);
     }
 }
 protected ModelComposite(ModelTask guard, string name, params ModelTask[] children)
     : base(guard, name, children)
 {
     if (children.Length == 0)
     {
         throw new ArgumentException("The list of children cannot be empty");
     }
 }
 /**
  * Creates an ExecutionStaticPriorityList that is able to run a
  * ModelStaticPriorityList task and that is managed by a BTExecutor.
  *
  * @param modelTask
  *            the ModelStaticPriorityList that this
  *            ExecutionStaticPriorityList is going to run.
  * @param executor
  *            the BTExecutor in charge of running this
  *            ExecutionStaticPriorityList.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionStaticPriorityList(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelStaticPriorityList))
     {
         throw new ArgumentException("The ModelTask must subclass ModelStaticPriorityList but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 /**
  * Constructs an ExecutionSafeContextManager that knows how to run a
  * ModelSafeContextManager.
  *
  * @param modelTask
  *            the ModelSafeContextManager to run.
  * @param executor
  *            the BTExecutor that will manage this
  *            ExecutionSafeContextManager.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionSafeContextManager(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelSafeContextManager))
     {
         throw new ArgumentException("The ModelTask must subclass ModelSafeContextManager but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 /**
  * Constructs an ExecutionSubtreeLookup that knows how to run a
  * ModelSubtreeLookup.
  *
  * @param modelTask
  *            the ModelSubtreeLookup to run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionSubtreeLookup.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionSubtreeLookup(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelSubtreeLookup))
     {
         throw new ArgumentException("The ModelTask must subclass ModelSubtreeLookup but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 /**
  * Creates an ExecutionComposite that is able to run a particular
  * ModelComposite task.
  *
  * @param modelTask
  *            the ModelComposite task to run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionComposite.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 protected ExecutionComposite(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelComposite))
     {
         throw new ArgumentException("The ModelTask must subclass " + typeof (ModelComposite).Name + " but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 /**
  * Constructs and ExecutionUntilFail that knows how to run a ModelUntilFail.
  *
  * @param modelTask
  *            the ModelUntilFail that this ExecutionUntilFail will run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionUntilFail.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionUntilFail(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelUntilFail))
     {
         throw new ArgumentException("The ModelTask must subclass ModelUntilFail but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 /**
  * Creates an ExecutionPerformInterruption that is able to run a
  * ModelPerformInterruption task and that is managed by a BTExecutor.
  *
  * @param modelTask
  *            the ModelPerformInterruption that this
  *            ExecutionPerformInterruption is going to run.
  * @param executor
  *            the BTExecutor in charge of running this
  *            ExecutionPerformInterruption.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionPerformInterruption(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelPerformInterruption))
     {
         throw new ArgumentException("The ModelTask must subclass ModelPerformInterruption but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
Exemplo n.º 10
0
        /**
         * Creates an ExecutionWait that is able to run a ModelWait task and that is
         * managed by a BTExecutor.
         *
         * @param modelTask
         *            the ModelWait that this ExecutionWait is going to run.
         * @param executor
         *            the BTExecutor in charge of running this ExecutionWait.
         * @param parent
         *            the parent ExecutionTask of this task.
         */
        public ExecutionWait(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelWait))
            {
                throw new ArgumentException("The ModelTask must subclass ModelWait but it inherits from " + modelTask.GetType().Name);
            }

            Initialize(modelTask);
        }
Exemplo n.º 11
0
        /**
         * Creates an ExecutionLimit that knows how to run a ModelLimit.
         *
         * @param modelTask
         *            the ModelLimit to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionLimit.
         * @param parent
         *            the parent ExecutionTask of this task.
         */
        public ExecutionLimit(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelLimit))
            {
                throw new ArgumentException("The ModelTask must subclass ModelLimitbut it inherits from " + modelTask.GetType().Name);
            }

            _maxNumTimes = ((ModelLimit) ModelTask).getMaxNumTimes();
            _numRunsSoFar = 0;
        }
        /**
         * Constructs an ExecutionVariableRenamer that knows how to run a
         * ModelVariableRenamer.
         *
         * @param modelTask
         *            the ModelVariableRenamer to run.
         * @param executor
         *            the BTExecutor in charge of running this
         *            ExecutionVariableRenamer.
         * @param parent
         *            the parent ExecutionTask of this task.
         */
        public ExecutionVariableRenamer(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelVariableRenamer))
            {
                throw new ArgumentException("The ModelTask must subclass ModelVariableRenamer but it inherits from " +
                                            modelTask.GetType().Name);
            }

            _variableName = ((ModelVariableRenamer) modelTask).VariableName;
            _newVariableName = ((ModelVariableRenamer) modelTask).NewVariableName;
        }
Exemplo n.º 13
0
        protected ModelTask(ModelTask guard, string name, params ModelTask[] children)
        {
            _guard    = guard;
            _name     = name;
            _children = new List <ModelTask>();

            foreach (var modelTask in children)
            {
                _children.Add(modelTask);
            }

            _position = new Position();
        }
Exemplo n.º 14
0
        protected ModelTask(ModelTask guard, string name, params ModelTask[] children)
        {
            _guard = guard;
            _name = name;
            _children = new List<ModelTask>();

            foreach (var modelTask in children)
            {
                _children.Add(modelTask);
            }

            _position = new Position();
        }
        /**
         * Adds the behaviour tree <code>tree</code> to the set of behaviour trees
         * stored in this library. If there is already a tree with the name
         * <code>name</code>, then it is overwritten by <code>tree</code>.
         *
         * @param name
         *            the name that will identify the tree <code>tree</code> in the
         *            library.
         * @param tree
         *            the tree to insert.
         * @return true if there was already a tree with name <code>name</code>, and
         *         false otherwise.
         */
        public bool AddBT(string name, ModelTask tree)
        {
            bool overwritten = false;
            if (_trees.ContainsKey(name))
            {
                overwritten = true;
                _trees.Remove(name);
            }

            _trees.Add(name, tree);

            return overwritten;
        }
        /**
         * Creates an ExecutionParallel that is able to run a ModelParallel task and
         * that is managed by a BTExecutor.
         *
         * @param modelTask
         *            the ModelParallel that this ExecutionParallel is going to run.
         * @param executor
         *            the BTExecutor in charge of running this ExecutionParallel.
         * @param parent
         *            the parent ExecutionTask of this task.
         */
        public ExecutionParallel(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelParallel))
            {
                throw new ArgumentException("The ModelTask must subclass " + typeof (ModelParallel).Name + " but it inherits from " +
                                            modelTask.GetType().Name);
            }

            _policy = ((ModelParallel)modelTask).Policy;
            _modelChildren = modelTask.Children;
            Initialize();
        }
Exemplo n.º 17
0
        /**
         * This method sets the positions of all tasks below <code>t</code> in the
         * tree.
         *
         * @param t
         *            the task whose descendants will be computed their positions.
         */

        private void RecursiveComputePositions(ModelTask t)
        {
            /*
             * Set the position of all of the children of this task and recursively
             * compute the position of the rest of the tasks.
             */
            for (var i = 0; i < t._children.Count; i++)
            {
                var currentChild    = t._children[i];
                var currentChildPos = new Position(t.Position);
                currentChildPos.AddMove(i);
                currentChild._position = currentChildPos;
                RecursiveComputePositions(currentChild);
            }
        }
Exemplo n.º 18
0
        /**
         * This method computes the positions of all the tasks of the behaviour tree
         * whose root is this node. After calling this method, the positions of all
         * the tasks below this one will be available and accessible through
         * {@link #getPosition()}.
         * <p>
         * It is important to note that, when calling this method, this task is
         * considered to be the root of the behaviour tree, so its position will be
         * set to an empty sequence of moves, with no offset, and the positions of
         * the tasks below it will be computed from it.
         */
        public void ComputePositions()
        {
            /* Assume this node is the root of the tree. */
            _position = new Position(new List <int>());

            /*
             * Set the position of all of the children of this task and recursively
             * compute the position of the rest of the tasks.
             */
            for (var i = 0; i < _children.Count; i++)
            {
                ModelTask currentChild    = _children[i];
                var       currentChildPos = new Position(_position);
                currentChildPos.AddMove(i);
                currentChild._position = currentChildPos;
                RecursiveComputePositions(currentChild);
            }
        }
 /**
  * Constructor.
  *
  * @param guard
  *            the guard of the ModelHierarchicalContextManager, which may be null.
  * @param child
  *            the child of the ModelHierarchicalContextManager.
  */
 public ModelHierarchicalContextManager(ModelTask guard, ModelTask child)
     : base(guard, child)
 {
 }
Exemplo n.º 20
0
 private void Initialize(ModelTask modelTask)
 {
     duration = ((ModelWait) modelTask).Duration;
 }
 /**
  * Creates a ModelDynamicPriorityList task with a guard, and a list of
  * children to run. A ModelDynamicPriorityList must have at least one child.
  *
  * @param guard
  *            the guard, which may be null.
  * @param children
  *            the list of children. Must have at least one element.
  */
 public ModelDynamicPriorityList(ModelTask guard, params ModelTask[] children)
     : base(guard, children)
 {
 }
Exemplo n.º 22
0
        /**
         * Creates a BTExecutor that handles the execution of a behaviour tree. The behaviour tree is
         * represented by a ModelTask (the root of the tree).
         * <p>
         * A new empty context for the tree is created. This context is passed to the root of the tree,
         * and, in general, it will be shared by all the nodes in the tree (it will be passed down the
         * hierarchy of the tree). Note however that, depending on the semantics of the tree itself,
         * some nodes may not use the context context.
         *
         * @param modelBT
         *            the root of the behaviour tree to run.
         */
        public BTExecutor(ModelTask modelBT)
        {
            if (modelBT == null)
            {
                throw new ArgumentException("The input ModelTask cannot be null");
            }

            _modelBT = modelBT;
            _modelBT.ComputePositions();
            _context = new BasicContext();
            _tickableTasks = new List<ExecutionTask>();
            _openTasks = new List<ExecutionTask>();
            _currentOpenInsertions = new List<ExecutionTask>();
            _currentOpenRemovals = new List<ExecutionTask>();
            _currentTickableInsertions = new List<ExecutionTask>();
            _currentTickableRemovals = new List<ExecutionTask>();
            _interrupters = new Dictionary<ModelInterrupter, ExecutionInterrupter>();
            _tasksStates = new Dictionary<Position, ITaskState>();
        }
 public StubExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
 }
Exemplo n.º 24
0
        /**
         * Constructs an ExecutionTask with an associated ModelTask and a
         * BTExecutor. The ModelTask represents the conceptual task that the
         * ExecutionTask is running, and the BTExecutor is that in charge of the
         * ExecutionTask. Also, the parent of the ExecutionTask must be provided.
         *
         * @param modelTask
         *            the ModelTask this ExecutionTask will run.
         * @param executor
         *            the BTExecutor managing this task.
         * @param parent
         *            the parent ExecutionTask, or null in case this is the root of
         *            the tree.
         */
        protected ExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
        {
            _modelTask = modelTask;
            _executor = executor as BTExecutor;
            _listeners = new List<ITaskListener>();
            _spawnable = true;
            _tickable = false;
            _terminated = false;
            _status = Status.Uninitialized;
            _parent = parent;

            if(_modelTask != null)
                AlwaysFail = modelTask.AlwaysFail;

            /* Compute the position of this node. */
            if (parent == null)
            {
                _position = new Position();
            }
            else
            {
                _position = new Position(parent._position);
                var nextMove = GetMove();
                _position.AddMove(nextMove);
            }
        }
 /**
  * Creates a ModelRandomSelector with a guard and several children. The list
  * of children cannot be empty.
  *
  * @param guard
  *            the guard of the ModelRandomSelector, which may be null.
  * @param children
  *            the list of children, which cannot be empty.
  */
 public ModelRandomSelector(ModelTask guard, params ModelTask[] children)
     : base(guard, children)
 {
 }
 /**
  * Constructor.
  *
  * @param guard
  *            the guard of the ModelSafeOutputContextManager, which may be
  *            null.
  * @param child
  *            the child of the ModelSafeOutputContextManager.
  * @param outputVariables
  *            the list of output variables of the SafeOutputContext that is
  *            created.
  */
 public ModelSafeOutputContextManager(ModelTask guard, List<string> outputVariables, ModelTask child)
     : base(guard, child)
 {
     this.outputVariables = outputVariables;
 }
Exemplo n.º 27
0
 /**
  * This method sets the positions of all tasks below <code>t</code> in the
  * tree.
  *
  * @param t
  *            the task whose descendants will be computed their positions.
  */
 private void RecursiveComputePositions(ModelTask t)
 {
     /*
      * Set the position of all of the children of this task and recursively
      * compute the position of the rest of the tasks.
      */
     for (var i = 0; i < t._children.Count; i++)
     {
         var currentChild = t._children[i];
         var currentChildPos = new Position(t.Position);
         currentChildPos.AddMove(i);
         currentChild._position = currentChildPos;
         RecursiveComputePositions(currentChild);
     }
 }
Exemplo n.º 28
0
 /**
  * Constructor.
  * <p>
  * Constructs a ModelDecorator with one child.
  *
  * @param guard
  *            the guard of the ModelDecorator. which may be null.
  * @param child
  *            the child of the ModelDecorator.
  */
 protected ModelDecorator(ModelTask guard, ModelTask child)
     : base(guard, child)
 {
 }
Exemplo n.º 29
0
 /**
  * Creates a new ModelTask with a guard and several children. The guard may
  * be null, in which case it is always evaluated to true. The task may also
  * have no children.
  *
  * @param guard
  *            the guard, which may be null.
  * @param children
  *            the list of children.
  */
 protected ModelTask(ModelTask guard, params ModelTask[] children)
     : this(guard, null, children)
 {
 }
Exemplo n.º 30
0
 /**
  * Constructor.
  * <p>
  * Constructs a ModelComposite with some children. A ModelComposite must
  * have at least one child.
  *
  * @param guard
  *            the guard of the ModelComposite.
  * @param children
  *            the list of children. Must have at least one element.
  */
 protected ModelComposite(ModelTask guard, params ModelTask[] children)
     : this(guard, null, children)
 {
 }
 /**
  * Creates a ModelRandomSequence with a guard and several children. The list
  * of children cannot be empty.
  *
  * @param guard
  *            the guard of the ModelRandomSequence, which may be null.
  * @param children
  *            the list of children, which cannot be empty.
  */
 public ModelRandomSequence(ModelTask guard, params ModelTask[] children)
     : base(guard, children)
 {
 }
Exemplo n.º 32
0
 public TestTask(ModelTask guard, params ModelTask[] children)
     : base(guard, children)
 {
 }
 /**
  * Constructor.
  *
  * @param guard
  *            the guard of the task, which may be null.
  * @param variableName
  *            the name of the variable to rename.
  * @param newVariableName
  *            the new name for the variable.
  */
 public ModelVariableRenamer(ModelTask guard, string variableName, string newVariableName)
     : base(guard)
 {
     _variableName = variableName;
     _newVariableName = newVariableName;
 }
Exemplo n.º 34
0
 /**
  * Constructor.
  *
  * @param guard
  *            the guard of the ModelRepeat, which may be null.
  * @param child
  *            the child that will be run forever.
  */
 public ModelRepeat(ModelTask guard, ModelTask child)
     : base(guard, child)
 {
 }