private StatusUpdater() { roverStatus = new RoverStatus(); //timer = new System.Timers.Timer(Properties.Settings.Default.StatusUpdateInterval) { Enabled = false }; updatesQueue = new PriorityQueue(100); listener = new MessageListener(Properties.NetworkSettings.Default.StatusUpdatePort, updatesQueue, Properties.NetworkSettings.Default.RoverIPAddress); }
private Rover() { _currentStatus = new RoverStatus { DirectionIndex = 0, Position = new Location { X = 0, Y = 0 } }; }
public MarsRover(Point startingPoint, CardinalDirection startingDirection, Grid map = null, IObstacleDetector obstacleDetector = null) { this._map = map ?? new Grid(); this.ObstacleDetector = obstacleDetector; Status = new RoverStatus(); var normalizedStartingPoint = this._map.NormalizeCoordinates(startingPoint); this.Position = new RoverPosition(normalizedStartingPoint, startingDirection); }
public void MoveBackward() { Position nextPosition = this.Position.GetPositionFacingDirection(this.Direction.GetOpposite()); if (IsObstacleSenseTicklingForTargetPosition(nextPosition)) { this.Status = RoverStatus.StoppedFacingObstacle; return; } this.Position = nextPosition; }
public void Test1() { _controller = new ExplorationController(); var input = new InputModel { SizeX = 5, SizeY = 5, }; RoverCommandsModel command1 = new RoverCommandsModel { DeployLocation = new DeploymentModel { X = 1, Y = 2, Orientation = Orientations.N }, Command = "LMLMLMLMM" }; RoverCommandsModel command2 = new RoverCommandsModel { DeployLocation = new DeploymentModel { X = 3, Y = 3, Orientation = Orientations.E }, Command = "MMRMMRMRRM" }; input.CommandSets = new List <RoverCommandsModel>(); input.CommandSets.Add(command1); input.CommandSets.Add(command2); var output = _controller.ExploreMars(input); Assert.IsType <OkObjectResult>(output.Result); var okObjectResult = output.Result as OkObjectResult; Assert.NotNull(okObjectResult); var outputModel = okObjectResult.Value as OutputModel; Assert.NotNull(outputModel); var expectedResult = new OutputModel(); expectedResult.statutes = new List <RoverStatus>(); var status1 = new RoverStatus { X = 1, Y = 3, orientation = Orientations.N }; var status2 = new RoverStatus { X = 5, Y = 1, orientation = Orientations.E }; expectedResult.statutes.Add(status1); expectedResult.statutes.Add(status2); Assert.Equal(2, outputModel.statutes.Count); expectedResult.Should().BeEquivalentTo(outputModel); }
public Guid CreateARover(YAndXCoordinate startingGridPosition, RoverStatus roverStatus, Direction roverStartDirection) { var result = new Entities.Rover { GridPosition = startingGridPosition, RoverStatus = roverStatus, RoverFacingDirection = roverStartDirection, RoverId = Guid.NewGuid() }; _rovers.Add(result); return(result.RoverId); }
static void Main(string[] args) { string size = string.Empty; string position = string.Empty; string directive = string.Empty; #region size do { Console.Write("Size: "); size = Console.ReadLine().ToUpper(); }while (!Regex.Match(size, "[0-9]* [0-9]*").Success); #endregion while (true) { #region position do { Console.Write("Position: "); position = Console.ReadLine().ToUpper(); }while (!Regex.Match(position, "[0-9]* [0-9]* [NSEW]{1}$").Success); #endregion #region directive do { Console.Write("Directives: "); directive = Console.ReadLine().ToUpper(); }while (!Regex.Match(directive, "[LRM]*").Success); #endregion Rover marsRover = new Rover(int.Parse(GetDataPart(size, 0)), int.Parse(GetDataPart(size, 1))); RoverStatus result = marsRover.Move(int.Parse(GetDataPart(position, 0)), int.Parse(GetDataPart(position, 1)), GetDataPart(position, 2), directive); if (result.IsError) { Console.Write(result.Message); } else { Console.Write($"{result.Position.x} {result.Position.y} {result.Position.direction}"); } Console.WriteLine(); } }
internal void Move(char[] moves) { this.Status.StatusCode = RoverStatus.RoverStatusCode.Ok; try { foreach (char commandChar in moves) { IRoverCommand command = CommandFactory(commandChar); if (command == null) { throw new RoverException($"invalid command character: {command}!"); } RoverPosition newPosition = command.CalcNewPosition(this.Coordinates, this.Direction); var normalizeCoords = _map.NormalizeCoordinates(newPosition.Coordinates); RoverPosition normalizePosition = new RoverPosition(normalizeCoords, newPosition.Direction); if (ObstacleDetector != null && ObstacleDetector.IsObstacleDetected(normalizePosition.Coordinates)) { RoverStatus status = new RoverStatus(RoverStatus.RoverStatusCode.Fail) { StatusMessage = $"obstacle detected at: ({normalizeCoords})", }; this.Status = status; return; //don't move and report error by changing own status } this.Position = normalizePosition; } } catch (RoverException e) { this.Status = new RoverStatus(RoverStatus.RoverStatusCode.Error) { StatusMessage = e.Message }; } }
private void AdjustPosition(RoverStatus status) { if (status.Position.X < 0) { status.Position.X += _grid.GetWidth(); } if (status.Position.X >= _grid.GetWidth()) { status.Position.X -= _grid.GetWidth(); } if (status.Position.Y < 0) { status.Position.Y += _grid.GetHeight(); } if (status.Position.Y >= _grid.GetHeight()) { status.Position.Y -= _grid.GetHeight(); } }
public RoverStatus(RoverStatus other) { DirectionIndex = other.DirectionIndex; Position = new Location { X = other.Position.X, Y = other.Position.Y }; }
private void Step(RoverStatus status, int multiplier) { status.Position.X += CoordianteDirections[status.DirectionIndex].X * multiplier; status.Position.Y += CoordianteDirections[status.DirectionIndex].Y * multiplier; AdjustPosition(status); }
private RoverStatus GetNewStatusForCommand(char command) { var newStatus = new RoverStatus(_currentStatus); if (command == 'F') { Step(newStatus, 1); } if (command == 'B') { Step(newStatus, -1); } if (command == 'R') { newStatus.DirectionIndex = (newStatus.DirectionIndex + 1) % 4; } if (command == 'L') { var newDirIndex = newStatus.DirectionIndex - 1; if (newDirIndex < 0) { newDirIndex += 4; } newStatus.DirectionIndex = newDirIndex; } return newStatus; }
private CommandResponse ExecuteCommand(char command) { var newStatus = GetNewStatusForCommand(command); if (_grid.IsObsctacle(newStatus.Position.X, newStatus.Position.Y)) return CommandResponse.Obstacle; _currentStatus = newStatus; return CommandResponse.OK; }
public Rover() { GridPosition = new YAndXCoordinate(); RoverStatus = RoverStatus.Operational; }
public Rover(int x, int y, Direction direction) { this.Position = new Position(x, y); this.Direction = direction; this.Status = RoverStatus.Operative; }
public void UpdateRoverStatus(Guid roverId, RoverStatus roversStatus) { var rover = _rovers.FirstOrDefault(x => x.RoverId == roverId); rover.RoverStatus = roversStatus; }