public override void Start()
        {
            while (true)
            {
                var key = new ConsoleKeyInfo();
                bool keyread = false;

                while (Console.KeyAvailable)
                {
                    var newkey = Console.ReadKey(true);
                    if (actionMap.ContainsKey(newkey.KeyChar))
                    {
                        key = newkey;
                        keyread = true;
                    }

                }

                if (keyread == true)
                    currentAction = this.actionMap[key.KeyChar];
                else
                    continue;

                this.performAction(currentAction);

                this.performAction(new GetAllPerceptsAction());

            }
        }
        public HumanInterfaceController(Agent agent, KeyboardSettings settings)
            : base(agent)
        {
            this.settings = settings;

            this.actionMap.Add(settings.MoveUp(),new MoveUnitAction(new Vector(0,1)));
            this.actionMap.Add(settings.MoveDown(),new MoveUnitAction(new Vector(0,-1)));
            this.actionMap.Add(settings.MoveRight(),new MoveUnitAction(new Vector(1,0)));
            this.actionMap.Add(settings.MoveLeft(),new MoveUnitAction(new Vector(-1,0)));

            this.currentAction = this.actionMap[this.settings.MoveUp()];
        }
Пример #3
0
        //this method will be called when an agent recieves a percept
        private void agent_perceptRecieved(object sender, UnaryValueEvent<PerceptCollection> evt)
        {
            //go through all percepts
            foreach (Percept percept in evt.Value.Percepts)
            {

                if (percept is VacuumVision)
                {
                    //Check if the vacuum cleaner is in a tile with dirt then call suck
                    //otherwise move the vacuum cleaner
                    VacuumVision vision = percept as VacuumVision;

                    if (vision.ContainsDirt)
                        this.nextAction = new SuckAction();
                    else
                        this.nextAction = new MoveVacuumCleanerAction();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Performs an action on a certain agent, the method is frozen until the action has completed.
        /// </summary>
        /// <param name="action">The action that is being performed</param>
        public void performAction(EntityXmasAction action)
        {
            action.Resolved += action_Completed;
            agent.QueueAction(action);

            actionComplete.WaitOne();

            PerceptCollection activepercepts = null;
            lock (this)
            {
                activepercepts = newpercepts;
                newpercepts = null;
            }

            if (PerceptsRecieved != null && activepercepts != null && action.ActionFailed == false)
            {
                PerceptsRecieved(this, new UnaryValueEvent<PerceptCollection>(activepercepts));
            }
        }
Пример #5
0
 /// <summary>
 /// Run action as child action of this action
 /// </summary>
 /// <param name="entity">entity the action is put on</param>
 /// <param name="action">action to be executed</param>
 public void RunAction(XmasEntity entity, EntityXmasAction action)
 {
     this.MakeActionChild(action);
     action.Source = entity;
     ActionManager.ExecuteAction(action);
 }