Exemplo n.º 1
0
        private static List <IRover> ExtractRoverDataFromInput(string inputFile, IPlanet mars)
        {
            try
            {
                List <IRover> roverDataCollection = new List <IRover>();

                string[] lines = File.ReadAllLines(inputFile);
                RoverController.SetMapGrid(mars, lines[0]);

                for (int counter = 1; counter < lines.Length - 1; counter = counter + 2)
                {
                    Rover rover = RoverController.GetRover(lines[counter], lines[counter + 1]);
                    if (rover != null)
                    {
                        roverDataCollection.Add(rover);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("A rover could not be created. Invalid Raw material: {0} {1}", lines[counter], lines[counter + 1]));
                    }
                }

                return(roverDataCollection);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while processing the input. Please make sure the input file is in correct format." + ex.Message);
                return(null);
            }
        }
Exemplo n.º 2
0
        // TODO: dependency injection

        static void Main(string[] args)
        {
            // The first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates are assumed to be 0, 0.
            Console.WriteLine("Hello to Martian Robot sequence!");
            Console.WriteLine("Please, the file path with then instructions");

            string filepath = Console.ReadLine();

            IPlanet mars = CreatePlanet("Mars");

            List <IRover> rovers = ExtractRoverDataFromInput(filepath, mars);

            if (rovers == null)
            {
                Console.WriteLine("Could not create any rover with provided instructions");
            }

            foreach (IRover rover in rovers)
            {
                Console.WriteLine("----Processing Rover------");
                if (!mars.AddRover(rover))
                {
                    Console.WriteLine("Could not add rover to plateau.");
                }
                else
                {
                    RoverController.ExploreArea(mars, rover);
                }
            }

            Console.Read();
            return;
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            InputManager manager = new InputManager();

            List <string> inputs = new List <string>();
            string        line   = string.Empty;

            Console.WriteLine("New exploration");

            do
            {
                line = Console.ReadLine();

                if (line.Trim() != string.Empty)
                {
                    inputs.Add(line.ToUpper());
                }
                else
                {
                    break;
                }
            } while (line.Trim() != string.Empty);

            List <UserInput> userInputs  = manager.SetInputs(inputs);
            Exploration      exploration = new Exploration(userInputs);

            if (exploration.Rovers.Count > 0)
            {
                RoverController roverController = new RoverController(exploration);
                roverController.ExecuteInstructions();

                foreach (Rover rover in exploration.Rovers)
                {
                    if (exploration.Grid.X < rover.CurrentPosition.X || exploration.Grid.Y < rover.CurrentPosition.Y || rover.CurrentPosition.X < 0 || rover.CurrentPosition.Y < 0)
                    {
                        Console.WriteLine("Rover location unknown!");
                    }
                    else
                    {
                        Console.WriteLine($"{rover.CurrentPosition.X} {rover.CurrentPosition.Y} {rover.CurrentPosition.Z}");
                    }
                }
            }
            else
            {
                Console.WriteLine("No Rovers ready!!");
            }


            if (exploration.Rovers.Count > 0)
            {
            }
        }