public static void InitializeForProblem1Scenario2AndPrintResults() { Traffic traffic = new Traffic(new List <Weather>() { sunny, windy, rainy }, new List <Vehicle>() { superCar, tuktuk, bike }, new List <Orbit>() { orbit1, orbit2 }); Dictionary <Orbit, int> dict = new Dictionary <Orbit, int>(); dict[orbit1] = 14; dict[orbit2] = 20; traffic.SetCurrentState(windy, dict); List <TrafficResult> results = traffic.GetTimeOfAllVehiclesOnAllOrbits(traffic.ListOfOrbits, traffic.ListOfVehicles.Where(v => v.Weathers.Contains(traffic.CurrentWeather)).ToList()); TrafficResult finalResult = traffic.DeterMineWinner(results); if (finalResult != null) { Console.WriteLine("Orbit {0} in vehicle {1} in {2} mins ", finalResult.Orbit.Name, finalResult.Vehicle.Name, finalResult.TimeForTravel); } else { Console.WriteLine("oops"); } }
public TrafficResult DeterMineWinner(List <TrafficResult> results) { double lowestTimeTaken = results.First().TimeForTravel; List <TrafficResult> finalResults = results.Where(result => result.TimeForTravel == lowestTimeTaken).ToList(); TrafficResult finalResult = null; if (finalResults.Count > 1) { finalResult = finalResults.OrderBy(r => r.Vehicle.Order).ElementAt(0); } else { finalResult = finalResults.Single(); } return(finalResult); }