-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHappinessIncrementer.cs
65 lines (61 loc) · 2.26 KB
/
HappinessIncrementer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// <copyright file="HappinessIncrementer.cs" company="Chris Muller">
// Copyright (c) Chris Muller. All rights reserved.
// </copyright>
namespace Examples {
using MountainGoap;
using MountainGoapLogging;
/// <summary>
/// Simple goal to maximize happiness.
/// </summary>
internal static class HappinessIncrementer {
/// <summary>
/// Runs the demo.
/// </summary>
internal static void Run() {
_ = new DefaultLogger();
Agent agent = new(
name: "Happiness Agent",
state: new() {
{ "happiness", 0 },
{ "happinessRecentlyIncreased", false }
},
goals: new() {
new Goal(
name: "Maximize Happiness",
desiredState: new() {
{ "happinessRecentlyIncreased", true }
})
},
sensors: new() {
new(EnnuiSensorHandler, "Ennui Sensor")
},
actions: new() {
new(
name: "Seek Happiness",
executor: SeekHappinessAction,
preconditions: new() {
{ "happinessRecentlyIncreased", false }
},
postconditions: new() {
{ "happinessRecentlyIncreased", true }
}
)
}
);
while (agent.State["happiness"] is int happiness && happiness != 10) agent.Step();
}
private static ExecutionStatus SeekHappinessAction(Agent agent, Action action) {
int? happiness = agent.State["happiness"] as int?;
if (happiness != null) {
happiness++;
agent.State["happiness"] = happiness;
Console.WriteLine("Seeking happiness.");
Console.WriteLine($"NEW HAPPINESS IS {happiness}");
}
return ExecutionStatus.Succeeded;
}
private static void EnnuiSensorHandler(Agent agent) {
agent.State["happinessRecentlyIncreased"] = false;
}
}
}