示例#1
0
        private void LoadWithSampleData()
        {
            ExamplePage page = new ExamplePage(
                "When I see fruit, move toward it.\nWhen I bump fruit, eat it.",
                new ReflexDesc[] {
                new ReflexDesc(
                    new string[] {
                    "sensor.eyes",
                    "filter.fruit",
                    "actuator.movement",
                    "selector.towardclosest",
                }),
                new ReflexDesc(
                    new string[] {
                    "sensor.bumpers",
                    "filter.fruit",
                    "actuator.eat",
                }),
            });


            ActorHelp example = new ActorHelp();

            example.description = "This is the actor description.";
            ExampleProgram program = new ExampleProgram();

            program.pages = new List <ExamplePage>();
            program.pages.Add(page);
            example.programs = new List <ExampleProgram>();
            example.programs.Add(program);
            instance.actorHelp.Add("BokuBot", example);
        }
示例#2
0
 private int CompareByRank(ExamplePage lhs, ExamplePage rhs)
 {
     if (lhs.rank < rhs.rank)
     {
         return(1);
     }
     if (lhs.rank > rhs.rank)
     {
         return(-1);
     }
     return(0);
 }
示例#3
0
        /// <summary>
        /// Build an example program from the specified brain contents.
        /// </summary>
        /// <param name="brain"></param>
        /// <returns></returns>
        public static ExampleProgram FromBrain(Brain brain)
        {
            ExampleProgram program = new ExampleProgram();

            program.pages = new List <ExamplePage>();

            foreach (Task task in brain.tasks)
            {
                ExamplePage page = ExamplePage.FromTask(task);
                program.pages.Add(page);
            }

            return(program);
        }
示例#4
0
        /// <summary>
        /// Build an ExamplePage from the specified task
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public static ExamplePage FromTask(Task task)
        {
            ExamplePage page = new ExamplePage();

            page._reflexDescList = new List <ReflexDesc>();

            foreach (Reflex reflex in task.reflexes)
            {
                ReflexDesc desc = reflex.Data.ToDesc();
                page._reflexDescList.Add(desc);
            }

            return(page);
        }
示例#5
0
 public bool ActorCompatible(GameActor actor)
 {
     for (int i = 0; i < pages.Count; ++i)
     {
         ExamplePage page = pages[i];
         for (int j = 0; j < page.reflexes.Length; ++i)
         {
             if (!page.reflexes[j].ActorCompatible(actor))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#6
0
        private void RankAndSortProgrammingExamples(
            RankSettings settings,
            GameActor actor,
            ProgrammingElement selected,
            ReflexData reflex)
        {
            for (int i = 0; i < programmingExamples.Count; ++i)
            {
                ExamplePage example = programmingExamples[i];
                RankProgrammingExample(
                    example,
                    settings,
                    actor,
                    selected,
                    reflex);
            }

            programmingExamples.Sort(CompareByRank);
        }
示例#7
0
        private void RankProgrammingExample(
            ExamplePage example,
            RankSettings settings,
            GameActor actor,
            ProgrammingElement selected,
            ReflexData reflex)
        {
            if (!example.ActorCompatible(actor))
            {
                example.rank = -1;
                return;
            }

            string selectedUpid;

            if (selected != null)
            {
                selectedUpid = selected.upid;
            }
            else
            {
                selectedUpid = String.Empty;
            }


            example.rank = 0;

            for (int iReflex = 0; iReflex < example.reflexes.Length; ++iReflex)
            {
                ReflexData exampleReflex = example.reflexes[iReflex];

                // Rank sensor
                if (selected == exampleReflex.Sensor)
                {
                    example.rank += RankElements(exampleReflex.Sensor, selected, settings.sensorRank);
                }

                if (exampleReflex.Sensor != null && reflex.Sensor != null)
                {
                    example.rank += RankElements(exampleReflex.Sensor, reflex.Sensor, settings.sensorRank);
                }

                // Rank selector
                if (selected == exampleReflex.Selector)
                {
                    example.rank += RankElements(exampleReflex.Selector, selected, settings.selectorRank);
                }

                if (exampleReflex.Selector != null && reflex.Selector != null)
                {
                    example.rank += RankElements(exampleReflex.Selector, reflex.Selector, settings.selectorRank);
                }

                // Rank actuator
                if (selected == exampleReflex.Actuator)
                {
                    example.rank += RankElements(exampleReflex.Actuator, selected, settings.actuatorRank);
                }

                if (exampleReflex.Actuator != null && reflex.Actuator != null)
                {
                    example.rank += RankElements(exampleReflex.Actuator, reflex.Actuator, settings.actuatorRank);
                }

                // Rank filters
                for (int i = 0; i < exampleReflex.Filters.Count; ++i)
                {
                    if (selected == exampleReflex.Filters[i])
                    {
                        example.rank += RankElements(exampleReflex.Filters[i], selected, settings.filterRank);
                    }

                    for (int j = 0; j < reflex.Filters.Count; ++j)
                    {
                        example.rank += RankElements(exampleReflex.Filters[i], reflex.Filters[j], settings.filterRank);
                    }
                }

                // Rank modifiers
                for (int i = 0; i < exampleReflex.Modifiers.Count; ++i)
                {
                    if (selected == exampleReflex.Modifiers[i])
                    {
                        example.rank += RankElements(exampleReflex.Modifiers[i], selected, settings.modifierRank);
                    }

                    for (int j = 0; j < reflex.Modifiers.Count; ++j)
                    {
                        example.rank += RankElements(exampleReflex.Modifiers[i], reflex.Modifiers[j], settings.modifierRank);
                    }
                }
            }
        }