Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                IPlanetSurface mars = new MarsSurface("5 5");
                //Console.WriteLine($"X coord:{mars._width}, Y coord:{mars._height}");

                //IVehicle rover1 = new MarsRover("1 2 N", "LMLMLMLMM", mars);
                //Console.WriteLine(rover1.PrintFinalPositionAndHeading());

                //IVehicle rover2 = new MarsRover("3 3 E", "MMRMMRMRRM", mars);
                //Console.WriteLine(rover2.PrintFinalPositionAndHeading());

                Squad mrSquad = new Squad(mars);

                mrSquad.AddVehicle("1 2 N", "LMLMLMLMM");
                mrSquad.AddVehicle("3 3 E", "MMRMMRMRRM");

                foreach (var marsRover in mrSquad)
                {
                    Console.WriteLine(marsRover.PrintFinalPositionAndHeading());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error occured: {ex.Message.ToString()}");
            }
        }
Ejemplo n.º 2
0
        public void Get_Surface_Size(int x, int y)
        {
            var size            = new Size(x, y);
            var marsSurface     = new MarsSurface(size);
            var marsSurfaceSize = marsSurface.GetSize();

            Assert.Equal(size, marsSurfaceSize);
        }
Ejemplo n.º 3
0
        public void TestMarsRover1()
        {
            //Arrange
            IPlanetSurface mars   = new MarsSurface("5 5");
            IVehicle       rover1 = new MarsRover("1 2 N", "LMLMLMLMM", mars);

            //Act
            string actResult = rover1.PrintFinalPositionAndHeading();

            //Assert
            Assert.Equal("1 3 N", actResult);
        }
Ejemplo n.º 4
0
        public void WidthOrHeightCanNotBeLessZeroThrowException(string command)
        {
            ISurface landingSurface = new MarsSurface();

            var commandSplit = command.Split(' ');
            var width        = int.Parse(commandSplit[0]);
            var height       = int.Parse(commandSplit[1]);

            var action = new Action(() => landingSurface.SetSurface(new SurfaceModel()
            {
                Width  = width,
                Height = height
            }));

            action.Should().Throw <Exception>().WithMessage("width and height can not be less than zero");
        }
Ejemplo n.º 5
0
        public void TestMarsSquad()
        {
            //Arrange
            IPlanetSurface mars    = new MarsSurface("5 5");
            Squad          mrSquad = new Squad(mars);

            mrSquad.AddVehicle("1 2 N", "LMLMLMLMM");
            mrSquad.AddVehicle("3 3 E", "MMRMMRMRRM");

            //Act
            string actResult1 = mrSquad[0].PrintFinalPositionAndHeading();
            string actResult2 = mrSquad[1].PrintFinalPositionAndHeading();

            //Assert
            Assert.Equal("1 3 N", actResult1);
            Assert.Equal("5 1 E", actResult2);
        }
Ejemplo n.º 6
0
        public void CreateSurfaceCorrectSize(string command)
        {
            ISurface landingSurface = new MarsSurface();

            var commandSplit = command.Split(' ');
            var width        = int.Parse(commandSplit[0]);
            var height       = int.Parse(commandSplit[1]);


            landingSurface.SetSurface(new SurfaceModel()
            {
                Width  = width,
                Height = height
            });


            landingSurface.Size.SurfaceModel.Width.Should().Be(width);
            landingSurface.Size.SurfaceModel.Height.Should().Be(height);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Выполняет парсинг строки в поверхность Марса с заданными в строке размерами.
        /// </summary>
        /// <param name="data">Данные для парсинга.</param>
        /// <returns>Поверхность марса <see cref="MarsSurface"/> с указанными размерами.</returns>
        public MarsSurface ParseMarsSurface(string data)
        {
            data = Guard.ArgumentIsNotNullOrWhiteSpace(data, nameof(data));

            var sizes = data
                        .ToUpperInvariant()
                        .Where(char.IsDigit)
                        .Select(_ => _.ToString())
                        .ToArray();

            if (sizes.Length != 2)
            {
                throw new InvalidOperationException("Mars surface sizes must be represent as two digits");
            }

            var xDimensionSize = Convert.ToInt32(sizes[0]);
            var yDimensionSize = Convert.ToInt32(sizes[1]);

            var surface = new MarsSurface(xDimensionSize, yDimensionSize);

            return(surface);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Enter Surface X Coordinate");
            string surfaceX = Console.ReadLine();

            Console.WriteLine("Enter Surface Y Coordinate");
            string   surfaceY = Console.ReadLine();
            Size     size     = new Size(Convert.ToInt32(surfaceX), Convert.ToInt32(surfaceY));
            ISurface surface  = new MarsSurface(size);
            Position position = new Position();

            Console.WriteLine("Enter Rover Landing Position");
            Console.WriteLine("Enter Rover Landing Position X");
            string roverx = Console.ReadLine();

            Console.WriteLine("Enter Rover Landing Position Y");
            string rovery = Console.ReadLine();

            position.Coordinate = new Coordinate(Convert.ToInt32(roverx), Convert.ToInt32(rovery));
            Console.WriteLine("Enter Rover Landing Position");
            Console.WriteLine("North -> 0");
            Console.WriteLine("East ->  1");
            Console.WriteLine("South -> 2");
            Console.WriteLine("West ->  3");
            string direction = Console.ReadLine();

            position.Direction = (Directions)(Convert.ToInt32(direction));
            Core.Rover.MarsRover marsRover = new Core.Rover.MarsRover();
            marsRover.LandingSurface(surface, position);
            Console.WriteLine("Command:");
            string cmmds = Console.ReadLine();

            marsRover.Action(cmmds);
            Console.WriteLine(marsRover.Position.Coordinate.CoordinateX.ToString() + " " + marsRover.Position.Coordinate.CoordinateY.ToString() + " " + marsRover.Position.Direction.ToString());
            Console.ReadLine();
        }
Ejemplo n.º 9
0
        public void HBRequired2(string command)
        {
            var plataue = new MarsSurface();

            plataue.SetSurface(new SurfaceModel()
            {
                Width = 5, Height = 5
            });
            var manager = new RoverManager(plataue);

            manager.LaunchRover(3, 3, Directions.E);
            var movements = command
                            .ToCharArray()
                            .Select(x => Enum.Parse <Movements>(x.ToString()))
                            .ToList();


            movements.ForEach(manager.Rover.Move);

            manager.Rover.Should().NotBeNull();
            manager.Rover.X.Should().Be(5);
            manager.Rover.Y.Should().Be(1);
            manager.Rover.Direction.Should().Be(Directions.E);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Осуществляет выполнение сессии
        /// </summary>
        public void Execute()
        {
            foreach (var operand in Operands)
            {
                var robot             = operand.Key;
                var commandsToExecute = operand.Value;

                foreach (var command in commandsToExecute)
                {
                    var previousPosition = robot.CurrentPosition;

                    robot.ExecuteCommand(command);

                    var newPosition = robot.CurrentPosition;

                    if (!IsOutside(newPosition))
                    {
                        continue;
                    }

                    if (MarsSurface.IsPositionScented(previousPosition))
                    {
                        robot.CurrentPosition = previousPosition;

                        continue;
                    }

                    robot.IsLost          = true;
                    robot.CurrentPosition = previousPosition;

                    MarsSurface.AddScentedPosition(previousPosition);

                    break;
                }
            }
        }
Ejemplo n.º 11
0
 public void Setup()
 {
     _testee = new MarsSurface(new Vector2(5, 3));
 }