private List<string> BuildDestinationList(int BusLine, string CurrentBusStop,Route Route) { List<string> Destinations = new List<string>(); // add remaining bus stops after route destination include destination string[] AllBusStops = CityMap.Lines[BusLine]; int DestinationPosition = Array.IndexOf(AllBusStops, Route.BusStopA == CurrentBusStop ? Route.BusStopB : Route.BusStopA); var RemainStops = AllBusStops.Skip(DestinationPosition); Destinations.AddRange(RemainStops); return Destinations; }
public static bool Navigate(string From,string To,out Route Result) { Result = new Route(); var result = from r in Routes where (r.BusStopA == From && r.BusStopB == To) || (r.BusStopA == To && r.BusStopB == From) select r; if (result.Count() == 0) return false; Result = result.First(); return true; }
private bool CheckSkippedBusStopsGetOn(int BusLine,string CurrentBusStop,string Skipped, Route Route) { string[] AllBusStops = CityMap.Lines[BusLine]; int DestinationPosition = Array.IndexOf(AllBusStops, Route.BusStopA == CurrentBusStop ? Route.BusStopB : Route.BusStopA) + 1; string[] RemainStops = AllBusStops.Skip(DestinationPosition).ToArray(); bool GetOn = false; BusStop SkippedBusStop = CityMap.BusStops[Skipped]; foreach(var s in RemainStops) { if (SkippedBusStop.Passengers.Keys.ToList().Exists(x => x == s)) { if (SkippedBusStop.Passengers[s].Count != 0) GetOn = true; } } return GetOn; }
private string[] CheckSkippedBusStops(int BusLine,string CurrentBusStop, Route Route) { string[] AllBusStops = CityMap.Lines[BusLine]; int CurrentPosition = Array.IndexOf(AllBusStops, CurrentBusStop)+1; int DestinationPosition = Array.IndexOf(AllBusStops, Route.BusStopA == CurrentBusStop ? Route.BusStopB : Route.BusStopA)+1; int Count = DestinationPosition - CurrentPosition -1; string[] SkippedStops = AllBusStops.Skip(CurrentPosition).Take(Count).ToArray(); return SkippedStops; }