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(); } }
private void MoveTime() { //Console.SetCursorPosition(0, PassedTime); //Console.Write(PassedTime+ " "); //Console.SetCursorPosition(2, PassedTime); //Console.Write(WorkerCollection[0].WorkinStepChar); //Console.SetCursorPosition(3, PassedTime); //Console.Write(WorkerCollection[1].WorkinStepChar); PassedTime++; foreach (Worker w in WorkerCollection) { w.TimeLeft--; if (w.TimeLeft == 0) { OrderedSteps.Add(w.WorkinStepChar); w.WorkingOnStep.Taken = true; w.WorkingOnStep = null; } } }