diff --git a/Examples/ConsumerDemo.cs b/Examples/ConsumerDemo.cs
new file mode 100644
index 0000000..1493945
--- /dev/null
+++ b/Examples/ConsumerDemo.cs
@@ -0,0 +1,145 @@
+//
+// Copyright (c) Chris Muller. All rights reserved.
+//
+
+namespace Examples {
+ using MountainGoap;
+ using MountainGoapLogging;
+
+ ///
+ /// Goal to create enough food to eat by working and grocery shopping.
+ ///
+ internal static class ConsumerDemo {
+ ///
+ /// Runs the demo.
+ ///
+ internal static void Run() {
+ _ = new DefaultLogger();
+ var locations = new List { "home", "work", "store" };
+ var agent = new Agent(
+ name: "Consumer Agent",
+ state: new() {
+ { "food", 4 },
+ { "energy", 100 },
+ { "money", 0 },
+ { "inCar", false },
+ { "location", "home" }
+ },
+ goals: new() {
+ //new ComparativeGoal(
+ // name: "Get at least 5 food",
+ // desiredState: new() {
+ // {
+ // "food", new() {
+ // Operator = ComparisonOperator.GreaterThanOrEquals,
+ // Value = 5
+ // }
+ // }
+ // })
+ //new Goal(
+ // name: "Get 5 food",
+ // desiredState: new() {
+ // { "food", 5 }
+ // })
+ new ExtremeGoal(
+ name: "Get food",
+ desiredState: new() {
+ { "food", true }
+ })
+ },
+ actions: new() {
+ new(
+ name: "Walk",
+ cost: 10,
+ executor: GenericExecutor,
+ permutationSelectors: new() {
+ { "location", PermutationSelectorGenerators.SelectFromCollection(locations) }
+ },
+ comparativePreconditions: new() {
+ { "energy", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } }
+ },
+ arithmeticPostconditions: new() {
+ { "energy", -1 }
+ },
+ parameterPostconditions: new() {
+ { "location", "location" }
+ }
+ ),
+ new(
+ name: "Drive",
+ cost: 1,
+ preconditions: new() {
+ { "inCar", true }
+ },
+ comparativePreconditions: new() {
+ { "energy", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } }
+ },
+ executor: GenericExecutor,
+ permutationSelectors: new() {
+ { "location", PermutationSelectorGenerators.SelectFromCollection(locations) }
+ },
+ arithmeticPostconditions: new() {
+ { "energy", -1 }
+ },
+ parameterPostconditions: new() {
+ { "location", "location" }
+ }
+ ),
+ new(
+ name: "Get in Car",
+ cost: 1f,
+ preconditions: new() {
+ { "inCar", false }
+ },
+ comparativePreconditions: new() {
+ { "energy", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } }
+ },
+ postconditions: new() {
+ { "inCar", true }
+ },
+ arithmeticPostconditions: new() {
+ { "energy", -1 }
+ },
+ executor: GenericExecutor
+ ),
+ new(
+ name: "Work",
+ cost: 1f,
+ preconditions: new() {
+ { "location", "work" },
+ },
+ comparativePreconditions: new() {
+ { "energy", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } }
+ },
+ arithmeticPostconditions: new() {
+ { "energy", -1 },
+ { "money", 1 }
+ },
+ executor: GenericExecutor
+ ),
+ new(
+ name: "Shop",
+ cost: 1f,
+ preconditions: new() {
+ { "location", "store" }
+ },
+ comparativePreconditions: new() {
+ { "energy", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } },
+ { "money", new() { Operator = ComparisonOperator.GreaterThan, Value = 0 } }
+ },
+ arithmeticPostconditions: new() {
+ { "energy", -1 },
+ { "money", -1 },
+ { "food", 1 }
+ },
+ executor: GenericExecutor
+ )
+ });
+ while (agent.State["food"] is int food && food < 5) agent.Step();
+ }
+
+ private static ExecutionStatus GenericExecutor(Agent agent, Action action) {
+ return ExecutionStatus.Succeeded;
+ }
+ }
+}
diff --git a/Examples/Program.cs b/Examples/Program.cs
index 587b263..f929323 100644
--- a/Examples/Program.cs
+++ b/Examples/Program.cs
@@ -39,13 +39,18 @@ public static async Task Main(string[] args) {
carCommand.SetHandler(() => {
RunCarDemo();
});
+ var consumerCommand = new Command("consumer", "Run the consumer demo.");
+ consumerCommand.SetHandler(() => {
+ RunConsumerDemo();
+ });
var cmd = new RootCommand {
happinessIncrementerCommand,
rpgCommand,
arithmeticHappinessIncrementerCommand,
extremeHappinessIncrementerCommand,
comparativeHappinessIncrementerCommand,
- carCommand
+ carCommand,
+ consumerCommand
};
return await cmd.InvokeAsync(args);
}
@@ -73,5 +78,9 @@ private static void RunComparativeHappinessIncrementer() {
private static void RunCarDemo() {
CarDemo.Run();
}
+
+ private static void RunConsumerDemo() {
+ ConsumerDemo.Run();
+ }
}
}
diff --git a/Examples/RpgExample/RpgUtils.cs b/Examples/RpgExample/RpgUtils.cs
index e013ef4..785e4eb 100644
--- a/Examples/RpgExample/RpgUtils.cs
+++ b/Examples/RpgExample/RpgUtils.cs
@@ -91,22 +91,28 @@ internal static List