Skip to content
New issue

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

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

Already on GitHub? # to your account

How to update Goal weight and desired state #34

Open
inezradulov opened this issue Sep 19, 2024 · 0 comments
Open

How to update Goal weight and desired state #34

inezradulov opened this issue Sep 19, 2024 · 0 comments

Comments

@inezradulov
Copy link

I am running the examples with a scenario of updating the goals at runtime, and it seems once the agent is created with goals they can't be updated.

here is an example

 _ = new DefaultLogger(true);
        var goal = new ComparativeGoal(
                  name: "Travel 50 miles",
                  desiredState: new() {
                            {
                                "distanceTraveled", new() {
                                    Operator = ComparisonOperator.GreaterThanOrEquals,
                                    Value = 50
                                }
                            }
                  });

        var walkAction = new Action(
              name: "Walk",
              cost: 50,
              postconditions: new() {
                            { "distanceTraveled", 50 }
              },
              executor: TravelExecutor
          );
        var driveAction = new Action(
                      name: "Drive",
                      cost: 5,
                      preconditions: new() {
                            { "inCar", true }
                      },
                      postconditions: new() {
                            { "distanceTraveled", 50 }
                      },
                      executor: TravelExecutor
                  );

        var getInCarAction = new Action(
              name: "Get in Car",
              cost: 1,
              preconditions: new() {
                            { "inCar", false }
              },
              postconditions: new() {
                            { "inCar", true }
              },
              executor: GetInCarExecutor
          );


        var agent = new Agent(
          name: "Driving Agent",
          state: new() {
                    { "distanceTraveled", 0 },
                    { "inCar", false }
          }
          );
        agent.Goals.Add(goal);
        agent.Actions.Add(walkAction);
        agent.Actions.Add(driveAction);
        agent.Actions.Add(getInCarAction);

        agent.Step(StepMode.OneAction);
        agent.Step(StepMode.OneAction);
        agent.Step(StepMode.OneAction);


        var newGoal = new ComparativeGoal(
                  name: "Travel 60 miless",
                  desiredState: new() {
                            {
                                "distanceTraveled", new() {
                                    Operator = ComparisonOperator.GreaterThanOrEquals,
                                    Value = 60
                                }
                            }
                  });

        agent.Goals.Clear();
        agent.Goals.Add(newGoal);
        agent.Step(StepMode.OneAction);
        agent.Step(StepMode.OneAction);
        agent.Step(StepMode.OneAction);

It throws

 :0 @ void System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array , IntPtr , System.Object ): System.IndexOutOfRangeException: Index was outside the bounds of the array.
  <C++ Error>    System.IndexOutOfRangeException
  <C++ Source>   :0 @ void System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array , IntPtr , System.Object )
  <Stack Trace>  :0 @ void System.Runtime.CompilerServices.CastHelpers.StelemRef(System.Array , IntPtr , System.Object )
                 :0 @ MountainGoap.ActionAStar..ctor(MountainGoap.ActionGraph , MountainGoap.ActionNode , MountainGoap.BaseGoal , Single , Int32 )
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant