コード例 #1
0
        private void SetPendingStep()
        {
            List <Step> possibleSteps = new List <Step>();

            //go trough all of them and filter for conditions
            foreach (Step s in AllSteps.Where(x => !x.Taken))
            {
                List <char> preconditions     = s.PreConditionSteps.Select(x => x.Name).ToList();
                bool        allConditionsGood = true;
                foreach (char condition in preconditions)
                {
                    if (!OrderedSteps.Contains(condition))
                    {
                        allConditionsGood = false;
                    }
                }
                if (allConditionsGood)
                {
                    possibleSteps.Add(s);
                }
            }

            PendingStep = possibleSteps.OrderBy(p => p.Underprogress).ThenBy(s => s.Name).FirstOrDefault();

            if (PendingStep == null)
            {
                //Add steps with no parents to list, if they are still there
                //My mistake was here, thought, that parentless steps should be done as soon as they are alpabetically next
                List <Step> parentlessSteps = AllSteps.Where(s => !s.Taken && s.PreConditionSteps.Count < 1).OrderBy(s => s.Name).ToList();
                PendingStep = parentlessSteps.OrderBy(s => s.Name).FirstOrDefault();
                //parentlessSteps.Add(nextStep);
            }
            if (PendingStep == null)
            {
                return;
            }
            if (PendingStep.Underprogress)
            {
                MoveTime();
                SetPendingStep();
            }
        }