-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
RepeatForever, RepeatUntilSuccess, and RepeatUntilFailure are new decorators used to continue a task indefinitely. RepeatForever executes its child and returns TaskStatus.Continue, regardless of its child's return status. RepeatUntilSuccess returns TaskStatus.Success if its child returns success, else it returns TaskStatus.Continue. RepeatUntilFailure returns TaskStatus.Failure if its child returns failure, else it returns TaskStatus.Continue.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using CleverCrow.Fluid.BTs.Trees; | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
|
||
namespace CleverCrow.Fluid.BTs.Decorators { | ||
public class RepeatForever : DecoratorBase { | ||
protected override TaskStatus OnUpdate () { | ||
Child?.Update(); | ||
return TaskStatus.Continue; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CleverCrow.Fluid.BTs.Trees; | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
|
||
namespace CleverCrow.Fluid.BTs.Decorators { | ||
public class RepeatUntilFailure : DecoratorBase { | ||
protected override TaskStatus OnUpdate () { | ||
if (Child == null) { | ||
return TaskStatus.Failure; | ||
} | ||
|
||
var childStatus = Child.Update(); | ||
var status = childStatus; | ||
|
||
if (status == TaskStatus.Failure) { | ||
return TaskStatus.Failure; | ||
} | ||
else { | ||
return TaskStatus.Continue; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CleverCrow.Fluid.BTs.Trees; | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
|
||
namespace CleverCrow.Fluid.BTs.Decorators { | ||
public class RepeatUntilSuccess : DecoratorBase { | ||
protected override TaskStatus OnUpdate () { | ||
if (Child == null) { | ||
return TaskStatus.Success; | ||
} | ||
|
||
var childStatus = Child.Update(); | ||
var status = childStatus; | ||
|
||
if (status == TaskStatus.Success) { | ||
return TaskStatus.Success; | ||
} | ||
else { | ||
return TaskStatus.Continue; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace CleverCrow.Fluid.BTs.Testing { | ||
public class RepeatForeverTest { | ||
public class UpdateMethod { | ||
[Test] | ||
public void Returns_continue_on_child_failure () { | ||
var repeater = new RepeatForever(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_continue_on_child_success () { | ||
var repeater = new RepeatForever(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Success).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_continue_on_child_continue () { | ||
var repeater = new RepeatForever(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Does_not_crash_if_no_child () { | ||
var repeater = new RepeatForever(); | ||
|
||
Assert.DoesNotThrow(() => repeater.Update()); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace CleverCrow.Fluid.BTs.Testing { | ||
public class RepeatUntilFailureTest { | ||
public class UpdateMethod { | ||
[Test] | ||
public void Returns_failure_on_child_failure () { | ||
var repeater = new RepeatUntilFailure(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Failure, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_continue_on_child_success () { | ||
var repeater = new RepeatUntilFailure(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Success).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_continue_on_child_continue () { | ||
var repeater = new RepeatUntilFailure(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Does_not_crash_if_no_child () { | ||
var repeater = new RepeatUntilFailure(); | ||
|
||
Assert.DoesNotThrow(() => repeater.Update()); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CleverCrow.Fluid.BTs.Decorators; | ||
using CleverCrow.Fluid.BTs.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace CleverCrow.Fluid.BTs.Testing { | ||
public class RepeatUntilSuccessTest { | ||
public class UpdateMethod { | ||
[Test] | ||
public void Returns_continue_on_child_failure () { | ||
var repeater = new RepeatUntilSuccess(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Failure).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_success_on_child_success () { | ||
var repeater = new RepeatUntilSuccess(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Success).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Success, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Returns_continue_on_child_continue () { | ||
var repeater = new RepeatUntilSuccess(); | ||
repeater.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build()); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, repeater.Update()); | ||
} | ||
|
||
[Test] | ||
public void Does_not_crash_if_no_child () { | ||
var repeater = new RepeatUntilSuccess(); | ||
|
||
Assert.DoesNotThrow(() => repeater.Update()); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.