public static Leaf RepeatUntilFail(Leaf leaf) { return(() => { State leafState = leaf(); switch (leafState) { case State.SUCCESS: return RepeatUntilFail(leaf)(); case State.FAILURE: return State.SUCCESS; default: return leafState; } }); }
public void Node_Succeeds() { RepeatUntilFail cud = Create_Repeater(false); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Success); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Success); }
private RepeatUntilFail Create_Repeater(bool yieldable) { FakeProcesses set = new FakeProcesses(NodeStatus.Success, NodeStatus.Running, NodeStatus.Failure); RepeatUntilFail cud = new RepeatUntilFail(set, yieldable); return(cud); }
public void Reset_The_Yieldable() { RepeatUntilFail cud = Create_Repeater(true); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Running); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Running); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Success); TestHelper.AssertResult <RepeatUntilFail>(cud, NodeStatus.Success); cud.Reset(); }
private Sequence AggressiveAI() { BehaviorAction stop = new BehaviorAction(aiToTarget.Stop); Sequence sequenceShootWhileMove = new Sequence(Shoot(), DoTransitionBehavior()); RepeatUntilFail followPathLoop = new RepeatUntilFail(sequenceShootWhileMove); RepeatUntilFail stopLoop = new RepeatUntilFail(stop); IndexSelector minDistance = new IndexSelector(MinDistanceReached, stopLoop, followPathLoop); return(new Sequence(Shoot(), new StatefulSequence(CalculatePath(aiToTarget.CalculatePath), minDistance))); }
private Sequence DefensiveAI() { Conditional targetAlive = new Conditional(aiWeapon.TargetAlive); Conditional aiIsOnTransitionOrDodge = new Conditional(aiToTarget.OnTransitionOrDodge); Conditional isBreakValid = new Conditional(aiToTarget.IsBreakValid); Conditional canIShoot = new Conditional(aiWeapon.IsTargetHittable); Selector shootSelect = new Selector(new Inverter(targetAlive), canIShoot, aiIsOnTransitionOrDodge); StatefulSelector stayOrMove = new StatefulSelector(isBreakValid, DoTransitionBehavior()); Sequence shootAndOrMove = new Sequence(stayOrMove, shootSelect); RepeatUntilFail followPathLoop = new RepeatUntilFail(shootAndOrMove); return(new Sequence(new Sequence(Dodge(), Shoot()), new StatefulSequence(CalculatePath(aiToTarget.CalculatePathToUpperNode), followPathLoop))); }
// Use this for initialization void Start () { mRoot = new RepeatUntilFail(null); //Level 0 (Not normally a thing but I didnt think it through ... //normally starts at root then level 1 comes next Sequence l0_sequence = new Sequence(mRoot); //level 1 GetStackOfPOIs l1_getStack = new GetStackOfPOIs(l0_sequence, "poiStack"); RepeatUntilFail l1_RepeatUntilFail = new RepeatUntilFail(l0_sequence); SpawnPOIs l1_spawnPOIs = new SpawnPOIs(l0_sequence, mPOIPrefab); //level 2 Sequence l2_sequence = new Sequence(l1_RepeatUntilFail); //level 3 Inverter l3_inverter = new Inverter(l2_sequence); RepeatUntilFail l3_ruf = new RepeatUntilFail(l2_sequence); WalkToObject l3_walkToObject = new WalkToObject(l2_sequence, "Basket"); DropPOI l3_dropPOI = new DropPOI(l2_sequence); //level 4 IsStackEmpty l4_isStackEmpty = new IsStackEmpty(l3_inverter, "poiStack"); Sequence l4_sequence = new Sequence(l3_ruf); //level 5 CanCarryPOI l5_canCarry = new CanCarryPOI(l4_sequence); Sequence l5_sequence = new Sequence(l4_sequence); //level 6 PopFromStack l6_popFromStack = new PopFromStack(l5_sequence, "poiStack", "item"); WalkToPOI l6_walkTo = new WalkToPOI(l5_sequence, "item"); PickupPOI l6_pickup = new PickupPOI(l5_sequence, "item"); if(mBehaveOnStart) Begin(); }
public BTGuard(Guard ownerBrain) : base(ownerBrain) { // Actions chaseAction = new Chase(NodeOwner); investigateAction = new Investigate(NodeOwner); lookAroundAction = new LookAround(NodeOwner); moveToNextPatrolPointAction = new MoveToPatrolPoint(NodeOwner); chooseNextPatrolPointAction = new ChooseNextPatrolPoint(NodeOwner); catchSpyAction = new CatchSpy(NodeOwner); // Conditions canIHearSpyCondition = new CanIHearSpy(NodeOwner); canISeeSpyCondition = new CanISeeSpy(NodeOwner); haveIArrivedToThePatrolPointCondition = new HaveIArrivedToThePatrolPoint(NodeOwner); haveIFinishedLookingAroundCondition = new HaveIFinishedLookingAround(NodeOwner); amIChasingCondition = new AmIChasing(NodeOwner); haveIFinishedInvestigatingCondition = new HaveIFinishedInvestigating(NodeOwner); canICatchSpyCondition = new CanICatchSpy(NodeOwner); // Composites rootSequence = new Sequence(); patrolSequence = new Sequence(); patrolParallel = new Parallel(3, 1); chaseParallel = new Parallel(3, 1); chaseSequence = new PrioritisedSequence(); engageSelector = new Selector(); patrolSelector = new Selector(); investigationParallel = new Parallel(3, 1); investigationSequence = new Sequence(); hearChaseSequence = new Sequence(); seeChaseSequence = new Sequence(); // Decorators repeatUntilFailDecoratorForPatrolSequence = new RepeatUntilFail(patrolSequence); // Tree Structure // Tree level 0 rootSequence.AddChildNode(patrolSelector); rootSequence.AddChildNode(engageSelector); // Tree level 1 patrolSelector.AddChildNode(amIChasingCondition); patrolSelector.AddChildNode(patrolParallel); engageSelector.AddChildNode(chaseParallel); engageSelector.AddChildNode(investigationParallel); // Tree level 2 patrolParallel.AddChildNode(repeatUntilFailDecoratorForPatrolSequence); patrolParallel.AddChildNode(canIHearSpyCondition); patrolParallel.AddChildNode(canISeeSpyCondition); chaseParallel.AddChildNode(chaseSequence); chaseParallel.AddChildNode(hearChaseSequence); chaseParallel.AddChildNode(seeChaseSequence); investigationParallel.AddChildNode(investigationSequence); investigationParallel.AddChildNode(canIHearSpyCondition); investigationParallel.AddChildNode(canISeeSpyCondition); // Tree level 3 patrolSequence.AddChildNode(moveToNextPatrolPointAction); patrolSequence.AddChildNode(haveIArrivedToThePatrolPointCondition); patrolSequence.AddChildNode(lookAroundAction); patrolSequence.AddChildNode(haveIFinishedLookingAroundCondition); patrolSequence.AddChildNode(chooseNextPatrolPointAction); chaseSequence.AddChildNode(chaseAction); chaseSequence.AddChildNode(canICatchSpyCondition); chaseSequence.AddChildNode(catchSpyAction); hearChaseSequence.AddChildNode(canIHearSpyCondition); hearChaseSequence.AddChildNode(chaseAction); seeChaseSequence.AddChildNode(canISeeSpyCondition); seeChaseSequence.AddChildNode(chaseAction); investigationSequence.AddChildNode(investigateAction); investigationSequence.AddChildNode(haveIFinishedInvestigatingCondition); }