public List <TaskBase> Planning(IWorldState currentState, TaskBase rootTask) { plannerStateHistory.Clear(); plannerState = new PlannerState( currentState.Clone(), new List <TaskBase>(), new List <TaskBase>() { rootTask }, 0); while (plannerState.TaskListToProcess.Count > 0) { var currentTask = plannerState.TaskListToProcess[0]; Debug.Log("CurrentTask:" + currentTask); if (currentTask is CompoundTask currentCompoundTask) { var satisfiedMethod = FindSatisfiedMethod(currentCompoundTask, plannerState); if (satisfiedMethod != null) { RecordDecompositionOfTask(currentCompoundTask); plannerState.TaskListToProcess.RemoveAt(0); plannerState.TaskListToProcess.InsertRange(0, satisfiedMethod.SubTasks); } else { RestoreToLastDecomposedTask(); } } else // PrimitiveTask { if (currentTask.CheckPreCondition(plannerState.WorkingWS)) { plannerState.TaskListToProcess.RemoveAt(0); plannerState.FinalPlanList.Add(currentTask); plannerState.WorkingWS = currentTask.ApplyEffects(plannerState.WorkingWS); } else { RestoreToLastDecomposedTask(); } } } return(new List <TaskBase>(plannerState.FinalPlanList)); }
public virtual IWorldState ApplyEffects(IWorldState state) { return(state.Clone()); }