Beispiel #1
0
        static void RecordDecompositionOfTask(State plannerState, CompoundTask CurrentTaskCompound, Stack <State> DecompHistory)
        {
            var copy = new State {
                finalPlan      = new List <TaskBase>(plannerState.finalPlan),
                tasksToProcess = new Stack <TaskBase>(plannerState.tasksToProcess),
                workingWS      = plannerState.workingWS.Clone(),
                nextMethodIdx  = plannerState.nextMethodIdx,
                nextMethodPtr  = plannerState.nextMethodPtr
            };

            copy.tasksToProcess.Push(CurrentTaskCompound);
            DecompHistory.Push(copy);
        }
Beispiel #2
0
        static Method FindSatisfiedMethod(CompoundTask CurrentTaskCompound, IState state, ref int nextMethodIdx)
        {
            var methodState = state.Clone();

            var methods = CurrentTaskCompound.methods.OrderByDescending(m => m.Score(state)).ToList();

            for (; nextMethodIdx < methods.Count; ++nextMethodIdx)
            {
                var method = methods[nextMethodIdx];

                if (!method.Check(methodState))
                {
                    continue;
                }

                var methodValid = true;
                foreach (var task in method.tasks)
                {
                    if (!task.Check(methodState))
                    {
                        //Debug.Log(CurrentTaskCompound + " not satisfied because " + task + " check failed");

                        methodValid = false;
                        break;
                    }

                    task.Apply(methodState);
                }

                if (methodValid)
                {
                    ++nextMethodIdx;
                    return(method);
                }
            }
            nextMethodIdx = 0;
            return(null);
        }