static void Main(string[] args) { string input = @"5 5 1 2 N LMLMLMLMM 3 3 E MMRMMRMRRM "; RoverLogic logic = new RoverLogic(); logic.MainLogic(input); }
public void MainLogic(string input) { /* * It is the main function that controls all the * operations that Rover will perform on Mars. It * runs all intermediate functions within it. * These functions are; * * 1. Separating the input into lines. * * 2. Convert the non-numerical values in the first * row to numerical values and create the limits. * * 3. Converting incoming non-numerical rover coordinates * to numerical rover coordinates. (Using Direction enum) * * 4. Calculating the target point and * checking whether the limit is exceeded in this process. * * 5. Converting the calculated target * point back to non-numeric output as desired. * * 6. To do all the above functions in a loop. * */ string[] inputArray = input.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var border = CreateBorder(inputArray[0]); for (int i = 1; i < inputArray.Length / 2 + 1; i++) { RoverLogic logic = new RoverLogic(); Rover rover = new Rover(); int[] coordinates = ConvertToCoordinates(inputArray[i * 2 - 1]); int[] result = { 0, 0, 0 }; rover.Coordinates = coordinates; rover.Directions = inputArray[i * 2]; result = logic.GetRoute(rover.Coordinates, rover.Directions, border); Console.WriteLine(ConvertToResult(result)); } }