public void fails_when_required_number_of_children_fail() { Init(2, 2); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Failure); var mockChild2 = new Mock<IBehaviourTreeNode>(); mockChild2 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Failure); var mockChild3 = new Mock<IBehaviourTreeNode>(); mockChild3 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Running); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); testObject.AddChild(mockChild3.Object); Assert.Equal(BehaviourTreeStatus.Failure, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Once()); mockChild3.Verify(m => m.Tick(time), Times.Once()); }
public BehaviourTreeStatus Tick(TimeData time) { var numChildrenSuceeded = 0; var numChildrenFailed = 0; foreach (var child in children) { var childStatus = child.Tick(time); switch (childStatus) { case BehaviourTreeStatus.Success: ++numChildrenSuceeded; break; case BehaviourTreeStatus.Failure: ++numChildrenFailed; break; } } if (numRequiredToSucceed > 0 && numChildrenSuceeded >= numRequiredToSucceed) { return BehaviourTreeStatus.Success; } if (numRequiredToFail > 0 && numChildrenFailed >= numRequiredToFail) { return BehaviourTreeStatus.Failure; } return BehaviourTreeStatus.Running; }
public BehaviourTreeStatus Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("Succeeder must have a child node!"); } childNode.Tick(time); return(BehaviourTreeStatus.Success); }
public BehaviourTreeStatus Tick(TimeData time) { var childStatus = childNode.Tick(time); if (childStatus == BehaviourTreeStatus.Failure) { return(BehaviourTreeStatus.Success); } return(BehaviourTreeStatus.Running); }
public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { currentStatus = BehaviourTreeStatus.Running; while (isRunning()) { numChildrenSuceeded = 0; numChildrenFailed = 0; foreach (var child in children) { var childStatus = child.Tick(time); childStatus.MoveNext(); if (childStatus.Current == BehaviourTreeStatus.Running) { // keep looping until we exit running mode or we // run out of enum values. yield return(childStatus.Current); while (childStatus.MoveNext()) { if (childStatus.Current != BehaviourTreeStatus.Running) { break; } yield return(childStatus.Current); } } switch (childStatus.Current) { case BehaviourTreeStatus.Success: ++numChildrenSuceeded; break; case BehaviourTreeStatus.Failure: ++numChildrenFailed; break; } } if (numRequiredToSucceed > 0 && numChildrenSuceeded >= numRequiredToSucceed) { currentStatus = BehaviourTreeStatus.Success; } else if (numRequiredToFail > 0 && numChildrenFailed >= numRequiredToFail) { currentStatus = BehaviourTreeStatus.Failure; } else { // Return Running if conditions were not met currentStatus = BehaviourTreeStatus.Running; } yield return(currentStatus); } }
public BehaviourTreeStatus Tick(TimeData time) { foreach (var child in children) { var childStatus = child.Tick(time); if (childStatus != BehaviourTreeStatus.Success) { return childStatus; } } return BehaviourTreeStatus.Success; }
public BehaviourTreeStatus Tick(TimeData time) { if ((maxIterations > -1 || maxIterations == 0) && iterations >= maxIterations) { iterations = 0; return(BehaviourTreeStatus.Success); } childNode.Tick(time); iterations++; return(BehaviourTreeStatus.Running); }
public BehaviourTreeStatus Tick(TimeData time) { foreach (var child in children) { var childStatus = child.Tick(time); if (childStatus != BehaviourTreeStatus.Failure) { return(childStatus); } } return(BehaviourTreeStatus.Failure); }
public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { for (var e = fn(time); e.MoveNext();) { currentStatus = e.Current; yield return(currentStatus); // this will continue looping until complete and as long as // the function returns another enumerated value that is not success or failure if (isComplete()) { yield break; } } }
public void pass_through_running_of_child_node() { Init(); var time = new TimeData(); var mockChildNode = new Mock<IBehaviourTreeNode>(); mockChildNode .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Running); testObject.AddChild(mockChildNode.Object); Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time)); mockChildNode.Verify(m => m.Tick(time), Times.Once()); }
public void inverts_success_of_child_node() { Init(); var time = new TimeData(); var mockChildNode = new Mock<IBehaviourTreeNode>(); mockChildNode .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Success); testObject.AddChild(mockChildNode.Object); Assert.Equal(BehaviourTreeStatus.Failure, testObject.Tick(time)); mockChildNode.Verify(m => m.Tick(time), Times.Once()); }
public BehaviourTreeStatus Tick(TimeData time) { for (int i = 0; i < children.Count; i++) { var childStatus = children[i].Tick(time); if (childStatus == BehaviourTreeStatus.Running) { i--; break; } if (childStatus != BehaviourTreeStatus.Failure) { return(childStatus); } } return(BehaviourTreeStatus.Failure); }
public void can_run_action() { var time = new TimeData(); var invokeCount = 0; var testObject = new ActionNode( "some-action", t => { Assert.Equal(time, t); ++invokeCount; return BehaviourTreeStatus.Running; } ); Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time)); Assert.Equal(1, invokeCount); }
public void runs_the_first_node_if_it_succeeds() { Init(); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Success); var mockChild2 = new Mock<IBehaviourTreeNode>(); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Success, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Never()); }
public BehaviourTreeStatus Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(time); if (result == BehaviourTreeStatus.Failure) { return BehaviourTreeStatus.Success; } else if (result == BehaviourTreeStatus.Success) { return BehaviourTreeStatus.Failure; } else { return result; } }
public BehaviourTreeStatus Tick(TimeData time) { for (int i = 0; i < children.Count; i++) { var childStatus = children[i].Tick(time); if (childStatus != BehaviourTreeStatus.Success) { if (childStatus == BehaviourTreeStatus.Running) { i--; break; } if (childStatus == BehaviourTreeStatus.Failure) { return(childStatus);//this should break us out of the loop } } } //otherwise we go all the way through the loop return(BehaviourTreeStatus.Success); }
public void when_first_child_fails_then_entire_sequence_fails() { Init(); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Failure); var mockChild2 = new Mock<IBehaviourTreeNode>(); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Failure, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Never()); }
public BehaviourTreeStatus Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(time); if (result == BehaviourTreeStatus.Failure) { return(BehaviourTreeStatus.Success); } else if (result == BehaviourTreeStatus.Success) { return(BehaviourTreeStatus.Failure); } else { return(result); } }
public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(time); result.MoveNext(); currentStatus = result.Current; if (isRunning()) { // keep looping until we exit running mode or we // run out of enum values. yield return(currentStatus); while (result.MoveNext()) { currentStatus = result.Current; if (!isRunning()) { break; } } } if (isFailed()) { currentStatus = BehaviourTreeStatus.Success; } else if (isSuccess()) { currentStatus = BehaviourTreeStatus.Failure; } yield return(currentStatus); }
public BehaviourTreeStatus Tick(TimeData time) { var numChildrenSuceeded = 0; var numChildrenFailed = 0; if (!iscompleted) { while (current != null) { var status = current.Value.Action.Tick(time); switch (status) { case BehaviourTreeStatus.Success: ++numChildrenSuceeded; break; case BehaviourTreeStatus.Failure: ++numChildrenFailed; break; } current = current.Next; } iscompleted = true; } if (numRequiredToSucceed > 0 && numChildrenSuceeded >= numRequiredToSucceed) { return(BehaviourTreeStatus.Success); } if (numRequiredToFail > 0 && numChildrenFailed >= numRequiredToFail) { return(BehaviourTreeStatus.Failure); } return(BehaviourTreeStatus.Failure); }
public void can_run_all_children_in_order() { Init(); var time = new TimeData(); var callOrder = 0; var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Success) .Callback(() => { Assert.Equal(1, ++callOrder); }); var mockChild2 = new Mock<IBehaviourTreeNode>(); mockChild2 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Success) .Callback(() => { Assert.Equal(2, ++callOrder); }); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Success, testObject.Tick(time)); Assert.Equal(2, callOrder); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Once()); }
public BehaviourTreeStatus Tick(TimeData time) { if (!iscompleted) { bool hasrunning = false; while (current != null) { var status = current.Value.Action.Tick(time); if (status == BehaviourTreeStatus.Success) { iscompleted = true; return(status); } else if (status == BehaviourTreeStatus.Running) { hasrunning = true; } current = current.Next; } //if has running node, continue wait if (hasrunning) { //reset current position to first current = children.First; return(BehaviourTreeStatus.Running); } iscompleted = true; } return(BehaviourTreeStatus.Failure); }
public void continues_to_run_if_required_number_children_neither_succeed_or_fail() { Init(2, 2); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Success); var mockChild2 = new Mock<IBehaviourTreeNode>(); mockChild2 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Failure); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Once()); }
public void when_first_child_is_running_second_child_is_supressed() { Init(); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Running); var mockChild2 = new Mock<IBehaviourTreeNode>(); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Never()); }
// A Selector may be contaminated with other nodes (Condition) or IParentBeahviourTreeNodes over which // it's behaviour as a selector is applied. The assumption here is that any item in it's child list // should have selector behaviour applied unless the first one is a condition Action. public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { int skipOne = 0; // check if this is a conditional action IBehaviourTreeNode firstNode = children[0]; if (firstNode is ConditionNode) { ConditionNode firstChild = (ConditionNode)firstNode; var status = firstChild.Tick(time); status.MoveNext(); if (status.Current != BehaviourTreeStatus.Success) { // Return Failure and Exit the Node currentStatus = BehaviourTreeStatus.Failure; yield return(currentStatus); yield break; } else { ++skipOne; } } List <IBehaviourTreeNode> remainingChildren = children.Skip(skipOne).ToList <IBehaviourTreeNode>(); if (isRandom) { remainingChildren = Randomize(remainingChildren); } foreach (var child in remainingChildren) { var childStatus = child.Tick(time); childStatus.MoveNext(); currentStatus = childStatus.Current; if (isRunning()) { // keep looping until we exit running mode or we // run out of enum values. yield return(currentStatus); while (childStatus.MoveNext()) { currentStatus = childStatus.Current; if (!isRunning()) { break; } } } // On exit above, status should be success or fail // if success, then exit selector if (isSuccess()) { yield return(currentStatus); yield break; } } yield return(currentStatus); }
public BehaviourTreeStatus Tick(TimeData time) { return(fn(time)); }
public BehaviourTreeStatus Tick(TimeData time) { return fn(time); }
public void stops_on_the_first_node_when_it_is_running() { Init(); var time = new TimeData(); var mockChild1 = new Mock<IBehaviourTreeNode>(); mockChild1 .Setup(m => m.Tick(time)) .Returns(BehaviourTreeStatus.Running); var mockChild2 = new Mock<IBehaviourTreeNode>(); testObject.AddChild(mockChild1.Object); testObject.AddChild(mockChild2.Object); Assert.Equal(BehaviourTreeStatus.Running, testObject.Tick(time)); mockChild1.Verify(m => m.Tick(time), Times.Once()); mockChild2.Verify(m => m.Tick(time), Times.Never()); }
public BehaviourTreeStatus Tick(TimeData time) { return(fn(time) ? BehaviourTreeStatus.Success : BehaviourTreeStatus.Failure); }
public BehaviourTreeStatus Tick(TimeData time) { Status = fn(time); return(Status); }
public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { currentStatus = fn(time) ? BehaviourTreeStatus.Success : BehaviourTreeStatus.Failure; yield return(currentStatus); }