Пример #1
0
 public Day7Worker(Day7Worker _tmp)
 {
     this.ID            = _tmp.ID;
     this.Working       = _tmp.Working;
     this.WorkingOnChar = _tmp.WorkingOnChar;
     this.TimeLeft      = _tmp.TimeLeft;
 }
Пример #2
0
        public int RunWork(out Dictionary <int, List <Day7Worker> > workList)
        {
            workList = this.workList;
            while (Chash.Count > 0)
            {
                foreach (var worker in workers)
                {
                    bool isCompleted = false;

                    char work = '*';

                    if (worker.Working)
                    {
                        worker.TimeLeft--;

                        if (worker.TimeLeft == 0)
                        {
                            isCompleted = true;
                        }
                    }

                    if (isCompleted)
                    {
                        worker.Working = false;
                        Chash.Remove(worker.WorkingOnChar);
                        foreach (var v in Dependencies.Where(w => w.Value.Contains(worker.WorkingOnChar)).ToList())
                        {
                            Dependencies[v.Key] = Dependencies[v.Key].Remove(Dependencies[v.Key].IndexOf(worker.WorkingOnChar), 1);
                        }
                        worker.WorkingOnChar = '*';
                        isCompleted          = false;
                    }


                    if (!worker.Working)
                    {
                        try
                        {
                            work = Dependencies.OrderByDescending(o => o.Key).First(f => String.IsNullOrEmpty(f.Value)).Key;
                        }

                        catch { }

                        if (work != '*')
                        {
                            Dependencies.Remove(work);
                            worker.Working       = true;
                            worker.WorkingOnChar = work;
                            worker.TimeLeft      = timebase + this.AlphaProvider.CharValue(work);
                        }
                    }

                    /*
                     * else
                     * {
                     *  worker.TimeLeft--;
                     *
                     *  if (worker.TimeLeft == 0)
                     *      isCompleted = true;
                     * }
                     *
                     * if (isCompleted)
                     * {
                     *  worker.Working = false;
                     *  Chash.Remove(worker.WorkingOnChar);
                     *  foreach (var v in Dependencies.Where(w => w.Value.Contains(worker.WorkingOnChar)).ToList())
                     *      Dependencies[v.Key] = Dependencies[v.Key].Remove(Dependencies[v.Key].IndexOf(worker.WorkingOnChar), 1);
                     *  worker.WorkingOnChar = '*';
                     *  isCompleted = false;
                     * }
                     */
                }

                List <Day7Worker> _tmplist = new List <Day7Worker>();
                foreach (var worker in workers)
                {
                    Day7Worker _tmpworker = new Day7Worker(worker);
                    _tmplist.Add(_tmpworker);
                }

                workList.Add(this.Second, _tmplist);

                this.Second++;
            }

            return(this.Second);
        }