public void SetupParallel() { var root = new Parallel(); var conditionalA = new TestYieldConditionNode { Conditional = s => s.A }; var conditionalB = new TestNestedConditionNode { Conditional = s => s.B }; var conditionalC = new TestConditionNode { Conditional = s => s.C }; var conditionalD = new TestRunningConditionNode { Conditional = s => s.D }; root.Children = new List <Node> { conditionalA, conditionalB, conditionalC, conditionalD }; _treeB = new BehaviourTree(root); _stateB = new State { A = true, B = false, C = true, D = false }; while (_treeB.TickCount == 0) { _treeB.Update(_stateB); } }
public void SetupNestedParallel() { var parallelA = new Parallel(); var parallelB = new Parallel(); var parallelC = new Parallel(); var root = new Sequence(); var entryCondition = new Condition(s => ((State)s).Entry); var conditionalA = new TestYieldConditionNode { Conditional = s => s.A }; var conditionalB = new TestYieldConditionNode { Conditional = s => s.B }; var conditionalC = new TestYieldConditionNode { Conditional = s => s.C }; var conditionalD = new TestYieldConditionNode { Conditional = s => s.D }; var conditionalE = new TestRunningConditionNode { Conditional = s => s.E }; root.Children = new List <Node> { entryCondition, parallelA }; parallelA.Children = new List <Node> { parallelB, parallelC, conditionalA }; parallelB.Children = new List <Node> { conditionalB, conditionalC }; parallelC.Children = new List <Node> { conditionalD, conditionalE }; _treeA = new BehaviourTree(root); _stateA = new State { Entry = true, A = true, B = true, C = true, D = true, E = true }; while (_treeA.TickCount == 0) { _treeA.Update(_stateA); } }
public void CorouinePoolLeakTest() { var stages = new Queue <string>(); var sequence = new List <string>(); var parallelA = new Parallel(); var parallelB = new Parallel(); var parallelC = new Parallel(); var root = new Sequence(); var entryCondition = new Condition(s => ((State)s).Entry); var conditionalA = new TestYieldConditionNode { PrintA = "AYield", PrintB = "A", Stages = stages, Conditional = s => s.A }; var conditionalB = new TestYieldConditionNode { PrintA = "BYield", PrintB = "B", Stages = stages, Conditional = s => s.B }; var conditionalC = new TestYieldConditionNode { PrintA = "CYield", PrintB = "C", Stages = stages, Conditional = s => s.C }; var conditionalD = new TestYieldConditionNode { PrintA = "DYield", PrintB = "D", Stages = stages, Conditional = s => s.D }; var conditionalE = new TestRunningConditionNode { PrintA = "E", Stages = stages, Conditional = s => s.E }; parallelA.Children = new List <Node> { parallelB, parallelC, conditionalA }; parallelB.Children = new List <Node> { conditionalB, conditionalC }; parallelC.Children = new List <Node> { conditionalD, conditionalE }; root.Children = new List <Node> { entryCondition, parallelA }; foreach (var n in root.DepthFirstIterate()) { n.Initialize(); } var manager = new BehaviourTree(root); Coroutine <Result> .Pool.Clear(); Coroutine.Pool.Clear(); TickOnce(manager, stages, sequence); var genericPoolCount = Coroutine <Result> .Pool.Count; var voidPoolCount = Coroutine.Pool.Count; for (var i = 0; i < 100; i++) { TickOnce(manager, stages, sequence); Assert.IsTrue(Coroutine <Result> .Pool.Count > 0); Assert.IsTrue(Coroutine.Pool.Count > 0); Assert.AreEqual(genericPoolCount, Coroutine <Result> .Pool.Count); Assert.AreEqual(voidPoolCount, Coroutine.Pool.Count); } }
public void AsynchronousTaskTest() { var stages = new Queue <string>(); var parallelA = new Parallel(); var parallelB = new Parallel(); var parallelC = new Parallel(); var root = new Sequence(); var entryCondition = new Condition(s => ((State)s).Entry); var conditionalA = new TestYieldConditionNode { PrintA = "AYield", PrintB = "A", Stages = stages, Conditional = s => s.A }; var conditionalB = new TestYieldConditionNode { PrintA = "BYield", PrintB = "B", Stages = stages, Conditional = s => s.B }; var conditionalC = new TestYieldConditionNode { PrintA = "CYield", PrintB = "C", Stages = stages, Conditional = s => s.C }; var conditionalD = new TestYieldConditionNode { PrintA = "DYield", PrintB = "D", Stages = stages, Conditional = s => s.D }; var conditionalE = new TestRunningConditionNode { PrintA = "E", Stages = stages, Conditional = s => s.E }; parallelA.Children = new List <Node> { parallelB, parallelC, conditionalA }; parallelB.Children = new List <Node> { conditionalB, conditionalC }; parallelC.Children = new List <Node> { conditionalD, conditionalE }; root.Children = new List <Node> { entryCondition, parallelA }; foreach (var n in root.DepthFirstIterate()) { n.Initialize(); } var manager = new BehaviourTree(root); var state = new State { Entry = true, A = true, B = true, C = true, D = true, E = true }; for (var i = 0; i < 2; i++) { var sequence = new[] { "AYield", "BYield", "CYield", "DYield" }; var initialTick = manager.TickCount; while (initialTick == manager.TickCount) { manager.Update(state); } Assert.AreEqual(Result.Success, manager.Result); Assert.AreEqual(initialTick + 1UL, manager.TickCount); Assert.IsTrue(stages.Take(4).SequenceEqual(sequence)); Assert.IsTrue(stages.Any(s => s == "A")); Assert.IsTrue(stages.Any(s => s == "B")); Assert.IsTrue(stages.Any(s => s == "C")); Assert.IsTrue(stages.Any(s => s == "D")); stages.Clear(); } }
public void NestedParallelNodeTest() { var stages = new Queue <string>(); var parallelA = new Parallel(); var parallelB = new Parallel(); var parallelC = new Parallel(); var root = new Sequence(); var entryCondition = new Condition(s => ((State)s).Entry); var conditionalA = new TestYieldConditionNode { PrintA = "AYield", PrintB = "A", Stages = stages, Conditional = s => s.A }; var conditionalB = new TestYieldConditionNode { PrintA = "BYield", PrintB = "B", Stages = stages, Conditional = s => s.B }; var conditionalC = new TestYieldConditionNode { PrintA = "CYield", PrintB = "C", Stages = stages, Conditional = s => s.C }; var conditionalD = new TestYieldConditionNode { PrintA = "DYield", PrintB = "D", Stages = stages, Conditional = s => s.D }; var conditionalE = new TestRunningConditionNode { PrintA = "E", Stages = stages, Conditional = s => s.E }; parallelA.Children = new List <Node> { parallelB, parallelC, conditionalA }; parallelB.Children = new List <Node> { conditionalB, conditionalC }; parallelC.Children = new List <Node> { conditionalD, conditionalE }; root.Children = new List <Node> { entryCondition, parallelA }; foreach (var n in root.DepthFirstIterate()) { n.Initialize(); } var manager = new BehaviourTree(root); var sequence = new List <string>(); for (var i = 0; i < 2; i++) { Assert.AreEqual(0UL, manager.TickCount); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK", "AYield", "BYield", "CYield", "DYield" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Unknown, manager.Result); Assert.AreEqual(0UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK", "A", "B", "C", "D" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Unknown, manager.Result); Assert.AreEqual(0UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Unknown, manager.Result); Assert.AreEqual(0UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Unknown, manager.Result); Assert.AreEqual(0UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Unknown, manager.Result); Assert.AreEqual(0UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); stages.Enqueue("TICK"); sequence.AddRange(new[] { "TICK", "E" }); manager.Update(new State { Entry = true, A = true, B = true, C = true, D = true, E = true }); Assert.AreEqual(Result.Success, manager.Result); Assert.AreEqual(1UL, manager.TickCount); Assert.IsTrue(stages.SequenceEqual(sequence)); manager.Reset(); stages.Clear(); sequence.Clear(); } }