public BaseRover(IRoverCommand init, bool debug = false) { Heading = init.Heading; Position = init.Start; Mission = init.Mission; _debug = debug; }
public static void ExecuteRoverCommands(string roverCommands, IRover rover) { foreach (char roverCommand in TrimCommand(roverCommands)) { IRoverCommand command = RoverCommandFactory(roverCommand.ToString()); command?.Execute(rover); } }
public void CommandFactory_InvalidCommand_Null() { //Arrange Point startingPoint = new Point(0, 0); MarsRover.CardinalDirection startingDirection = MarsRover.CardinalDirection.North; MarsRover rover = new MarsRover(startingPoint, startingDirection, null, null); //Act IRoverCommand cmd = rover.CommandFactory('?'); //Assert Assert.IsNull(cmd); }
public RoverInvoker(IRover rover) { _rover = rover; foreach (var ch in rover.CommandParams) { IRoverCommand command = GetCommand(ch); if (command != null) { AddCommand(command); } else { throw new NullReferenceException("Girilen karakter için command tanımlı değil."); } } }
/** * This method is used to fetch respective factory methods. * @param factoryType - factoryType input string * @return IRoverCommand - respective IRoverCommand Object */ public IRoverCommand getFactory(String factoryType) { IRoverCommand command = null; if (factoryType.Equals(RoverConstants.MOVE_AHEAD)) { command = getMoveCommand(); } else if (factoryType.Equals(RoverConstants.ROTATE_LEFT)) { command = getRotateLeftCommand(); } else if (factoryType.Equals(RoverConstants.ROTATE_RIGHT)) { command = getRotateRightCommand(); } return(command); }
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 AddCommand(IRoverCommand c) { _commandList.Enqueue(c); }
public void Get_Null_For_InvalidCommand() { IRoverCommand command = CommandHelper.RoverCommandFactory("X"); Assert.AreSame(null, command); }
public void Get_Turn_Right_For_R() { IRoverCommand command = CommandHelper.RoverCommandFactory("R"); Assert.AreSame(typeof(TurnRight), command.GetType()); }
public void Get_Turn_Left_For_L() { IRoverCommand command = CommandHelper.RoverCommandFactory("L"); Assert.AreSame(typeof(TurnLeft), command.GetType()); }
public void Get_Move_Forward_For_M() { IRoverCommand command = CommandHelper.RoverCommandFactory("M"); Assert.AreSame(typeof(MoveForward), command.GetType()); }
public Worker(IRoverCommand roverCommand) { _roverCommand = roverCommand; }
public static void CreateRoverCommandFrom(string[] input, IRoverFactory roverFactory) { roverCommand = new RoverCommand(input, roverFactory); }
public OptimisticRover(IRoverCommand init, bool debug = false) : base(init, debug) { }