-
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 action continuation for actions that are in Executing status
- Loading branch information
Showing
3 changed files
with
63 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace MountainGoapTest { | ||
using System.Collections.Generic; | ||
|
||
public class ActionContinuationTests { | ||
[Fact] | ||
public void ItCanContinueActions() { | ||
var timesExecuted = 0; | ||
var agent = new Agent( | ||
state: new() { | ||
{ "key", false }, | ||
{ "progress", 0 } | ||
}, | ||
goals: new List<BaseGoal> { | ||
new Goal( | ||
desiredState: new() { | ||
{ "key", true } | ||
} | ||
) | ||
}, | ||
actions: new List<Action> { | ||
new Action( | ||
preconditions: new() { | ||
{ "key", false } | ||
}, | ||
postconditions: new() { | ||
{ "key", true } | ||
}, | ||
executor: (Agent agent, Action action) => { | ||
timesExecuted++; | ||
if (agent.State["progress"] is int progress && progress < 3) { | ||
agent.State["progress"] = progress + 1; | ||
return ExecutionStatus.Executing; | ||
} | ||
else return ExecutionStatus.Succeeded; | ||
} | ||
) | ||
} | ||
); | ||
agent.Step(StepMode.OneAction); | ||
if (agent.State["key"] is bool value) Assert.False(value); | ||
else Assert.False(true); | ||
agent.Step(StepMode.OneAction); | ||
if (agent.State["key"] is bool value2) Assert.False(value2); | ||
else Assert.False(true); | ||
agent.Step(StepMode.OneAction); | ||
if (agent.State["key"] is bool value3) Assert.False(value3); | ||
else Assert.False(true); | ||
agent.Step(StepMode.OneAction); | ||
if (agent.State["key"] is bool value4) Assert.True(value4); | ||
else Assert.False(true); | ||
Assert.Equal(4, timesExecuted); | ||
} | ||
} | ||
} |