Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-goal #32

Open
ray2k opened this issue Jul 5, 2024 · 1 comment
Open

Multi-goal #32

ray2k opened this issue Jul 5, 2024 · 1 comment

Comments

@ray2k
Copy link

ray2k commented Jul 5, 2024

Multiple goals should be supported, right?

When I have this happiness-increaser based example it runs until it hits 25 as expected:

public static void RunBasicExample()
{
    var ag = new GoapAgent(
        name: "Happiness Agent",
        state: new()
        {
            { "happiness", 0 },
            { "complete", false }
        },
        goals: new()
        {
            new Goal(
                name: "Acquire Max Happiness",
                desiredState: new()
                {
                    { "happiness", 25 }
                })
        },
        sensors: new()
        {
            new Sensor(CheckComplete)
        },
        actions: new()
        {
            new MountainGoap.Action(
                name: "Increase Happiness",
                executor: IncreaseHappiness,
                arithmeticPostconditions: new()
                {
                    { "happiness", 1 }
                })                    
        });

    while ((bool)ag.State["complete"] == false)
        ag.Step(StepMode.AllActions);
}

        private static void CheckComplete(GoapAgent agent)
        {
            if ((int)agent.State["happiness"] >= 25)
                agent.State["complete"] = true;
        }

        private static ExecutionStatus IncreaseHappiness(GoapAgent agent, MountainGoap.Action action)
        {
            Console.WriteLine("Happiness is at {0} - Increasing!", agent.State["happiness"]);
            return ExecutionStatus.Succeeded;
        }

But that's pretty contrived as it's basically a goap version of a while-loop. Whenever I add an additional goal + action, it gets an IndexOutOfBounds exception related to A*- this setup should be solvable though, right?

 public static void RunAdvancedExample()
 {
     var ag = new GoapAgent(
         name: "Phase 1",
         state: new()
         {
             { "happiness", 0 },
             { "complete", false },
             { "anotherThingDone", false }
         },
         goals: new()
         {
             new Goal(
                 name: "Acquire Max Happiness",
                 desiredState: new()
                 {
                     { "happiness", 25 }                            
                 }),
             new Goal(
                 name: "Do the other thing",
                 desiredState: new()
                 {
                     { "anotherThingDone", true }
                 })
         },
         sensors: new()
         {
             new Sensor(CheckComplete)
         },
         actions: new()
         {
             new MountainGoap.Action(
                 name: "Increase Happiness",
                 executor: IncreaseHappiness,
                 arithmeticPostconditions: new()
                 {
                     { "happiness", 1 }
                 }),
             new MountainGoap.Action(
                 name: "Do the other thing",
                 executor: DoAnotherThing,
                 postconditions: new()
                 {
                     { "anotherThingDone", true }
                 })
         });

     while ((bool)ag.State["complete"] == false)
         ag.Step(StepMode.AllActions);

    // not shown: update to CheckComplete to also consider anotherThingDone == true
 }

        private static ExecutionStatus DoAnotherThing(GoapAgent agent, MountainGoap.Action action)
        {
            Console.WriteLine("Doing the other thing");
            return ExecutionStatus.Succeeded;
        }

Tried:

  • Adding weights to goals
  • remove StepMode.AllActions on ag.Step()
  • Instead of additional Goal, adding { "anotherThingDone", true } to the single goal along with happiness == 25

Is it because they are booleans? Is this even supported? What am I missing?

@caesuric
Copy link
Owner

caesuric commented Jul 5, 2024

Multiple goals do work. Usually when I've seen it spin and then die, it's because it finds one or more goals impossible and no limits have been set on how far to search for completing the goal. The code above, at first glance, looks like it should work though. I'll try to replicate on my end and get back to you when I figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants