Esempio n. 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);
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
 public void GoForward()
 {
     CurrentWagon = Train.NextWagon();
     Position++;
     TotalWagonsPassed++;
 }
Esempio n. 4
0
 public void GoBack()
 {
     CurrentWagon = Train.PreviousWagon();
     Position--;
     TotalWagonsPassed++;
 }
Esempio n. 5
0
 public People(Train train)
 {
     Train        = train;
     CurrentWagon = train.NextWagon();
 }