コード例 #1
0
    public bool IsPlanValid(AStarGOAPNode currentNode)
    {
        /*if (Owner.debugGOAP)
         * {
         * if (Map.GetAction(currentNode.NodeID) != null)
         * Debug.Log("IsPlanValid : GOAL");
         * else
         * Debug.Log("IsPlanValid node id :" + currentNode.NodeID);
         *
         *      int ii = 0;
         *      AStarNode a = currentNode;
         *      while (Map.GetAction(a.NodeID) != null)
         *      {
         *              Debug.Log(ii + ". " + Map.GetAction(a.NodeID).ToString());
         *              a = a.Parent;
         *              ii++;
         *      }
         * }*/

        //if (Owner.debugGOAP) Debug.Log("WS diference :" + currentNode.GoalState.GetNumWorldStateDifferences(currentNode.CurrentState));

        // if (Owner.debugGOAP) Debug.Log("WS : goal " + currentNode.GoalState.ToString());
        //if (Owner.debugGOAP) Debug.Log("WS : current " + currentNode.CurrentState.ToString());

        if (currentNode.GoalState.GetNumWorldStateDifferences(currentNode.CurrentState) == 0)
        {
            WorldState tempState = new WorldState();
            //tempState.CopyWorldState(Ai.WorldState);
            tempState.CopyWorldState(currentNode.GoalState);

            // if (Owner.debugGOAP) Debug.Log(tempState.ToString());

            AStarGOAPNode currNode = currentNode;

            GOAPAction parentNode;

            // int i = 0;
            while (currNode.NodeID != -1)
            {
                parentNode = Map.GetAction(currNode.NodeID);

                /*if (Owner.debugGOAP) Debug.Log("Validating" + i + ". "+ parentNode.ToString());
                 * i++;
                 *
                 * //Get out if the current world state is validated by the current node
                 * if (!parentNode.ValidateWSEffects(tempState, null))
                 * {
                 * if (Owner.debugGOAP)
                 * {
                 * Debug.Log("FAILED: ValidateWSEffects return false");
                 * Debug.Log(parentNode.ToString() + " " + parentNode.WorldEffects.ToString());
                 * Debug.Log(tempState.ToString());
                 *
                 * }
                 * return false;
                 * }*/

                /**
                 * Now that the action's preconditions have been reversed,
                 * the preconditions of the action must be satisfied
                 */
                if (!parentNode.ValidateWSPreconditions(tempState, null))
                {
                    //         if (Owner.debugGOAP) Debug.Log("FAILED: ValidateWSPreconditions return false");
                    return(false);
                }

                /**
                 * The context preconditions must also be satisfied
                 */
                if (!parentNode.ValidateContextPreconditions(tempState, true))
                {
                    //            if (Owner.debugGOAP) Debug.Log("FAILED: ValidateContextPreconditions return false");
                    return(false);
                }

                /**
                 * Apply the preconditions to the temporate world state
                 */
                parentNode.ApplyWSEffects(tempState, null);

                //Get the next node in the list of nodes
                currNode = (AStarGOAPNode)currNode.Parent;
            }

            //Have applied all the actions in reverse,is the temp state now equal to the agents current state???
            if (Goal.IsWSSatisfiedForPlanning(tempState))
            {
//                if (Owner.debugGOAP) Debug.Log("TRUE :");
                return(true);
            }
        }

//        Debug.Log("FAILED");
        return(false);
    }
コード例 #2
0
    public bool IsPlanValid(AStarGOAPNode currentNode)
    {
        //if (Owner.debugGOAP) Debug.Log("IsPlanValid :" + currentNode.NodeID);
        //if (Owner.debugGOAP) Debug.Log("IsPlanValid :" + currentNode.GoalState.GetNumWorldStateDifferences(currentNode.CurrentState));

        //if (Owner.debugGOAP) Debug.Log("IsPlanValid : goal" + currentNode.GoalState.ToString());
        //if (Owner.debugGOAP) Debug.Log("IsPlanValid : current" + currentNode.CurrentState.ToString());

        if (currentNode.GoalState.GetNumWorldStateDifferences(currentNode.CurrentState) == 0)
        {
            WorldState tempState = new WorldState();
            //tempState.CopyWorldState(Ai.WorldState);
            tempState.CopyWorldState(currentNode.GoalState);

            // if (Owner.debugGOAP) Debug.Log(tempState.ToString());

            AStarGOAPNode currNode = currentNode;

            GOAPAction parentNode;

            while (currNode.NodeID != -1)
            {
                parentNode = Map.GetAction(currNode.NodeID);

                //if (Owner.debugGOAP) Debug.Log("IsPlanValid : " + parentNode.ToString());

                //Get out if the current world state is validated by the current node
                if (!parentNode.ValidateWSEffects(tempState, null))
                {
                    //if (Owner.debugGOAP) Debug.Log("IsPlanValid : ValidateWSEffects return false, so failed");
                    return(false);
                }

                /**
                 * Now that the action's preconditions have been reversed,
                 * the preconditions of the action must be satisfied
                 */
                if (!parentNode.ValidateWSPreconditions(tempState, null))
                {
                    //if (Owner.debugGOAP) Debug.Log("IsPlanValid : ValidateWSPreconditions return false, so failed");
                    return(false);
                }

                /**
                 * The context preconditions must also be satisfied
                 */
                if (!parentNode.ValidateContextPreconditions(Owner))
                {
                    //if (Owner.debugGOAP) Debug.Log("IsPlanValid : ValidateContextPreconditions return false, so failed");
                    return(false);
                }


                /**
                 * Apply the preconditions to the temporate world state
                 */
                parentNode.ApplyWSEffects(tempState, null);


                //Get the next node in the list of nodes
                currNode = (AStarGOAPNode)currNode.Parent;
            }

            //Have applied all the actions in reverse,is the temp state now equal to the agents current state???
            if (Goal.IsWSSatisfiedForPlanning(tempState))
            {
                //if (Owner.debugGOAP) Debug.Log("IsPlanValid : IsWSSatisfied return true, so its true");
                return(true);
            }
        }


        //Debug.Log("IsPlanValid : failed");
        return(false);
    }