示例#1
0
        private BehaviourReturnCode BehaveInternal()
        {
            try
            {
                switch (RootSelector.Behave())
                {
                case BehaviourReturnCode.Failure:
                    ReturnCode = BehaviourReturnCode.Failure;
                    return(ReturnCode);

                case BehaviourReturnCode.Success:
                    ReturnCode = BehaviourReturnCode.Success;
                    return(ReturnCode);

                case BehaviourReturnCode.Running:
                    ReturnCode = BehaviourReturnCode.Running;
                    return(ReturnCode);

                default:
                    ReturnCode = BehaviourReturnCode.Running;
                    return(ReturnCode);
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Console.Error.WriteLine(e.Message, e.StackTrace);
#endif
                ReturnCode = BehaviourReturnCode.Failure;
                return(ReturnCode);
            }
        }
 /// <summary>
 /// Checks an interrupt condition, executing the given behaviour only if the condition returns False
 /// -Returns Success if the given behaviour returns Success and the condition returns False
 /// -Returns Running if the given behaviour returns Running and the condition returns False
 /// -Returns Failure if the given behaviour returns Failure or the condition returns True
 /// 
 /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write
 /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur
 /// </summary>
 /// <param name="name">the name of the interruptible</param>
 /// <param name="behaviour"></param>
 /// <param name="interruptCondition"></param>
 /// <param name="onInterruptReturn"></param>
 public Interruptible(string name, BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn)
 {
     Name = name;
     _behaviourComponent = behaviour;
     _interruptCondition = interruptCondition;
     _onInterruptReturn = onInterruptReturn;
 }
示例#3
0
 /// <summary>
 /// Checks an interrupt condition, executing the given behaviour only if the condition returns False
 /// -Returns Success if the given behaviour returns Success and the condition returns False
 /// -Returns Running if the given behaviour returns Running and the condition returns False
 /// -Returns Failure if the given behaviour returns Failure or the condition returns True
 ///
 /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write
 /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur
 /// </summary>
 /// <param name="name">the name of the interruptible</param>
 /// <param name="behaviour"></param>
 /// <param name="interruptCondition"></param>
 /// <param name="onInterruptReturn"></param>
 public Interruptible(string name, BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn)
 {
     Name = name;
     _behaviourComponent = behaviour;
     _interruptCondition = interruptCondition;
     _onInterruptReturn  = onInterruptReturn;
 }
        public void When_interrupt_throws_then_doesnt_interrupt()
        {
            const BehaviourReturnCode actual = BehaviourReturnCode.Success;
            var action = new BehaviourAction(() => actual);

            var condition  = new Conditional(() => { throw new Exception(); });
            var returnCode = new Interruptible(action, condition, BehaviourReturnCode.Success).Behave();

            Assert.AreEqual(actual, returnCode);
        }
 /// <summary>
 /// Checks an interrupt condition, executing the given behaviour only if the condition returns False
 /// -Returns Success if the given behaviour returns Success and the condition returns False
 /// -Returns Running if the given behaviour returns Running and the condition returns False
 /// -Returns Failure if the given behaviour returns Failure or the condition returns True
 /// 
 /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write
 /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur
 /// </summary>
 /// <param name="behaviour"></param>
 /// <param name="interruptCondition"></param>
 /// <param name="onInterruptReturn"></param>
 public Interruptible(BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn)
     : this("", behaviour, interruptCondition, onInterruptReturn)
 {
 }
示例#6
0
 /// <summary>
 /// Checks an interrupt condition, executing the given behaviour only if the condition returns False
 /// -Returns Success if the given behaviour returns Success and the condition returns False
 /// -Returns Running if the given behaviour returns Running and the condition returns False
 /// -Returns Failure if the given behaviour returns Failure or the condition returns True
 ///
 /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write
 /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur
 /// </summary>
 /// <param name="behaviour"></param>
 /// <param name="interruptCondition"></param>
 /// <param name="onInterruptReturn"></param>
 public Interruptible(BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) :
     this("", behaviour, interruptCondition, onInterruptReturn)
 {
 }