/// <summary>
 /// Konumlanma koordinatlarının platoya göre kontrolü
 /// </summary>
 /// <param name="plateau"></param>
 /// <param name="deploymentPoint"></param>
 private void CheckDeploymentPoint(PlateauModel plateau, DeploymentPointModel deploymentPoint)
 {
     if (plateau.Width < deploymentPoint.X || plateau.Height < deploymentPoint.Y || deploymentPoint.X < 0 || deploymentPoint.Y < 0)
     {
         throw new OutOfBoundsFromPlateauException("Rover can't located on plateau.");
     }
 }
Beispiel #2
0
        public bool Move(PlateauModel plateau, RoverModel rover)
        {
            if (!CanItMove(plateau, rover))
            {
                return(false);
            }

            switch (rover.Direction)
            {
            case DirectionEnum.N:
                rover.CurrentYCoordinate += 1;
                break;

            case DirectionEnum.E:
                rover.CurrentXCoordinate += 1;
                break;

            case DirectionEnum.S:
                rover.CurrentYCoordinate -= 1;
                break;

            case DirectionEnum.W:
                rover.CurrentXCoordinate -= 1;
                break;
            }

            return(true);
        }
Beispiel #3
0
 private bool MoveCheck(PlateauModel plateau, RoverModel rover)
 {
     return((rover.XCoord >= 0) &&
            (rover.XCoord <= plateau.Width) &&
            (rover.YCoord >= 0) &&
            (rover.YCoord <= plateau.Height));
 }
        /// <summary>
        /// İstenilen yönüne göre hareket eylemine yönlendirir.
        /// </summary>
        /// <param name="rover"></param>
        /// <param name="plateau"></param>
        /// <returns></returns>
        private RoverModel Move(RoverModel rover, PlateauModel plateau)
        {
            foreach (var movingDirection in rover.Movement.MovementList)
            {
                switch (movingDirection)
                {
                case MovementAbility.L:
                    MoveLeft(rover);
                    break;

                case MovementAbility.R:
                    MoveRight(rover);
                    break;

                case MovementAbility.M:
                    MoveStraight(rover, plateau);
                    break;

                default:
                    throw new InvalidMovementAbilityParamException("Invalid moving key for rover");
                }
            }

            return(rover);
        }
Beispiel #5
0
        public void CalculateRoverMovement_Success_TaskInput2(string calculationCommand)
        {
            // Arrange
            var plataue = new PlateauModel(5, 5);
            //Act
            var rover = _roverService.SetRoverOnPlateau(plataue, new DeploymentPointModel(Direction.E.ToString())
            {
                X = 3,
                Y = 3
            });
            var movements = calculationCommand
                            .ToCharArray()
                            .Select(x => Enum.Parse <MovementAbility>(x.ToString()))
                            .ToList();

            rover.Movement.MovementList = movements;
            _roverService.CalculateRoverMovement(rover, plataue);

            //Assert
            Assert.NotNull(plataue);
            Assert.NotNull(rover.Movement.MovementList);
            Assert.Equal(5, rover.DeploymentPoint.X);
            Assert.Equal(1, rover.DeploymentPoint.Y);
            Assert.Equal(Direction.E, rover.DeploymentPoint.Direction);
        }
Beispiel #6
0
        private static bool IsValid(RoverPositionModel roverPositionModel, PlateauModel plateauModel)
        {
            var isValidX = roverPositionModel.X >= 0 && roverPositionModel.X <= plateauModel.Width;
            var isValidY = roverPositionModel.Y >= 0 && roverPositionModel.Y <= plateauModel.Height;

            return(isValidX && isValidY);
        }
Beispiel #7
0
        public async Task GivenTheCommandIsValidWhenMoveRoverIsCalledThenRoverPositionIsChanged(string command)
        {
            //Arrange
            var arrangedPosition = new PositionModel
            {
                XPos      = 3,
                YPos      = 3,
                Direction = Model.Enums.Direction.N
            };
            var plateauModel = new PlateauModel
            {
                Height = 5,
                Width  = 5
            };
            var expectedPosition = new PositionModel
            {
                XPos      = 2,
                YPos      = 3,
                Direction = Model.Enums.Direction.S
            };
            var roverMovementService = new RoverMovementService(plateauService);

            //Act
            var response = await roverMovementService.MoveRover(command, arrangedPosition, plateauModel);

            //Assert
            Assert.AreEqual(expectedPosition.XPos, response.XPos);
            Assert.AreEqual(expectedPosition.YPos, response.YPos);
            Assert.AreEqual(expectedPosition.Direction, response.Direction);
        }
Beispiel #8
0
 /// <summary>
 /// Plateau and Coord control function
 /// </summary>
 /// <param name="plateauInput"></param>
 /// <returns>true: OK ,false : Coordinate Error </returns>
 private bool PlateauCoordControl(PlateauModel plateauInput)
 {
     if (XCoord < 0 || XCoord > plateauInput.Width || YCoord < 0 || YCoord > plateauInput.Height)
     {
         return(false);
     }
     return(true);
 }
 /// <summary>
 /// Gezicinin plato üzerinde hareketini hesaplar.
 /// </summary>
 /// <param name="rover"></param>
 /// <param name="plateau"></param>
 /// <returns></returns>
 public RoverModel CalculateRoverMovement(RoverModel rover, PlateauModel plateau)
 {
     if (rover == null)
     {
         throw new BadRequestException("Please check your requested Rover Model.");
     }
     return(Move(rover, plateau));
 }
Beispiel #10
0
 public string CalculatePosition(PlateauModel plateau, RoverModel rover, string order)
 {
     for (int i = 0; i < order.Length; i++)
     {
         rover = Execute(plateau, rover, order[i]);
     }
     return($"{rover.XCoord} {rover.YCoord} {rover.Direction}");
 }
Beispiel #11
0
        public void DrawPlateau_InvalidRangeException_WhenPointsIsNull(int width, int height)
        {
            // Act
            var plataeu = new PlateauModel(width, height);
            var action  = new Action(() => _plateauService.DrawPlateau(plataeu));

            // Assert
            Assert.Throws <InvalidParameterOfPlateauException>(action);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Mission started.");

            // create service collection
            RegisterServices();

            var roverService = _serviceProvider.GetService <IRoverService>();

            bool IsContinue;

            Console.WriteLine("Please enter the upper-right coordinates of the plateau.(Format=X Y)");
            Console.WriteLine("Info: Consider that the lower-left coordinates are assumed to be 0,0");
            string upperRightCoordinates = Console.ReadLine();
            var    _plateauCoordinates   = upperRightCoordinates.Split(" ");

            do
            {
                Console.WriteLine("Please enter the current coordinates and direction(N/E/S/W). (Format=X Y D)");
                string currentCoordinates  = Console.ReadLine();
                var    _currentCoordinates = currentCoordinates.Split(" ");
                Enum.TryParse(_currentCoordinates[2], out DirectionEnum _direction);

                Console.WriteLine("Please enter the your intsructions. (L=left, R=right, M=Move)");
                string command = Console.ReadLine();

                var plateau = new PlateauModel(Convert.ToInt32(_plateauCoordinates[0]), Convert.ToInt32(_plateauCoordinates[1]));
                var rover   = new RoverModel(Convert.ToInt32(_currentCoordinates[0]), Convert.ToInt32(_currentCoordinates[1]), _direction, command);

                var response = roverService.Run(plateau, rover);

                if (!response.HasError)
                {
                    Console.WriteLine($"Current location info: {response.Data.CurrentXCoordinate} {response.Data.CurrentYCoordinate} {response.Data.Direction}");

                    Console.WriteLine("Do you want to move new rover? (Y/N)");
                    string moveNewRover = Console.ReadLine();

                    if (moveNewRover.ToUpper() == "Y")
                    {
                        IsContinue = true;
                    }
                    else
                    {
                        IsContinue = false;
                    }
                }
                else
                {
                    Console.WriteLine($"{response.Errors}");
                    IsContinue = false;
                }
            } while (IsContinue);

            Console.WriteLine("Mission completed.");
            DisposeServices();
        }
        /// <summary>
        /// Platonun oluşturulmasını sağlar.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public PlateauModel DrawPlateau(PlateauModel model)
        {
            if (model.Width == 0 || model.Height == 0)
            {
                throw new InvalidParameterOfPlateauException("Invalid parameters for drawing plataeu area");
            }

            return(model);
        }
 /// <summary>
 /// Gezicinin plato üzerine konumlanmasını sağlar.
 /// </summary>
 /// <param name="plateau"></param>
 /// <param name="deploymentPoint"></param>
 /// <returns></returns>
 public RoverModel SetRoverOnPlateau(PlateauModel plateau, DeploymentPointModel deploymentPoint)
 {
     CheckDeploymentPoint(plateau, deploymentPoint);
     CheckDirection(deploymentPoint.Direction);
     return(new RoverModel()
     {
         DeploymentPoint = deploymentPoint
     });
 }
Beispiel #15
0
        public void DrawPlateau_Success_WhenCorrectParams(int width, int height)
        {
            // Act
            var plataeu = new PlateauModel(width, height);

            //Assert
            Assert.Equal(plataeu.Width, width);
            Assert.Equal(plataeu.Height, height);
        }
Beispiel #16
0
        public static PlateauModel ParsePlateauOrigin()
        {
            var plateuOrigin = ParseWithSpace(allCommandsLine[0]);
            var response     = new PlateauModel();
            var origins      = ConvertOrigin(plateuOrigin);

            response.PlateauMaxX = origins.Item1;
            response.PlateauMaxY = origins.Item2;
            return(response);
        }
Beispiel #17
0
        public bool IsRoverInsidePlateau(RoverPositionModel roverPosition, PlateauModel plateau)
        {
            bool isInside = false;

            if (roverPosition.X < plateau.X || roverPosition.Y < plateau.Y)
            {
                isInside = true;
            }
            return(isInside);
        }
        public PlateauService(string command)
        {
            if (_plateauModel == null)
            {
                _plateauModel = new PlateauModel();
            }

            _plateauModel.Width  = Convert.ToInt32(command.Split(" ")[0]) > 0 ? Convert.ToInt32(command.Split(" ")[0]) : throw new Exception();
            _plateauModel.Height = Convert.ToInt32(command.Split(" ")[1]) > 0 ? Convert.ToInt32(command.Split(" ")[1]) : throw new Exception();
        }
Beispiel #19
0
        public void RoverFinalPosition_ShouldReturnExpectedValue_WhenInstructionsAreSet()
        {
            PlateauModel plateau            = new PlateauModel(5, 5);
            RoverModel   rover              = new RoverModel(1, 2, "N");
            string       order              = "LMLMLMLMM";
            var          roverActionService = new RoverActionService();

            var actual = roverActionService.CalculatePosition(plateau, rover, order);

            Assert.Equal("1 3 N", actual);
        }
Beispiel #20
0
        private static void GetInputsForPlateau(PlateauModel plateaus, IManager manager)
        {
            do
            {
                manager.PreparePlateau(plateaus);

                if (plateaus.ErrorTracer != null)
                {
                    Console.WriteLine(plateaus.ErrorTracer);
                }
            } while (plateaus.ErrorTracer != null);
        }
Beispiel #21
0
        public void SendToPlateau(LandBase plateau)
        {
            var readonlyDictionary = plateau.Rovers.ToDictionary(rover => rover.Id, rover => new KeyValuePair <int, int>(rover.Point.XPosition, rover.Point.YPosition));

            Plateau   = PlateauModel.CreateNew(readonlyDictionary, plateau.Size, plateau.Id, plateau.Name);
            PlateauId = Plateau.PlateauId;

            if (!Plateau.IsValidPoint(Point))
            {
                throw new InvalidPositionException();
            }
        }
Beispiel #22
0
        public void Setup()
        {
            var fix = new PlateauModel
            {
                Height = 5,
                Width  = 5
            };
            var mockPlateauService = new Mock <IPlateauService>();

            mockPlateauService.Setup(x => x.GetPlateau()).Returns(fix);
            plateauService = mockPlateauService.Object;
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            #region Parameters

            var plateau = new PlateauModel();
            plateau.LowerLeft  = 5;
            plateau.UpperRight = 5;

            var rover1 = new RoverModel
            {
                X         = 1,
                Y         = 2,
                Direction = 'N',
                Movement  = "LMLMLMLMM",
                Plateau   = plateau
            };

            var rover2 = new RoverModel
            {
                X         = 3,
                Y         = 3,
                Direction = 'E',
                Movement  = "MMRMMRMRRM",
                Plateau   = plateau
            };
            #endregion

            Queue <RoverModel> myQueue = new Queue <RoverModel>();
            myQueue.Enqueue(rover1);
            myQueue.Enqueue(rover2);

            Manager manager = new Manager();

            GetInputsForPlateau(plateau, manager);
            manager.PreparePlateau(plateau);

            string roverStatus = "";

            int i = 1;
            while (myQueue.Count > 0)
            {
                var rover = myQueue.Dequeue();
                GetInputsForRover(rover, manager, plateau, i);
                roverStatus += manager.GetRoverStatus();

                i++;
            }

            Console.WriteLine(roverStatus);

            Console.ReadLine();
        }
        public Task <string> Handle(CalculateFinalPositionCommand request, CancellationToken cancellationToken)
        {
            var plateauCoordinates = request.PlateauCoordinates.Split(" ").ToList();
            var roverPosition      = request.RoverPosition.Split(" ").ToList();

            PlateauModel plateau = new PlateauModel(Convert.ToInt32(plateauCoordinates[0]), Convert.ToInt32(plateauCoordinates[1]));
            RoverModel   rover   = new RoverModel(Convert.ToInt32(roverPosition[0]), Convert.ToInt32(roverPosition[1]), roverPosition[2]);

            return(Task.Run(() =>
            {
                return _roverActionService.CalculatePosition(plateau, rover, request.RoverOrder);
            }));
        }
Beispiel #25
0
        public void Create_Zero_Plateau()
        {
            var model = new PlateauModel();

            model.LowerLeft  = 0;
            model.UpperRight = 0;

            _manager.PreparePlateau(model);
            var result         = _manager.PlateausInstance.ErrorMessage;
            var exceptedResult = MessageConstant.PlateauLimitsFail;

            Assert.Equal(exceptedResult, result);
        }
Beispiel #26
0
        public void Create_Valid_Plateau()
        {
            var model = new PlateauModel();

            model.LowerLeft  = 10;
            model.UpperRight = 5;

            _manager.PreparePlateau(model);

            var result = model.ErrorTracer;

            Assert.Null(result);
        }
Beispiel #27
0
        private static void GetInputsForRover(RoverModel rover, IManager manager, PlateauModel plateaus, int i)
        {
            do
            {
                manager.PrepareRover(rover);

                if (rover.ErrorTracer != null)
                {
                    Console.WriteLine(rover.ErrorTracer);
                }
            } while (rover.ErrorTracer != null);

            GetInputForPath(rover, manager);
        }
Beispiel #28
0
        public void Create_Invalid_Plateau()
        {
            var model = new PlateauModel();

            model.LowerLeft  = -1;
            model.UpperRight = -1;

            _manager.PreparePlateau(model);

            var result         = model.ErrorTracer;
            var exceptedResult = MessageConstant.PlateauLimitsFail;

            Assert.NotEqual(exceptedResult, result);
        }
Beispiel #29
0
        public void SetRoverOnPlateau_InvalidDirectionException_WhenDirectionIsInvalid(int expectedX, int expectedY, string expectedDirection)
        {
            // Arrange
            var plataue = new PlateauModel(10, 10);

            // Act
            var action = new Action(() => _roverService.SetRoverOnPlateau(plataue, new DeploymentPointModel(expectedDirection)
            {
                X = expectedX,
                Y = expectedY
            }));

            // Assert
            Assert.Throws <InvalidDirectionException>(action);
        }
Beispiel #30
0
        public void PreparePlateau(PlateauModel model)
        {
            if (model.ErrorTracer == null)
            {
                _plateaus = Plateau.CreatePlateau(this);

                if (model.UpperRight <= 0 && model.LowerLeft <= 0)
                {
                    _plateaus.ErrorMessage = MessageConstant.PlateauLimitsFail;
                }

                _plateaus.LowerLeft  = model.LowerLeft;
                _plateaus.UpperRight = model.UpperRight;
            }
        }