Exemplo n.º 1
0
        public static string GetPosition(RoboticRover roboticRover)
        {
            string roverPosition = string.Format("{0} {1} {2}", roboticRover.XPosition, roboticRover.YPosition, roboticRover.RoboticRoverDirection);

            Console.WriteLine(roverPosition);
            return(roverPosition);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This function will decide Robotic Rover Direction
 /// Example : S(270) - 90 is not less than 90 hence 270-90 = E(180) Rover Movement
 /// </summary>
 /// <param name="roboticRover"></param>
 /// <param name="direction"></param>
 public static void ChangeDirection(this RoboticRover roboticRover, char direction)
 {
     if (direction == 'L')
     {
         roboticRover.RoboticRoverDirection = (roboticRover.RoboticRoverDirection - 90) < Directions.Direction.N ? Directions.Direction.W : roboticRover.RoboticRoverDirection - 90;
     }
     else if (direction == 'R')
     {
         roboticRover.RoboticRoverDirection = (roboticRover.RoboticRoverDirection + 90) > Directions.Direction.W ? Directions.Direction.N : roboticRover.RoboticRoverDirection + 90;
     }
 }
Exemplo n.º 3
0
        public static void Direct(RoboticRover roboticRover, string inputDirections)
        {
            char[] directions = inputDirections.ToCharArray();

            foreach (char direction in directions)
            {
                if (direction == 'L' || direction == 'R')
                {
                    roboticRover.ChangeDirection(direction);
                }
                else if (direction == 'M')
                {
                    roboticRover.Move();
                }
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            try
            {
                Console.WriteLine("Enter Number of Rover");
                int RoverCount = Convert.ToInt16(Console.ReadLine());

                Console.WriteLine("Enter X Y maximum Coordinate of Plateu ");
                var plateau = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToList();

                for (int i = 0; i < RoverCount; i++)
                {
                    Console.WriteLine("Enter Starting Point Direction Ex- 1 2 N for the Rover " + (i + 1));
                    var startingPoint = Console.ReadLine().Trim().Split(' ');
                    //rover coordinates not greater than plateau
                    if (Convert.ToInt32(startingPoint[0]) > Convert.ToInt32(plateau[0]) || Convert.ToInt32(startingPoint[1]) > Convert.ToInt32(plateau[1]))
                    {
                        Console.WriteLine("Please enter valid Input");
                        Console.ReadLine();
                        break;
                    }
                    if (startingPoint.Count() == 3)
                    {
                        SetDirection(Convert.ToString(startingPoint[2].ToUpper()));
                    }
                    else
                    {
                        Console.WriteLine("Please enter valid Input");
                        Console.ReadLine();
                        break;
                    }
                    RoboticRover firstRoboticRover = new RoboticRover(Convert.ToInt16(startingPoint[0]), Convert.ToInt16(startingPoint[1]), direction, new Plateau(plateau[0], plateau[1]));
                    Console.WriteLine("Enter series of instructions to rover for how to explore Plateau Ex- LMLMLMLMM ");
                    var Instruction = Console.ReadLine().Trim();
                    DirectRoboticRover.Direct(firstRoboticRover, Instruction);
                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine("Output for Rover " + (i + 1));
                    GetRoboticRoverPosition.GetPosition(firstRoboticRover);
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Move X and Y for calculated direction
 /// For North and South -- Rover will move for Y direction
 /// For East and West -- Rover will move for X direction
 /// </summary>
 /// <param name="roboticRover"></param>
 public static void Move(this RoboticRover roboticRover)
 {
     if (roboticRover.RoboticRoverDirection == Directions.Direction.N && roboticRover.Plateau.Y >= roboticRover.YPosition)
     {
         roboticRover.YPosition++;
     }
     else if (roboticRover.RoboticRoverDirection == Directions.Direction.E && roboticRover.Plateau.X >= roboticRover.XPosition)
     {
         roboticRover.XPosition++;
     }
     else if (roboticRover.RoboticRoverDirection == Directions.Direction.S && roboticRover.YPosition >= 0)
     {
         roboticRover.YPosition--;
     }
     else if (roboticRover.RoboticRoverDirection == Directions.Direction.W && roboticRover.XPosition >= 0)
     {
         roboticRover.XPosition--;
     }
 }