private void ConstructAutopilotV2Ride(string line, int index) { string[] splitted = line.Split(' '); Rides tmp = new Rides(splitted[0], splitted[1], splitted[2], splitted[3], splitted[4], splitted[5], index); this.todo.Add(tmp); }
// Return the requied steps for a given car to archive the given ride private int GetRequiredSteps(Car car, Rides ride) { int requiredTravelSteps = Math.Abs(ride.x_start - car.x) + Math.Abs(ride.y_start - car.y); int requiredRideSteps = Math.Abs(ride.x_stop - ride.x_start) + Math.Abs(ride.y_stop - ride.y_stop); if (ride.time_to_start > current_step) { int waitingSteps = (ride.time_to_start - current_step) - requiredTravelSteps; if (waitingSteps > 0) { return(requiredTravelSteps + requiredRideSteps + waitingSteps); } } return(requiredTravelSteps + requiredRideSteps); }
// Get the most optimize ride for the given car private Rides GetBestRide(Car car) { int remainingSteps = step - current_step; Rides bestRide = null; int rideSteps; int bestRideSteps = int.MaxValue; foreach (Rides ride in todo) { rideSteps = GetRequiredSteps(car, ride); if (rideSteps >= remainingSteps || (current_step + rideSteps) >= ride.time_max_to_finish) { continue; } if (rideSteps < bestRideSteps) { bestRideSteps = rideSteps; bestRide = ride; } } return(bestRide); }