Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.GPSRObject"/> class.
 /// </summary>
 /// <param name="name">The name of the object</param>
 /// <param name="type">The type of the object</param>
 /// <param name="tier">The difficulty degree for GRASPING the object</param>
 public Object(string name, ObjectType type, DifficultyDegree tier)
 {
     this.Name       = name;
     this.Tier       = tier;
     this.Type       = type;
     this.properties = new Dictionary <string, string>();
 }
Пример #2
0
        /// <summary>
        /// Randomly selects a grammar of the specified difficulty degree (or lower)
        /// and uses it to produce a random task sentence prototype. The prototype
        /// contains several tokens to be replaced by random values
        /// </summary>
        /// <param name="tier">The maximum difficulty degree allowed</param>
        /// <returns>A task sentence prototype with unsolved constructs</returns>
        protected TaskNode GetTaskPrototype(DifficultyDegree tier)
        {
            Grammar g;

            g = GetRandomGrammar(tier);
            if (g == null)
            {
                Err("No grammars could be selected. Aborting.");
                return(null);
            }

            if (!Quiet)
            {
                if (String.IsNullOrEmpty(g.Name))
                {
                    Console.WriteLine("Selected {0} difficulty degree grammar.", g.Tier);
                }
                else
                {
                    Console.WriteLine("Selected {0} ({1} difficulty degree grammar).", g.Name, g.Tier);
                }
            }

            try {
                return(g.GenerateSentence(rnd));
            } catch (StackOverflowException) {
                Err("Can't generate grammar. Grammar is recursive");
                return(null);
            } catch {
                Err("Can't generate grammar. Unexpected error");
                return(null);
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.WildcardReplacer"/> class.
 /// </summary>
 /// <param name="g">A Generator which contains the databases and the random generator.</param>
 /// <param name="tier">The maximum difficulty degree for wildcard replacements</param>
 public WildcardReplacer(Generator g, DifficultyDegree tier)
 {
     this.textWildcards = new List <TextWildcard> ();
     this.wildcards     = new Dictionary <string, Wildcard> ();
     this.generator     = g;
     this.tier          = tier;
     FillAvailabilityLists();
 }
Пример #4
0
        /// <summary>
        /// Gets a random element from the provided list with the specified difficulty degree.
        /// </summary>
        /// <param name="tier">The difficulty for fetched object.</param>
        /// <param name="baseList">Base list which contains all objects.</param>
        /// <typeparam name="T">The type of object to fetch. Must be ITiered.</typeparam>
        /// <returns>A random element from the list.</returns>
        private T GetTieredElement <T>(DifficultyDegree tier, List <T> baseList) where T : ITiered
        {
            if ((baseList == null) || (baseList.Count < 1))
            {
                return(default(T));                // throw new Exception ("Provided baselist is null or empty");
            }
            // Get a list with all the elements of the requested difficulty degree
            List <T> tieredList = new List <T> (baseList.Where(idd => idd.Tier == tier));

            if (tieredList.Count < 1)
            {
                return(default(T));                //throw new Exception("No elements were found for the requested difficulty degree");
            }
            // Return random object
            return(tieredList[rnd.Next(tieredList.Count)]);
        }
Пример #5
0
 /// <summary>
 /// Randomly generates a task with the given grammar
 /// </summary>
 /// <param name="grammarName">The name of the grammar to generate the task</param>
 /// <param name="tier">The maximum difficulty degree allowed to produce the task</param>
 /// <returns></returns>
 public Task GenerateTask(string grammarName, DifficultyDegree tier)
 {
     for (int i = 0; i < 3; ++i)
     {
         try
         {
             string           taskPrototype = GetTaskPrototype(grammarName);
             WildcardReplacer replacer      = new WildcardReplacer(this, tier);
             if (String.IsNullOrEmpty(taskPrototype))
             {
                 return(null);
             }
             return(replacer.GetTask(taskPrototype));
         }
         catch
         {
             continue;
         }
     }
     return(null);
 }
Пример #6
0
        /// <summary>
        /// Obtains a random grammar with the highest difficulty degree possible
        /// </summary>
        /// <param name="tier">The maximum difficulty degree allowed</param>
        /// <returns>A grammar</returns>
        private Grammar GetRandomGrammar(DifficultyDegree tier)
        {
            int     idd;
            Grammar g;

            foreach (DifficultyDegree dd in sdd)
            {
                idd = (int)dd;
                if ((idd > (int)tier) || (idd < 1))
                {
                    continue;
                }
                g = GetTieredElement(dd, allGrammars);
                if (g != null)
                {
                    return(g);
                }
                if (!Quiet)
                {
                    Warn("No grammars were found for {0} difficulty degree. {1}", dd, idd > 1 ? "Grammar tier reduced." : String.Empty);
                }
            }
            return(null);
        }
Пример #7
0
 /// <summary>
 /// Randomly generates a task with the requested difficulty degree
 /// </summary>
 /// <param name="tier">The maximum difficulty degree allowed to produce the task</param>
 /// <returns></returns>
 public Task GenerateTask(DifficultyDegree tier)
 {
     for (int i = 0; i < 3; ++i)
     {
         try
         {
             TaskNode         root          = GetTaskPrototype(tier);
             string           taskPrototype = root.Render();
             WildcardReplacer replacer      = new WildcardReplacer(this, tier);
             if (String.IsNullOrEmpty(taskPrototype))
             {
                 return(null);
             }
             Task t = replacer.GetTask(taskPrototype);
             t.Tree = root;
             return(t);
         }
         catch
         {
             continue;
         }
     }
     return(null);
 }
Пример #8
0
        /// <summary>
        /// Adds an object to the category
        /// </summary>
        /// <param name="name">The name of the object to add.</param>
        /// <param name="type">The type of the object to add.</param>
        /// <param name="type">The difficulty degree of the object to add.</param>
        public void AddObject(string name, ObjectType type, DifficultyDegree tier)
        {
            Object o = new Object(name, type, tier);

            this.AddObject(o);
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.PredefindedQuestion"/> class.
 /// </summary>
 /// <param name="question">The question</param>
 /// <param name="answer">The answer for the question</param>
 /// <param name="tier">The  difficulty degree (tier) for UNDERSTANDING the question</param>
 public PredefinedQuestion(string question, string answer, DifficultyDegree tier)
 {
     this.Question = question;
     this.Answer   = answer;
     this.Tier     = tier;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.Gesture"/> class.
 /// </summary>
 /// <param name="name">The name of the gesture</param>
 /// <param name="tier">The difficulty degree for DETECTING the gesture</param>
 public Gesture(string name, DifficultyDegree tier)
 {
     this.Name = name;
     this.Tier = tier;
 }