/**
         * 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);
            }
        }
 public ExecutionComposite(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(typeof(ModelComposite).IsAssignableFrom(modelTask.GetType()))) {
         throw new ArgumentException("The ModelTask " + modelTask.GetType() + " must subclass "
         + typeof(ModelComposite) + " but it inherits from "
         + modelTask.GetType().BaseType);
     }
 }
 /**
  * Creates an ExecutionDecorator that is able to run a particular
  * ModelDecorator task.
  *
  * @param modelTask
  *            the ModelDecorator task to run.
  * @param executor
  *            the BTExecutor that will manage this ExecutionDecorator.
  * @param parent
  *            the parent ExecutionTask of this task.
  */
 public ExecutionDecorator(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelDecorator))
     {
         throw new ArgumentException("The ModelTask must subclass ModelDecorator but it inherits from " +
                                     modelTask.GetType().Name);
     }
 }
 public static void RunInterrupterBranch(IBTExecutor executor, int numTicks)
 {
     var counter = 0;
     do
     {
         executor.Tick();
         counter++;
     } while (executor.GetStatus() == Status.Running && counter < numTicks);
 }
        /**
         * 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);
            }
        }
 /**
  * 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);
     }
 }
 public ExecutionSelector(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelSelector)) {
         throw new ArgumentException("The ModelTask must subclass "
         + typeof(ModelSelector) + " but it inherits from "
         + modelTask.GetType().BaseType);
     }
 }
Exemple #8
0
        /**
         * Creates an ExecutionDecorator that is able to run a particular
         * ModelDecorator task.
         *
         * @param modelTask
         *            the ModelDecorator task to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionDecorator.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionDecorator(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelDecorator))
            {
                throw new ArgumentException("The ModelTask must subclass ModelDecorator but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
Exemple #9
0
        public static void RunInterrupterBranch(IBTExecutor executor, int numTicks)
        {
            var counter = 0;

            do
            {
                executor.Tick();
                counter++;
            } while (executor.GetStatus() == Status.Running && counter < numTicks);
        }
Exemple #10
0
        /**
         * This method ticks <code>executor</code> {@value #NUM_TICKS_LONG_TICK} times. If the executor
         * finishes earlier, it is not ticked anymore, and the ticking process stops.
         *
         * @param executor
         *            the IBTExecutor that is ticked.
         */

        private void longTick(IBTExecutor executor)
        {
            if (executor.GetStatus() == Status.Running || executor.GetStatus() == Status.Uninitialized)
            {
                int counter = 0;
                do
                {
                    executor.Tick();
                    counter++;
                } while (executor.GetStatus() == Status.Running && counter < NumTicksLongTick);
            }
        }
        public ExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
        {
            this.modelTask = modelTask;
            this.executor = executor;
            this.spawnable = true;
            this.tickable = false;
            this.status = TaskStatus.UNINITIALISED;

            if (parent == null) {
                this.position = new Position();
            }
            else {
                this.position = new Position(parent.position);
                this.position.AddMove(GetMove());
                this.parent = parent;
            }
        }
Exemple #12
0
        /**
         * Evaluate all the guards that have not finished yet, that is, those whose
         * result in {@link #guardsResults} is {@link Status#RUNNING}, by ticking
         * them.
         * <p>
         * If all the guards have finished in failure, this method returns a Tuple
         * whose first element is {@link Status#FAILURE}. If there is at least one
         * guard still being evaluated, the first element of the Tuple contains
         * {@link Status#RUNNING}. If all the guards have been evaluated and at
         * least one has succeeded, the first element of the Tuple is
         * {@link Status#SUCCESS}, and the second one is the index, over the list of
         * guards ({@link #guardsExecutors}) , of the first guard (that with the
         * highest priority) that has succeeded.
         *
         */

        private Tuple <Status, int> evaluateGuards()
        {
            bool oneRunning = false;

            /* First, evaluate all the guards that have not finished yet. */
            for (int i = 0; i < _guardsExecutors.Count; i++)
            {
                IBTExecutor guardExecutor = _guardsExecutors[i];
                if (guardExecutor != null)
                {
                    if (guardsResults[i] == Status.Running)
                    {
                        guardExecutor.Tick();
                        guardsResults[i] = guardExecutor.GetStatus();
                        if (guardsResults[i] == Status.Running)
                        {
                            oneRunning = true;
                        }
                    }
                }
            }

            /* If there is at least one still running... */
            if (oneRunning)
            {
                return(new Tuple <Status, int>(Status.Running, -1));
            }

            /* If all of them have finished we check which one succeeded first. */
            for (int i = 0; i < guardsResults.Count; i++)
            {
                if (guardsResults[i] == Status.Success)
                {
                    return(new Tuple <Status, int>(Status.Success, i));
                }
            }

            /* Otherwise, the evaluation has failed. */
            return(new Tuple <Status, int>(Status.Failure, -1));
        }
        /**
         * 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);
            }
        }
Exemple #14
0
 ///Creates an ExecutionInterrupter that is able to run a ModelInterrupter
 ///task and that is managed by a BTExecutor.
 ///
 ///@param modelTask the ModelInterrupter that this ExecutionInterrupter is going to run.
 ///@param executor the BTExecutor in charge of running this ExecutionInterrupter.
 ///@param parent the parent ExecutionTask of this task.
 public ExecutionInterrupter(ModelInterrupter modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     _interrupted = false;
 }
 public TestInterrupterExecutor(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
 }
 public void TriggerExecution()
 {
     if (this.TypeOfExecution == ExecutionType.TRIGGER) {
         if (this.executor == null) {
             this.executor = this.GetExecutor();
         }
         if (!running) {
             running = true;
             StartCoroutine("TickExecutorParallel");
             this.FireOutput("OnExecutionTrigger");
         }
     }
 }
 public StubExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
 }
 ///Creates an ExecutionInterrupter that is able to run a ModelInterrupter
 ///task and that is managed by a BTExecutor.
 ///
 ///@param modelTask the ModelInterrupter that this ExecutionInterrupter is going to run.
 ///@param executor the BTExecutor in charge of running this ExecutionInterrupter.
 ///@param parent the parent ExecutionTask of this task.
 public ExecutionInterrupter(ModelInterrupter modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     _interrupted = false;
 }
 public override ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent)
 {
     return new ExecutionStatusResponder(this, btExecutor, parent);
 }
 public override ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent)
 {
     return new ExecutionSequence(this, btExecutor, parent);
 }
 /// <summary>
 /// Creates a suitable ExecutionTask that will be able to run this ModelTask
 /// through the management of a BTExecutor.
 /// </summary>
 /// <param name="btExecutor"></param>
 /// <param name="parent"></param>
 /// <returns></returns>
 public abstract ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent);
 public void Start()
 {
     this.executor = this.GetExecutor();
     if (this.TypeOfExecution == ExecutionType.AUTO) {
         running = true;
         StartCoroutine("TickExecutorParallel");
     }
 }
 public StubExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent)
 {
 }
Exemple #24
0
        /**
         * Evaluate all the guards that have not finished yet, that is, those whose result in
         * {@link #guardsResults} is {@link Status#RUNNING}, by ticking them.
         * <p>
         * If all the guards have finished in failure, this method returns a Tuple whose first element is
         * {@link Status#FAILURE}. If guards' evaluation has not completed yet, the first element of the
         * Tuple contains {@link Status#RUNNING}. If all the guards have been evaluated and at least one
         * has succeeded, the first element of the Tuple is {@link Status#SUCCESS}, and the second one is
         * the index, over the list of guards ({@link #guardsExecutors}) , of the first guard (that with
         * the highest priority) that has succeeded.
         *
         */

        private Tuple <Status, int> EvaluateGuards()
        {
            /*
             * Tick all the guards that are still running. If one changes its status to SUCCESS and it
             * matches the guard associated to "indexMostRelevantGuard", then the guards' evaluation is
             * over and that is the selected guard.
             */
            for (int i = 0; i < _guardsExecutors.Count; i++)
            {
                IBTExecutor guardExecutor = _guardsExecutors[i];

                if (guardExecutor != null)
                {
                    if (_guardsResults[i] == Status.Running)
                    {
                        longTick(guardExecutor);

                        _guardsResults[i] = guardExecutor.GetStatus();

                        if (guardExecutor.GetStatus() != Status.Running)
                        {
                            /*
                             * If the guard has finished, we check if it matches the
                             * "most relevant guard".
                             */
                            if (i == _indexMostRelevantGuard)
                            {
                                if (guardExecutor.GetStatus() == Status.Success)
                                {
                                    return(new Tuple <Status, int>(Status.Success, i));
                                }

                                /*
                                 * If the guard failed, we have to find the next
                                 * "most relevant guard" and update "indexMostRelevantGuard"
                                 * accordingly. For that we check the status of the following
                                 * guards. If we find a successful guard before any running guard,
                                 * then the guards' evaluation is over, and that is the selected
                                 * guard. If we find a running guard before, then that's the new
                                 * "most relevant guard". Otherwise, the evaluation has failed, and
                                 * there is no successful guard.
                                 */
                                bool oneRunning = false;

                                for (int k = _indexMostRelevantGuard + 1; k < _guardsExecutors.Count; k++)
                                {
                                    if (_guardsExecutors[k] != null)
                                    {
                                        Status currentResult = _guardsExecutors[k].GetStatus();
                                        if (currentResult == Status.Running)
                                        {
                                            _indexMostRelevantGuard = k;
                                            oneRunning = true;
                                            break;
                                        }
                                        if (currentResult == Status.Success)
                                        {
                                            return(new Tuple <Status, int>(Status.Success, k));
                                        }
                                    }
                                    else
                                    {
                                        return(new Tuple <Status, int>(Status.Success, k));
                                    }
                                }

                                if (!oneRunning)
                                {
                                    return(new Tuple <Status, int>(Status.Failure, -1));
                                }
                            }
                        }
                    }
                }
                else
                {
                    /* Remember, null guard means successful evaluation. */
                    if (i == _indexMostRelevantGuard)
                    {
                        return(new Tuple <Status, int>(Status.Success, i));
                    }
                }
            }

            return(new Tuple <Status, int>(Status.Running, -1));
        }
 public TestInterrupterExecutor(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
 }
 /**
  * This method ticks <code>executor</code> {@value #NUM_TICKS_LONG_TICK} times. If the executor
  * finishes earlier, it is not ticked anymore, and the ticking process stops.
  *
  * @param executor
  *            the IBTExecutor that is ticked.
  */
 private void longTick(IBTExecutor executor)
 {
     if (executor.GetStatus() == Status.Running || executor.GetStatus() == Status.Uninitialized)
     {
         int counter = 0;
         do
         {
             executor.Tick();
             counter++;
         } while (executor.GetStatus() == Status.Running && counter < NumTicksLongTick);
     }
 }