示例#1
0
        /// <summary>
        /// Move the rover according to instructions, verifying the move is within the grid boundaries
        /// </summary>
        /// <param name="rover"></param>
        /// <param name="roverInstructions"></param>
        /// <returns></returns>
        private string ProcessRoverInstruction(IRover rover, string roverInstructions)
        {
            foreach (var move in roverInstructions.ToUpperInvariant())
            {
                switch (move)
                {
                case 'L':
                    _roverService.RotateRoverLeft(rover);
                    break;

                case 'R':
                    _roverService.RotateRoverRight(rover);
                    break;

                case 'M':
                    if (IsMovingWithinBoundaries(rover))
                    {
                        _roverService.MoveRoverForward(rover);
                    }
                    else
                    {
                        throw new OutOfBoundariesException($"Rover stepping out of the grid.");
                    }
                    break;

                default:
                    // todo:?
                    break;
                }
            }

            return(GetRoverPositionAndHeadingString(rover));
        }