示例#1
0
        public Train(int countWagons)
        {
            Wagons = new Wagon[countWagons];
            for (int i = 0; i < countWagons; i++)
            {
                Wagons[i] = new Wagon();
            }

            RandomLight();
            Random rnd = new Random();

            currentWagon = rnd.Next(0, CountWagons);
        }
示例#2
0
文件: Program.cs 项目: curs23/Wagons
        static Res Algoritm_2(Train train)
        {
            People people     = new People(train);
            Wagon  startWagon = people.CurrentWagon;

            startWagon.OnLight();
            people.GoBack();
            people.CurrentWagon.OffLight();
            people.GoForward();


            Tuda_2(people);
            while (true)
            {
                if (TudaCheckLightOff(people, people.Position - 2))
                {
                    int potencialCountWagon = (people.Position + 1) / 2;

                    // проверка света стартвого вагона бегом назад
                    while (people.Position != 0)
                    {
                        people.GoBack();
                    }

                    if (people.CurrentWagon.Light)
                    {
                        // не прошла
                        Tuda_2(people);
                    }
                    else
                    {
                        // прошла - вывод результата
                        return(new Res()
                        {
                            CountWagons = potencialCountWagon, TotalWagonsPassed = people.TotalWagonsPassed
                        });
                    }
                }
                else
                {
                    Tuda2_2(people);
                }
            }
        }
示例#3
0
文件: Program.cs 项目: curs23/Wagons
 public void GoForward()
 {
     CurrentWagon = Train.NextWagon();
     Position++;
     TotalWagonsPassed++;
 }
示例#4
0
文件: Program.cs 项目: curs23/Wagons
 public void GoBack()
 {
     CurrentWagon = Train.PreviousWagon();
     Position--;
     TotalWagonsPassed++;
 }
示例#5
0
文件: Program.cs 项目: curs23/Wagons
 public People(Train train)
 {
     Train        = train;
     CurrentWagon = train.NextWagon();
 }