/** * 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); } }
/** * 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); } }
/** * 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 ExecutionAction that knows how to run a ModelAction. * * @param modelTask * the ModelAction to run. * @param executor * the BTExecutor that will manage this ExecutionAction. * @param parent * the parent ExecutionTask of this task. */ protected ExecutionAction(ModelAction modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (modelTask == null ) { throw new ArgumentException("The ModelTask must not be null" ); } }
/** * 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); } }
/** * 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); } }
public void CanRegisterAnInterrupter() { var executor = new BTExecutor(new ModelSuccess(null)); var modelInterrupter = new ModelInterrupter(null, new ModelSuccess(null)); executor.RegisterInterrupter((ExecutionInterrupter)modelInterrupter.CreateExecutor(executor, null)); Assert.NotNull(executor.GetExecutionInterrupter(modelInterrupter)); }
/** * 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); } }
/** * 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 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); } }
/** * 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); }
/** * 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; }
/** * 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(); }
/** * Returns an ExecutionDynamicPriorityList that is able to run this * ModelDynamicPriorityList. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionDynamicPriorityList(this, executor, parent); }
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new TestInterrupterExecutor(this, executor, parent); }
/** * Copies the set of all tasks' states stored in <code>executor</code> into this BTExecutor. * <p> * <b>After calling this method, the set of all tasks' states is shared by both BTExecutor * objects (<code>executor</code> and <code>this</code>), so if one modifies it, the other will * notice the change.</b> */ public void CopyTasksStates(BTExecutor executor) { _tasksStates = executor._tasksStates; }
/** * Returns an ExecutionRandomSelector that knows how to run this * ModelRandomSelector. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionRandomSelector(this, executor, parent); }
public MyAction(ModelAction modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { ReturnStatusForInternalTick = Status.Running; }
/** * Returns an ExecutionSubtreeLookup that is able to run this * ModelSubtreeLookup. */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionSubtreeLookup(this, executor, parent); }
/** * Creates an ExecutionSequence that is able to run a ModelSequence task and * that is managed by a BTExecutor. * * @param modelTask * the ModelSequence that this ExecutionSequence is going to run. * @param executor * the BTExecutor in charge of running this ExecutionSequence. * @param parent * the parent ExecutionTask of this task. */ public ExecutionSequence(ModelSequence modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { }
/// ///Interrupts the ExecutionInterrupter. This method causes the ///ExecutionInterrupter to terminate its child and set the status that will ///be returned to <code>status</code>. Also, it requests to be inserted into ///the list of tickable nodes, since the terminated child will no longer ///react to ticks after being terminated. ///<p> ///A task that have not been spawned cannot be interrupted. It should be ///noted that if the task has already been terminated, this method does ///nothing. Also, if the task has already been interrupted, this method does ///nothing too. /// ///@param status /// the status that the ExecutionInterrupter will return. /// public void Interrupt(Status status) { if (!_interrupted) { /// ///If the task has not been spawned, throw an exception. /// if (!Spawned) { throw new Exception("Cannot interrupt an ExecutionInterrupter that has not been spawned"); } /// ///Also it is important to note that that if the task has been ///terminated it cannot be interrupted, since by doing so the task ///would insert itself into the list of tickable nodes (see below), ///which should not be done since the task has been terminated. /// if (!HasTerminated) { if (status != Status.Failure && status != Status.Success) { throw new ArgumentException("The specified status is not valid. Must be either Status.FAILURE or Status.SUCCESS"); } if (_executionChild.ModelTask.Interrupter != null) { var executor = new BTExecutor(_executionChild.ModelTask.Interrupter, Context); RunInterrupterBranch(executor, ((ModelInterrupter)ModelTask).NumInterrupterBranchTicks + 1); } _executionChild.Terminate(); ///It is very important for the ExecutionInterrupter to be ///inserted into the list of tickable nodes. If not, after being ///interrupted, it will not inform its parent about the ///termination of its child. Keep in mind that after terminating ///its child, the child will not react to ticks (actually it ///will leave the list of tickable nodes in the next AI cycle), ///so it has to be the interrupter itself that informs its ///parent about termination. Executor.RequestInsertionIntoList(BTExecutor.BTExecutorList.Tickable, this); _interrupted = true; _statusSet = status; } } }
/** * 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); } }
/** * Returns an ExecutionSafeOutputContextManager that knows how to run this * ModelSafeOutputContextManager. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionSafeOutputContextManager(this, executor, parent); }
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return null; }
/** * Returns an ExecutionContextManager that knows how to run this * ModelHierarchicalContextManager. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionHierarchicalContextManager(this, executor, parent); }
/** * Resets the evaluation of all the guards. This method leaves all the guard * executors ({@link #guardsExecutors}) ready to start again the evaluation * of the guards. It internally terminates the IBTExecutor of each guard, * creates a new one, and then ticks it. */ private void resetGuardsEvaluation() { for (int i = 0; i < _guardsExecutors.Count; i++) { BTExecutor guardExecutor = _guardsExecutors[i]; if (guardExecutor != null) { guardExecutor.Terminate(); guardsResults[i] = Status.Running; var newExecutor = new BTExecutor(guardExecutor.GetBehaviourTree(), Context); newExecutor.CopyTasksStates(guardExecutor); newExecutor.Tick(); _guardsExecutors[i] = newExecutor; } } }
/** * Constructs an ExecutionCondition that knows how to run a ModelCondition. * * @param modelTask * the ModelCondition to run. * @param executor * the BTExecutor that will manage this ExecutionCondition. * @param parent * the parent ExecutionTask of this task. */ protected ExecutionCondition(ModelCondition modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { }
/** * Creates a suitable ExecutionTask that will be able to run this ModelTask * through the management of a BTExecutor. * * @param executor * the BTExecutor that will manage the returned ExecutionTask. * @param parent * the parent ExecutionTask for the returned ExecutionTask. * * @return an ExecutionTask that is able to run this ModelTask. */ public abstract ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent);
/** * Returns a new {@link ExecutionVariableRenamer} that knows how to run this * ModelVariableRenamer. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * jbt.execution.core.ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionVariableRenamer(this, executor, parent); }
/** * Returns an ExecutionForever that knows how to run this ModelRepeat. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return new ExecutionRepeat(this, executor, parent); }