caesuric / mountain-goap

A GOAP (Goal Oriented Action Planning) AI library, written in C#.
Other
89 stars 10 forks source link

Reproducing a minimal example with arithmeticPostconditions #17

Closed JanWerder closed 10 months ago

JanWerder commented 10 months ago

Hi, I'm trying a minimal example with the arithmeticPostconditions, but I'm getting an infinite loop.

_ = new AgentLogger(false, "npc.log");

this.goals = new List<BaseGoal>(){
new Goal(
    name: "Goal1",
    desiredState: new() {
        { "i", new ComparisonValuePair {
            Value = 100,
            Operator = ComparisonOperator.GreaterThan
        } }
    },
    weight: 1f
),
};

this.actions = new List<MountainGoap.Action>(){
new MountainGoap.Action(
    name: "Action1",
    executor: (Agent agent, MountainGoap.Action action) => {
        return ExecutionStatus.Succeeded;
    },
    arithmeticPostconditions: new Dictionary<string, object> {
        { "i", 10 }
    },
    cost: 0.5f
),
};

this.agent = new Agent(
    goals: this.goals,
    actions: this.actions,
    state: new() {
        { "i", 0 }
    }
);

Afterwards I'm executing the Step function once, but viewing the log I can see an infinite loop.

2023-12-13 21:19:23.174 +01:00 [INF] Agent Agent a37d195d-ddf0-43ee-b5f5-2ce034fabe8a is working.
2023-12-13 21:19:23.201 +01:00 [INF] Agent Agent a37d195d-ddf0-43ee-b5f5-2ce034fabe8a started planning.
2023-12-13 21:19:23.211 +01:00 [INF] Evaluating node Action1 with 0 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 1 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 2 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 3 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 4 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 5 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 6 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 7 nodes leading to it.
2023-12-13 21:19:23.212 +01:00 [INF] Evaluating node Action1 with 8 nodes leading to it.
2023-12-13 21:19:23.213 +01:00 [INF] Evaluating node Action1 with 9 nodes leading to it.
2023-12-13 21:19:23.213 +01:00 [INF] Evaluating node Action1 with 10 nodes leading to it.
2023-12-13 21:19:23.213 +01:00 [INF] Evaluating node Action1 with 11 nodes leading to it.
2023-12-13 21:19:23.213 +01:00 [INF] Evaluating node Action1 with 12 nodes leading to it.
2023-12-13 21:19:23.213 +01:00 [INF] Evaluating node Action1 with 13 nodes leading to it.
[...]

I'm most likely missing something, can you give me a hint?

caesuric commented 10 months ago

Let me try to reproduce, and I'll get back to you soon. :smile:

JanWerder commented 10 months ago

I recreated my example as a test for convenience. You can see it in the https://github.com/caesuric/mountain-goap/pull/18 where it shows the same behaviour.

JanWerder commented 10 months ago

I was using the Goal instead of the ComparativeGoal, which was the cause for the error. When you use the ComparativeGoal it works as it should. I've added that to the test in the pull request as well.

caesuric commented 10 months ago

I'm so glad to hear this works properly! I was confused as I'm pretty sure I have a test for that. I'll look at your PR and get that test added in. 😄

caesuric commented 10 months ago

And yes, the regular goals are just relatively simple equality checks. Should I make that more clear in my documentation, or was it just a typo in this case?

JanWerder commented 10 months ago

I think an additional sentence in the documentation would be good. I'll send a pull request