Example #1
0
    private void CreatePlanningState()
    {
        planningState = (fsm, gameObj) =>
        {
            Dictionary <string, object> worldState = worldDataProvider.GetWorldState();
            Dictionary <string, object> goalState  = worldDataProvider.CreateGoalState();

            Queue <GAction> plan = planner.Plan(this, availableActions, worldState, goalState);
            if (plan != null)
            {
                currentActions = plan;
                worldDataProvider.PlanFound(goalState, plan);

                fsm.PopState();
                fsm.PushState(performActionState);
            }
            else
            {
                Debug.Log("Planning failed! Goal: " + goalState);
                worldDataProvider.PlanFailed(goalState);
                fsm.PopState();
                fsm.PushState(planningState);
            }
        };
    }
Example #2
0
    private void CreatePerformActionState()
    {
        performActionState = (fsm, gagent) =>
        {
            if (!HasActionPlan())
            {
                Debug.Log("Done with actions, planning new actions.");
                fsm.PopState();
                fsm.PushState(planningState);
                worldDataProvider.ActionsFinished();
                return;
            }

            GAction action = currentActions.Peek();
            if (action.IsDone())
            {
                currentActions.Dequeue();
            }

            if (HasActionPlan())
            {
                action = currentActions.Peek();
                bool success = action.Perform(gagent);

                if (!success)
                {
                    fsm.PopState();
                    fsm.PushState(planningState);
                    worldDataProvider.PlanAborted(action);
                }
            }
            else
            {
                fsm.PopState();
                fsm.PushState(planningState);
                worldDataProvider.ActionsFinished();
            }
        };
    }