예제 #1
0
        static void Main(string[] args)
        {
            Console.Write("Enter plateau size: ");
            var plateauParams           = Console.ReadLine();
            var r1PlateauInstance       = new PlateauGrid(plateauParams);
            var r2PlateauInstance       = new PlateauGrid(plateauParams);
            var rover1CommandsToExecute = new List <string>();
            var rover2CommandsToExecute = new List <string>();

            Console.Write("Enter Rover1 deployment Coords and direction: ");
            rover1CommandsToExecute.Add(Console.ReadLine().ToUpper());
            Console.Write("Enter Rover1 movement instructions: ");
            rover1CommandsToExecute.Add(Console.ReadLine().ToUpper());
            Console.Write("Enter Rover2 deployment Coords and direction: ");
            rover2CommandsToExecute.Add(Console.ReadLine().ToUpper());
            Console.Write("Enter rover2 Movement instructions: ");
            rover2CommandsToExecute.Add(Console.ReadLine().ToUpper());

            var rover1 = new MarsRover(r1PlateauInstance);

            rover1.SetRoverDirection(rover1CommandsToExecute);
            var rover2 = new MarsRover(r2PlateauInstance);

            rover2.SetRoverDirection(rover2CommandsToExecute);
            rover1.ExecuteCommands(rover1CommandsToExecute);
            rover2.ExecuteCommands(rover2CommandsToExecute);
            Console.WriteLine();
            Console.WriteLine($"Current Rover Position Heading: {rover1.CoordinateX} {rover1.CoordinateY} {rover1.Direction.ToString()[0]}");
            Console.WriteLine($"Current Rover Position Heading: {rover2.CoordinateX} {rover2.CoordinateY} {rover2.Direction.ToString()[0]}");
        }
예제 #2
0
        public void When_Rover_Is_Positioned_At_North_And_Turned_Left_The_Direction_Is_West()
        {
            IDirection  direction       = new North();
            Coordinates initialPosition = new Coordinates(1, 2);
            MarsRover   rover           = new MarsRover(plateau, initialPosition, direction);

            rover.ExecuteCommands("L");
            Assert.That(rover.CurrentDirection, Is.TypeOf <West>());
        }
예제 #3
0
        public void When_Moving_East_At_X_Border_Should_Not_Go_Outside_Plateau()
        {
            IDirection  direction       = new East();
            Coordinates initialPosition = new Coordinates(5, 2);
            MarsRover   rover           = new MarsRover(plateau, initialPosition, direction);

            rover.ExecuteCommands("MMMMM");
            Assert.That(rover.CurrentCoordinates.XCoordinate, Is.EqualTo(5));
            Assert.That(rover.CurrentCoordinates.YCoordinate, Is.EqualTo(2));
        }
예제 #4
0
        public void When_Rover_Is_Positioned_At_1_1_N_And_Move_Rover_Will_Be_At_1_2()
        {
            IDirection  direction       = new North();
            Coordinates initialPosition = new Coordinates(1, 1);
            MarsRover   rover           = new MarsRover(plateau, initialPosition, direction);

            rover.ExecuteCommands("M");
            Assert.That(rover.CurrentCoordinates.XCoordinate, Is.EqualTo(1));
            Assert.That(rover.CurrentCoordinates.YCoordinate, Is.EqualTo(2));
        }
예제 #5
0
        public void Rover_ends_on_correct_test_case_on_input2()
        {
            var commands = new List <string> {
                "3 3 E", "MMRMMRMRRM"
            };

            var rover = new MarsRover(_plateau);

            rover.SetRoverDirection(commands);
            rover.ExecuteCommands(commands);
            Assert.That(rover.Direction, Is.TypeOf <East>());
            Assert.That(rover.CoordinateX, Is.EqualTo(5));
            Assert.That(rover.CoordinateY, Is.EqualTo(1));
        }
예제 #6
0
        public void Rover_ends_on_correct_test_case_on_input()
        {
            var commands = new List <string> {
                "1 2 N", "LMLMLMLMM"
            };

            var rover = new MarsRover(_plateau);

            rover.SetRoverDirection(commands);
            rover.ExecuteCommands(commands);
            Assert.That(rover.Direction, Is.TypeOf <North>());
            Assert.That(rover.CoordinateX, Is.EqualTo(1));
            Assert.That(rover.CoordinateY, Is.EqualTo(3));
        }