Ejemplo n.º 1
0
 public void planFailed(HashSet <KeyValuePair <string, object> > failedGoal)
 {
     // Not handling this here since we are making sure our goals will always succeed.
     // But normally you want to make sure the world state has changed before running
     // the same goal again, or else it will just fail.
     Debug.Log("<color=orange>Plan Failed</color> " + GoapAgent.prettyPrint(failedGoal));
 }
Ejemplo n.º 2
0
    public void GetPlanner()
    {
        // GOAP planning
        // get the world state and the goal we want to plan for
        Dictionary <string, bool> worldState = goapAgent.dataProvider.getWorldState();
        Dictionary <string, bool> goal       = goapAgent.dataProvider.createGoalState();

        // Plan
        Queue <GoapAction> executeActionQueue = goapPlanner.plan(goapAgent.gameObject, availableActions, worldState, goal);

        if (executeActionQueue != null && executeActionQueue.Count > 0)
        {
            // we have a plan, hooray!
            currentActions = executeActionQueue;
            goapAgent.stateMachine.clearState();
            goapAgent.stateMachine.pushState(FSMStateEnum.Perform);
        }
        else
        {
            // ugh, we couldn't get a plan
            Debug.Log("<color=orange>Failed Plan:</color>" + GoapAgent.prettyPrint(goal));
            goapAgent.stateMachine.clearState();
            goapAgent.stateMachine.pushState(FSMStateEnum.Idle);
        }
    }
Ejemplo n.º 3
0
 public void planAborted(GoapAction aborter)
 {
     // An action bailed out of the plan. State has been reset to plan again.
     // Take note of what happened and make sure if you run the same goal again
     // that it can succeed.
     Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter));
 }
Ejemplo n.º 4
0
Archivo: CrewAI.cs Proyecto: Thaon/GOAP
    public void planFound(HashSet <KeyValuePair <string, object> > goal, Queue <Action> actions)
    {
        // write to the log the queue of actions found
        Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions));

        //set the text on the action display done here for static actions purposes
        m_indicator.text = actions.Peek().GetType().ToString();
    }
Ejemplo n.º 5
0
 public void planFound(KeyValuePair <string, bool> goal, Queue <GoapAction> actions)
 {
     // Yay we found a plan for our goal
     if (EnableLog)
     {
         Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions));
     }
 }
Ejemplo n.º 6
0
 public void PlanAborted(GoapAction aborter)
 {
     // An action bailed out of the plan. State has been reset to plan again.
     // Take note of what happened and make sure if you run the same goal again
     // that it can succeed.
     // Console.WriteLine("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter));
     _actorTextOutput.Tell("Plan Aborted " + GoapAgent.prettyPrint(aborter));
 }
Ejemplo n.º 7
0
 public void planFound(HashSet <KeyValuePair <string, object> > goal, Queue <GoapAction> actions)
 {
     // Yay we found a plan for our goal
     if (goalDebug)
     {
         Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions));
     }
 }
    private void drawCurrentPlan(GoapAgent agent, Queue <GoapAction> actions)
    {
        GUIStyle style = new GUIStyle();

        style.normal.textColor = Color.green;

        Handles.BeginGUI();
        GUILayout.Label("Current plan:\r\n" + GoapAgent.prettyPrint(actions) + "\r\n\r\n" +
                        "Currently in state: " + agent.CurrentFSMState + "\r\n\r\n", style);
        Handles.EndGUI();
    }
Ejemplo n.º 9
0
    /**
     * Returns true if at least one solution was found.
     * The possible paths are stored in the leaves list. Each leaf has a
     * 'runningCost' value where the lowest cost will be the best action
     * sequence.
     */

    private bool BuildGraph(Node_ parent, List <Node_> leaves, HashSet <GoapAction> usableActions, List <Goal> goals)
    {
        bool foundOne = false;

        foreach (GoapAction action in usableActions)
        {
            //if the parent's state (world state) has the conditions for this action's preconditions, we can use it here
            if (PreconditionsInWorldState(action, action._preconditions, parent.state))
            { //parent.state is the world's state in this instance
                List <Condition> currentState = PopulateState(parent.state, action._effects);


                Node_ node = new Node_(parent, parent.runningCost + action.cost, currentState, action);


                if (GoalInState(goals, currentState))
                {
                    //if the goal aligns with the state --
                    //I think this is the constantly changing thing to see if each step satisfies the last
                    leaves.Add(node);
                    foundOne = true;
                }
                else
                {
                    HashSet <GoapAction> subset = actionSubset(usableActions, action); //taking all actions and the current action in this iteration . The current action needs to be removed because it didn't match the goal

                    bool found = BuildGraph(node, leaves, subset, goals);              //this time we're redoing this whole thing while taking the useless action out of the equation, but why? What makes this action useless?
                                                                                       //(The goal isn't found in this one?)
                    if (found)
                    {
                        foundOne = true;
                    }
                }
            }
            else
            {
                Debug.Log(action.ToString() + " Preconditions aren't in the world state");
                GoapAgent.prettyPrint(action);
            }
        }

        return(foundOne);
    }
Ejemplo n.º 10
0
    private void drawCurrentAction(GoapAgent agent, GoapAction action)
    {
        Handles.color = Color.green;
        if (action.target != null)
        {
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;

            Handles.BeginGUI();
            GUILayout.Label("Current action: " + GoapAgent.prettyPrint(action) + '\n' +
                            "Current target: " + action.target.name + '\n' +
                            "Currently in range? " + action.isInRange, style);
            Handles.EndGUI();

            Handles.DrawLine(agent.transform.position, action.target.transform.position);
            Handles.Label(action.target.transform.position + labelYOffset * Vector3.up, "Target", style);

            style.normal.textColor = Color.green;
            Handles.Label(agent.transform.position + labelYOffset * Vector3.up, "Distance to target: " +
                          (action.target.transform.position - agent.transform.position).magnitude, style);
        }
    }
Ejemplo n.º 11
0
 private void loadActions()
 {
     availableActions = goapAgent.dataProvider.initAction(goapAgent.transform);
     GoapAction[] actions = availableActions.ToArray();
     Debug.Log("Found actions: " + GoapAgent.prettyPrint(actions));
 }
Ejemplo n.º 12
0
 public void planFound(Dictionary <string, bool> goal, Queue <GoapAction> actions)
 {
     // Yay we found a plan for our goal
     Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions));
 }
Ejemplo n.º 13
0
 public void planAborted(GoapAction aborter)
 {
     Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter));
 }
Ejemplo n.º 14
0
Archivo: CrewAI.cs Proyecto: Thaon/GOAP
 public void planAborted(Action aborter)
 {
     // log the action that made us fail
     Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter));
 }
Ejemplo n.º 15
0
 public void planAborted(GoapAction aborter)
 {
     // An action failed and made the plan abort. State has been reset to plan again.
     Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter));
 }
Ejemplo n.º 16
0
 public void planFound(Dictionary <string, object> goal, Queue <GoapAction> actions)
 {
     Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions));
 }
Ejemplo n.º 17
0
//i//

    /**
     * Plan what sequence of actions can fulfill the goal.
     * Returns null if a plan could not be found, or a list of the actions
     * that must be performed, in order, to fulfill the goal.
     */



    public Queue <GoapAction> Plan(GameObject agent, HashSet <GoapAction> availableActions, List <Condition> worldState, List <Goal> goal)
    {
        // reset the actions so we can start fresh with them

        foreach (GoapAction a in availableActions)
        {
            a.doReset();
        }

        // check what actions can run using their checkProceduralPrecondition

        HashSet <GoapAction> usableActions = new HashSet <GoapAction>();

        foreach (GoapAction a in availableActions)
        {
            if (a.checkProceduralPrecondition(agent))
            {
                usableActions.Add(a);
            }
            else
            {
                Debug.Log(a.ToString() + " 's precondition check failed");
                GoapAgent.prettyPrint(a);
            }
        }


        // we now have all actions that can run, stored in usableActions
        // build up the tree and record the leaf nodes that provide a solution to the goal.

        List <Node_> leaves = new List <Node_>();

        //build graph
        Node_ start = new Node_(null, 0, worldState, null);

        bool success = BuildGraph(start, leaves, usableActions, goal);

        if (!success)
        {
            //Debug.log("No Plan");
            return(null);
        }

        Node_ cheapest = null;

        foreach (Node_ leaf in leaves)
        {
            if (cheapest == null)
            {
                cheapest = leaf;
            }
            else
            {
                if (leaf.runningCost < cheapest.runningCost)
                {
                    cheapest = leaf;
                }
            }
        }

        //get its node and work back through the parents
        List <GoapAction> result = new List <GoapAction>();
        Node_             n      = cheapest;

        while (n != null)
        {
            if (n.action != null)
            {
                result.Insert(0, n.action);
            }
            n = n.parent;
        }
        //we now have this action list in correct order

        Queue <GoapAction> queue = new Queue <GoapAction>();

        foreach (GoapAction a in result)
        {
            queue.Enqueue(a);
        }
        //hooray we have a plan!
        return(queue);
    }