-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability to access node state during cost calculation, comparati…
…ve preconditions, and the ability to set postconditions based on action parameters
- Loading branch information
Showing
9 changed files
with
309 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// <copyright file="ConsumerDemo.cs" company="Chris Muller"> | ||
// Copyright (c) Chris Muller. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Examples { | ||
using MountainGoap; | ||
using MountainGoapLogging; | ||
|
||
/// <summary> | ||
/// Goal to create enough food to eat by working and grocery shopping. | ||
/// </summary> | ||
internal static class ConsumerDemo { | ||
/// <summary> | ||
/// Runs the demo. | ||
/// </summary> | ||
internal static void Run() { | ||
_ = new DefaultLogger(); | ||
var locations = new List<string> { "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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.