예제 #1
0
        public void Action(List <Tuple <TypesPercept, Tuple <int, int> > > percepts)
        {
            if (Plan.Path.Count > 0)
            {
                var nextAction = Plan.NextAction();
                var percept    = percepts.Find(p => p.Item1 == nextAction);
                Move(percept.Item1);
                return;
            }

            if (percepts.Exists(p => p.Item1 == TypesPercept.Clean))
            {
                UpdateState();
            }
            if (percepts.Exists(p => p.Item1 == TypesPercept.Dirty))
            {
                Clean();
                return;
            }

            if (AreaTobeCleaned.Count > 0)
            {
                var nextCell = AreaTobeCleaned.First();
                AreaTobeCleaned.RemoveAt(0);
                Move(GetMove(nextCell));
            }
            else
            {
                if (!TaskFinished)
                {
                    TaskFinished = true;
                    MessageBox.Show("Task Finished");
                }
            }
        }
예제 #2
0
        private void ReactionTimeOnTick(object sender, EventArgs eventArgs)
        {
            // There's no area assigned for cleaning
            if (AreaTobeCleaned == null)
            {
                if (Role == ContractRole.Manager && AnnouncementMade && !TaskDistributed)
                {
                    ContractNet.Awarding(_messageBoardWin.Messages, Platform.Manager, Platform.Contractors, Platform.Task, Language);
                    TaskDistributed = true;
                }
                if (Role == ContractRole.Manager && !AnnouncementMade)
                {
                    ContractNet.Announcement(Platform.Task, Platform.Manager, Platform.Contractors,
                                             Language);
                    AnnouncementMade = true;
                    Thread.Sleep(2000);
                }
                if (Role == ContractRole.Contractor && AwaitingTaskAssignment || TaskDistributed)
                {
                    AreaTobeCleaned = SetSocialLaw(_messageBoardWin.Messages);
                }
                if (Role == ContractRole.Contractor && !AwaitingTaskAssignment)
                {
                    Thread.Sleep(2000);
                    ContractNet.Bidding(_messageBoardWin.Messages, Platform.Contractors);
                    AwaitingTaskAssignment = true;
                }
            }
            else
            {
                if (!InCleaningArea)
                {
                    if (Plan == null)
                    {
                        Plan = new Plan(TypesPlan.PathFinding, this);
                        Plan.BuildPlan(new Tuple <int, int>(X, Y), AreaTobeCleaned.First());
                    }
                    else if (Plan.Path.Count == 0)
                    {
                        InCleaningArea = true;
                    }
                }

                Action(Perceived());
            }
            _gui.Refresh();
        }