Ejemplo n.º 1
0
        /// <summary>
        /// Fires the competence priority element.
        /// 
        /// This method goes through its list of competence elements
        /// and fires the first one that is ready. In that case,
        /// the result of the competence element is returned. Otherwise,
        /// it returns FireResult(True, None) (this can never be returned
        /// by a competence element and is therefore uniquely identifyable).
        /// </summary>
        /// <returns>The result of firing the competence priority element.</returns>
        public override FireResult fire()
        {
            log.Debug("Fired");
            FireArgs args = new FireArgs();

            foreach (CompetenceElement elem in elements)
            {
                // as the method ignores the timestamp, we can give it
                // whatever we want
                if (elem.isReady(0))
                {
                    FireResult result =  elem.fire();
                    args.FireResult = result.continueExecution();
                    args.Time = DateTime.Now;
                    BroadCastFireEvent(args);

                    return result;
                }
            }
            log.Debug("Priority Element failed");

            args.FireResult = true;
            args.Time = DateTime.Now;
            BroadCastFireEvent(args);

            return new FireResult(true, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fires the action pattern.
        /// 
        /// This method fires the current action / sense / sense-act or
        /// competence of the pattern. In case of firing an action / sense
        /// / sense-act, the method points to the next element in the
        /// pattern and returns FireResult(True, None) if the current
        /// action / sense / sense-act was successful (i.e. evaluated to
        /// True) and not the last action in the sequence, in which case
        /// it returns FireResult(False, None) and resets the action
        /// pattern.
        /// 
        /// If the current element is a competence, then competence is
        /// returned as the next element by returning
        /// FireResult(True, competence), and the action pattern is
        /// reset.
        /// </summary>
        /// <returns>The result of firing the action pattern.</returns>
        public override FireResult fire()
        {
            log.Debug("Fired");
            FireArgs args = new FireArgs();

            CopiableElement element = elements[elementIdx];
            if (element is POSHAction || element is POSHSense)
            {
                bool result;
                if (element is POSHAction)
                    result = ((POSHAction)element).fire().continueExecution();
                else
                    result = ((POSHSense)element).fire().continueExecution();

                if (!result)
                {
                    log.Debug(string.Format("Action/Sense {0} failed", element.getName()));
                    elementIdx = 0;
                    args.FireResult = result;
                    args.Time = DateTime.Now;

                    BroadCastFireEvent(args);
                    return new FireResult(false, null);
                }

                // check if we've just fired the last action
                elementIdx += 1;
                if (elementIdx >= elements.Count)
                {
                    elementIdx = 0;
                    args.FireResult = result;
                    args.Time = DateTime.Now;

                    BroadCastFireEvent(args);
                    return new FireResult(false, null);
                }
                args.FireResult = result;
                args.Time = DateTime.Now;

                BroadCastFireEvent(args);
                return new FireResult(true, null);
            }
            else if (element is Competence)
            {
                // we have a competence
                elementIdx = 0;
                args.FireResult = true;
                args.Time = DateTime.Now;

                BroadCastFireEvent(args);
                return new FireResult(true, element);
            }

            return null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs the action and returns if it was successful.
        /// </summary>
        /// <returns>True if the action was successful, and False otherwise.</returns>
        public override FireResult fire()
        {
            bool success = action.Second.ExecuteAction(action.First);
            FireArgs args = new FireArgs();
            args.FireResult = success;
            args.Time = DateTime.Now;

            BroadCastFireEvent(args);

            log.Debug("Firing");
            return new FireResult(success,null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fires the trigger.
        /// 
        /// The trigger returns True of all senses/sense-acts of the
        /// trigger evaluate to True.
        /// </summary>
        /// <returns>If all the senses/sense-acts evaluate to True.</returns>
        public bool fire()
        {
            bool success = true;

            log.Debug("Firing");
            foreach (POSHSense sense in this.senses)
                if (!sense.fire().continueExecution())
                {
                    log.Debug(string.Format("Sense {0} failed",sense.getName()));
                    success = false;
                    break;
                }

            // logging the event
            FireArgs args = new FireArgs();
            args.FireResult = success;
            args.Time = DateTime.Now;

            BroadCastFireEvent(args);

            return success;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fires the drive element.
        /// 
        /// This method fires the current drive element and always
        /// returns None. It uses the slip-stack architecture to determine
        /// the element to fire in the next step.
        /// </summary>
        /// <returns>The result returned is null.</returns>
        public override FireResult fire()
        {
            FireResult result;
            FireArgs args = new FireArgs();

            log.Debug("Fired");
            // if our element is an action, we just fire it and do
            // nothing afterwards. That's because we can only have an action
            // as an element, if it is the drive element's root element.
            // Hence, we didn't descend in the plan tree and can keep
            // the same element.

            if (element is POSHAction || element.GetType().IsSubclassOf(typeof(POSHAction)))
            {
                ((POSHAction)element).fire();
                element = root;
                args.FireResult = false;
                args.Time = DateTime.Now;
                BroadCastFireEvent(args);
                return null;
            }

            // the element is a competence or an action pattern
            result = ((ElementCollection)element).fire();
            args.FireResult = false;
            args.Time = DateTime.Now;
            BroadCastFireEvent(args);
            if (result.continueExecution())
            {
                // if we have a new next element, store it as the next
                // element to execute
                CopiableElement next = result.nextElement();
                if (next is CopiableElement)
                    element = next;
            }
            else
                // we were told not to continue the execution -> back to root
                // We must not call reset() here, as that would also reset
                // the firing frequency of the element.
                element = root;

            return null;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fires the competence.
        /// 
        /// This method first checks if the competence's goal is satisfied
        /// (if the goal is not None). If that is the case, then it
        /// returns FireResult(False, None). Otherwise it fires the
        /// priority elements one by one. On the first successful firing
        /// of a competence priority element, the method returns the
        /// result of the priority element. If no priority element fired
        /// successfully, then FireResult(False, None) is returned.
        /// </summary>
        /// <returns>The result of firing an element, or
        ///         FireResult(False, None)</returns>
        public override FireResult fire()
        {
            log.Debug("Fired");
            FireArgs args = new FireArgs();

            // check if the goal is satisfied
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal satisfied");
                args.FireResult = false;
                args.Time = DateTime.Now;
                BroadCastFireEvent(args);

                return new FireResult(false, null);
            }
            // process the elements
            FireResult result;
            foreach (CompetencePriorityElement elem in elements)
            {
                result = elem.fire();
                // check if the competence priority element failed
                if (result.continueExecution() && !(result.nextElement() is CopiableElement) )
                    continue;
                args.FireResult = result.continueExecution();
                args.Time = DateTime.Now;
                BroadCastFireEvent(args);

                return result;
            }
            // we failed
            log.Debug("Failed");
            args.FireResult = false;
            args.Time = DateTime.Now;
            BroadCastFireEvent(args);

            return new FireResult(false, null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fires the drive collection.
        /// 
        /// This method first checks if the goal (if not null) is met. If
        /// that is the case, then FireResult(False, self) is
        /// returned. Otherwise it goes through the list of priority
        /// elements until the first one was fired successfully (returning
        /// something else than None). In that case, FireResult(True,
        /// None) is returned. If none of the priority elements were
        /// successful, FireResult(False, None) is returned, indicating a
        /// failing of the drive collection.
        /// 
        /// To summarise:
        ///     - FireResult(True, None): drive element fired
        ///     - FireResult(False, self): goal reached
        ///     - FireResult(False, None): drive failed
        /// </summary>
        /// <returns>The result of firing the drive.</returns>
        public override FireResult fire()
        {
            log.Debug("Fired");
            FireArgs args = new FireArgs();
            // check if goal reached
            if (goal is Trigger && goal.fire())
            {
                log.Debug("Goal Satisfied");
                args.FireResult = false;
                args.Time = DateTime.Now;
                BroadCastFireEvent(args);
                return new FireResult(false, this);
            }

            // fire elements
            foreach (DrivePriorityElement elem in elements)
                // a priority element returns None if it wasn't
                // successfully fired
                if (elem.fire() != null)
                {
                    args.FireResult = true;
                    args.Time = DateTime.Now;
                    BroadCastFireEvent(args);
                    return new FireResult(true, null);
                }

            // drive failed (no element fired)
            log.Debug("Failed");

            args.FireResult = false;
            args.Time = DateTime.Now;
            BroadCastFireEvent(args);
            return new FireResult(false, null);
        }