示例#1
0
 /// <summary>
 /// Initialises the action pattern.
 /// 
 /// The log domain is set to [AgentId].AP.[patternName]
 /// </summary>
 /// <param name="agent">The corresponding agent.</param>
 /// <param name="patternName">The name of the action pattern.</param>
 /// <param name="elements">The sequence of actions or senses and 
 ///         an optional competence as the final element.</param>
 /// </param>
 public ActionPattern(Agent agent, string patternName, CopiableElement []elements)
     : base(string.Format("AP.{0}", patternName),agent)
 {
     name = patternName;
     this.elements = (elements.Length > 0) ? new List<CopiableElement>(elements) : new List<CopiableElement>();
     this.elementIdx = 0;
     log.Debug("Created");
 }
示例#2
0
        /// <summary>
        /// Builds a competence element from the given structure.
        ///
        /// The competence element has to be given as a the quadruple (name,
        /// trigger, triggerable, retries), where the name is a string, the
        /// trigger is described in L{addCompetence}, the triggerable is the
        /// name of an action, competence or action pattern, and retries is the
        /// number of retries and given as long.
        ///
        /// If the triggerable cannot be found, then a NameError is raised.
        /// </summary>
        /// <param name="element">The structure of the competence element (Tuple[name,
        /// trigger, triggerable, retries]).</param>
        /// <param name="agent">The agent that the competence element is built for.</param>
        /// <param name="competences">A competence object dictionary.</param>
        /// <param name="actionPatterns">An action pattern object dictionary.</param>
        /// <returns>The competence element described by the given structure.</returns>
        /// <exception cref="NameException"> If the triggerable cannot be found.
        /// </exception>
        internal CompetenceElement buildCompetenceElement(Tuple <string, List <object>, string, int> element,
                                                          Agent agent, Dictionary <string, Competence> competences, Dictionary <string, ActionPattern> actionPatterns)
        {
            Trigger         trigger     = buildTrigger(agent, element.Second);
            CopiableElement triggerable = getTriggerable(agent, element.Third, competences, actionPatterns);

            return(new CompetenceElement(agent, element.First, trigger, triggerable, element.Forth));
        }
示例#3
0
 /// <summary>
 /// Initialises the result of firing an element.
 /// 
 /// For a more detailed description of the arguments, read the
 /// class documentation.
 /// </summary>
 /// <param name="continueExecution">If we want to continue executing the current
 /// part of the plan.</param>
 /// <param name="nextElement">The next plan element to fire.</param>
 public FireResult(bool continueExecution, CopiableElement nextElement)
 {
     continueExecuting = continueExecution;
     if (continueExecution && nextElement is CopiableElement)
         // copy the next element, if there is one
         next = (ElementCollection)nextElement.copy();
     else
         next = null;
     // FIX: @swen: here must be an error in the original implementation I just uncommented the next line because it seemed wrong
     // next = nextElement;
 }
示例#4
0
        /// <summary>
        /// Initialises the competence element.
        /// 
        /// The log domain is set to [AgentName].CE.[element_name].
        /// </summary>
        /// <param name="agent">The competence element's agent.</param>
        /// <param name="elementName">The name of the competence element.</param>
        /// <param name="trigger">The element's trigger</param>
        /// <param name="element">The element to fire (Action,Competence or ActionPattern).</param>
        /// <param name="maxRetries">The maximum number of retires. If this is set
        ///         to a negative number, it is ignored.</param>
        public CompetenceElement(Agent agent, string elementName, Trigger trigger, CopiableElement element, int maxRetries)
            : base(string.Format("CE.{0}",elementName),agent)
        {
            this.name = elementName;
            this.trigger = trigger;
            this.element = element;
            this.maxRetries = maxRetries;
            this.retries = 0;

            log.Debug("Created");
        }
示例#5
0
        /// <summary>
        /// Sets the elements of an action pattern.
        /// 
        /// Calling this method also resets the action pattern.
        /// </summary>
        /// <param name="elements">The list of elements of the action patterns. 
        ///         A sequence of Actions. An additional Competence can be the
        ///         last Element of the ActionPattern.</param>
        public void setElements(CopiableElement [] elements)
        {
            this.elements = new List<CopiableElement>(elements);

            reset();
        }