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