public void When_child_succeeds_Then_returns_success()
        {
            var returnCode = new RootSelector(() => 0,
                TestHelper.CreateSuccessAction()).Behave();

            Assert.AreEqual(BehaviourReturnCode.Success, returnCode);
        }
        public void When_child_is_running_Then_returns_running()
        {
            var returnCode = new RootSelector(() => 0,
                TestHelper.CreateRunningAction()).Behave();

            Assert.AreEqual(BehaviourReturnCode.Running, returnCode);
        }
        public void When_child_fails_Then_returns_fail()
        {
            var returnCode = new RootSelector(() => 0,
                TestHelper.CreateFailiedAction()).Behave();

            Assert.AreEqual(BehaviourReturnCode.Failure, returnCode);
        }
        public void Setup()
        {
            var isThiefNearTreasureConditional = new Conditional(IsThiefNearTreasure);
            var makethiefFleeAction = new BehaviourAction(MakeThiefFlee);
            var sequence = new Sequence(new Inverter(isThiefNearTreasureConditional), makethiefFleeAction);

            var chooseCastleAction = new BehaviourAction(ChooseACastleToFlyTo);
            var flytoCastleAction = new BehaviourAction(FlyToCastle);
            var fightAction = new BehaviourAction(FightGuards);
            var strongEnoughConditional = new Conditional(StrongEnough);
            var takeGold = new BehaviourAction(TakeGold);
            var flytoHomeAction = new BehaviourAction(FlyToHome);
            var storeRobingsAction = new BehaviourAction(StoreGold);
            var secondSequence = new Sequence(chooseCastleAction, flytoCastleAction, fightAction, strongEnoughConditional, takeGold,
                                    flytoHomeAction, storeRobingsAction);
            var rootSelector = new RootSelector(SwitchNodes, sequence, secondSequence);
            _behaviour = new Behaviour(rootSelector);
        }
        private void Setup()
        {
            var tooClose = new Conditional(isTooClose);
            var targetMoved = new Conditional(hasTargetMoved);
            var pathFound = new Conditional(hasPathBeenFound);
            var reachedCell = new Conditional(hasReachedCell);
            var reachedTarget = new Conditional(hasReachedTarget);
            var isNewPath = new Conditional(hasNewPath);

            //setup all actions and their delegate functions
            BehaviourAction moveToCell = new BehaviourAction(moveTowardsCell);
            BehaviourAction calcPath = new BehaviourAction(calculatePath);
            BehaviourAction initPathfinder = new BehaviourAction(initializePathfinder);
            BehaviourAction getNextCell = new BehaviourAction(getNextPathCell);
            BehaviourAction setPath = new BehaviourAction(setNewPath);
            BehaviourAction getPath = new BehaviourAction(getCurrentPath);
            BehaviourAction updatePosition = new BehaviourAction(updateTargetPosision);
            BehaviourAction reset = new BehaviourAction(resetPathfinder);
            BehaviourAction animate = new BehaviourAction(updateAnimation);

            //setup an initilization branch
            var initialize = new Sequence(initPathfinder, calcPath);

            //if the target has moved, reset and calculate a new path
            var ifMovedCreateNewPath = new Selector(new Inverter(targetMoved), new Inverter(reset), calcPath);
            var ifPathFoundGetPath = new Selector(new Inverter(pathFound), getPath);
            var ifPathNewUseIt = new Selector(new Inverter(isNewPath), setPath);
            var ifReachedCellGetNext = new Selector(new Inverter(reachedCell), getNextCell);
            var ifNotReachedTargetMoveTowardsCell = new Selector(reachedTarget, moveToCell);

            var follow = new Selector(new Inverter(tooClose), updatePosition, ifMovedCreateNewPath, ifPathFoundGetPath,
                ifPathNewUseIt, ifReachedCellGetNext, ifNotReachedTargetMoveTowardsCell, animate);

            var root = new RootSelector(SwitchBehaviours, initialize, follow);

            //set a reference to the root
            _behaviour = new Behaviour(root);
        }
Ejemplo n.º 6
0
 public Behaviour(RootSelector root)
 {
     _rootSelector = root;
 }