public RoverController(Stream stream) { using (var reader = new StreamReader(stream)) { var firstLine = reader.ReadLine(); plateau = plateauParser.Parse(firstLine); while (!reader.EndOfStream) { var roverPositionLine = reader.ReadLine(); var roverPosition = roverParser.Parse(roverPositionLine); var roverCommandsLine = reader.ReadLine(); var commands = commandParser.Parse(roverCommandsLine); var rover = new Rover(plateau, roverPosition.Coordinate, roverPosition.Direction); foreach (var command in commands) { command.Execute(rover); } rovers.Add(rover); } } }
public void RoverReadCommandsTest() { Plateau plateau = new Plateau(5,5); Rover rover = new Rover(1, 2, "N", plateau); String expected = "N"; Assert.AreEqual(expected, rover.ReadCommands("LLLL")); }
static void Main(string[] args) { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(1, 2, "N", plateau); Rover rover2 = new Rover(3, 3, "E", plateau); rover.ReadCommands("LMLMLMLMM"); rover2.ReadCommands("MMRMMRMRRM"); Console.WriteLine(rover.toString()); Console.WriteLine(rover2.toString()); }
private static void Main() { while (true) { Console.WriteLine("Enter platue dimensions. First digit is width, second is height. Example :'5 5'"); var readLine = Console.ReadLine(); if (readLine != null) { if (readLine == "Exit") return; var platueDimensions = readLine.Trim().Split(' '); if (platueDimensions.Length == 2) { int x; int y; var isXNumeric = int.TryParse(platueDimensions[0], out x); var isYNumeric = int.TryParse(platueDimensions[1], out y); if (isXNumeric && isYNumeric && x > 0 && y > 0) { var plateau = new Plateau(x, y); Console.WriteLine("Enter first rover starting coordinates and orientation. Example :'1 2 N'"); readLine = Console.ReadLine(); var rover1 = CreateRover(readLine, plateau, "Curiosity"); if (rover1 == null) continue; Console.WriteLine("Enter first rover commands. Example : 'LRMRMMMLRM"); var rover1Commands = Console.ReadLine(); Console.WriteLine("Enter second rover starting coordinates and orientation. Example :'1 2 N'"); readLine = Console.ReadLine(); var rover2 = CreateRover(readLine, plateau, "Oppurtunity"); Console.WriteLine("Enter second rover commands. Example : 'LRMRMMMLRM"); var rover2Commands = Console.ReadLine(); if (rover2 == null) continue; Console.WriteLine(rover1.ComModule.ProcessMessage(rover1Commands)); Console.WriteLine(rover2.ComModule.ProcessMessage(rover2Commands)); } else { Console.WriteLine("Enter digits for dimensions"); } } else { Console.WriteLine("Command not valid"); } } else { Console.WriteLine("Command not valid"); } } }
public void RoverConstructorTest() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(1, 2, "N", plateau); int expected = 1; Assert.AreEqual(expected, rover.PlateauX); expected = 2; Assert.AreEqual(expected, rover.PlateauY); String expected2 = "N"; Assert.AreEqual(expected2, rover.Direction); }
static void Main() { Plateau plateau = PlateauParameters.PlateauCreator(); Rover rover1 = RoverParameters.RoverCreator(plateau); rover1.Command(Command.ReturnCommand()); Rover rover2 = RoverParameters.RoverCreator(plateau); rover2.Command(Command.ReturnCommand()); rover1.Position(); rover2.Position(); Console.ReadKey(); }
public RoverBase(Plateau plateau, string baseLocation, string name) { if (plateau == null) throw new ArgumentNullException("plateau"); if (string.IsNullOrEmpty(baseLocation)) throw new ArgumentNullException("baseLocation"); Plateau = plateau; Name = name; this.SetBaseLocation(baseLocation); }
public void RoverReadCommandsTestWithMove() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(1, 2, "N", plateau); int expectedX = 1; int expectedY = 3; String expected = "N"; rover.ReadCommands("LMLMLMLMM"); Assert.AreEqual(expected, rover.Direction); Assert.AreEqual(expectedX, rover.PlateauX); Assert.AreEqual(expectedY, rover.PlateauY); }
static void Main(string[] args) { Plateau p = getPlateau(); Rover rover1 = getRover(); getInstructions(p, rover1); Rover rover2 = getRover(); getInstructions(p, rover2); rover1.ShowStatus(); rover2.ShowStatus(); Console.ReadKey(); }
public RoverManager(Plateau plateau, List <string> inputPositions, List <string> inputManoeuvres) { Plateau = plateau; Rovers = inputPositions.Select(position => { var x = position.Split(" "); return(new Rover(Convert.ToInt32(x[0]), Convert.ToInt32(x[1]), x[2])); }).ToList(); InputManoeuvres = inputManoeuvres; FinalPositions = new List <Coordinate>(); }
private static RoverCuriosity ReadRover(Plateau plateau) { var roverInput = Console.ReadLine().Split(' '); var x = Convert.ToInt32(roverInput[0]); var y = Convert.ToInt32(roverInput[1]); var compassDirection = roverInput[2][0]; var rover = new RoverCuriosity(x, y, compassDirection, plateau) { MoveList = Console.ReadLine() }; return(rover); }
public void RoverReadCommandsTestWithAnotherRover() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(3,3,"E",plateau); rover.ReadCommands("MMRMMRMRRM"); int expectedX = 5; int expectedY = 5; String expected = "E"; Assert.AreEqual(expected, rover.Direction); Assert.AreEqual(expectedX, rover.PlateauX); Assert.AreEqual(expectedY, rover.PlateauY); }
static void Main(string[] args) { #region Platanun konumunun alınması char[] plateauInformations = Console.ReadLine().ToCharArray(); //Beklenen input formatı: 55 Plateau plateau1 = new Plateau() { CoordinatX = int.Parse(plateauInformations[0].ToString()), CoordinatY = int.Parse(plateauInformations[1].ToString()) }; #endregion #region Rover 1 //Rover 1 string[] rover1Informations = Console.ReadLine().Split(' '); // Beklenen input formatı : 1 2 N Rover rover1 = new Rover() { CoordinateX = int.Parse(rover1Informations[0]), CoordinateY = int.Parse(rover1Informations[1]), Direction = char.Parse(rover1Informations[2]) }; //Instructions for rover 1 Beklenen input formatı : LMLMLMLMM string rover1Instructions = Console.ReadLine(); Helper.Helper.SendRoverInstructions(rover1, plateau1, rover1Instructions); #endregion #region Rover 2 string[] rover2Informations = Console.ReadLine().Split(' '); // Beklenen input formatı : 3 3 E Rover rover2 = new Rover() { CoordinateX = int.Parse(rover2Informations[0]), CoordinateY = int.Parse(rover2Informations[1]), Direction = char.Parse(rover2Informations[2]) }; //Instructions for rover 2 Beklenen input formatı : MMRMMRMRRM string rover2Instructions = Console.ReadLine(); Helper.Helper.SendRoverInstructions(rover2, plateau1, rover2Instructions); #endregion #region roverların son pozisyonlarını ekrana yazdırma kısmı Helper.Helper.PrintRoverPosition(rover1); Helper.Helper.PrintRoverPosition(rover2); Console.ReadLine(); #endregion }
static void Main(string[] args) { string testInput = "Test Input:\n5 5\n1 2 N\nLMLMLMLMM\n3 3E\nMMRMMRMRRM\n"; Console.WriteLine(testInput); Plateau plateau = new Plateau(new Position(5, 5)); Rover first = new Rover(plateau, new Position(1, 2), Commands.N); var firstOutput = first.Start("LMLMLMLMM"); Rover second = new Rover(plateau, new Position(3, 3), Commands.E); var secondOutput = second.Start("MMRMMRMRRM"); string expectedOutput = "Expected Output:\n" + firstOutput + "\n" + secondOutput; Console.WriteLine(expectedOutput); Console.ReadLine(); }
/// <summary> /// Creates the instance of plateau of a particular size. /// </summary> /// <param name="width">Width of the plateau</param> /// <param name="height">Height of the plateau</param> /// <returns></returns> internal static Plateau FormSize(int width, int height) { if (width < 1 || height < 1) throw new ArgumentException("Plateau width/height should be greater than zero"); // Check if the instance already exists. // If it does not create an instance of Plateau if (_instance == null) _instance = new Plateau(); // Max bounds of the Plateau _instance.Size = new Point(width, height); return _instance; }
public IPlateau ParsePlateau(IList <string> parsedFile, int startingX, int startingY, int graphicsScale, Color color) { var plateuSizes = parsedFile[0].Split(' '); if (plateuSizes.Length > 3 || plateuSizes[0] != plateuSizes[1]) { throw new Exception("InvalidFile - Plateu must have two values that are the same."); } var size = Int32.Parse(plateuSizes[0]) * graphicsScale; IPlateau plateu = new Plateau(startingX, startingY, size, color); return(plateu); }
static void Main(string[] args) { int[] dimensions = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray(); var upperRight = new Position(dimensions[0], dimensions[1]); Plateau plateau = new Plateau(upperRight); string[] initialPosition = Console.ReadLine().Split(" "); int x = int.Parse(initialPosition[0]); int y = int.Parse(initialPosition[1]); Direction orientation = Enum.Parse <Direction>(initialPosition[2]); Rover rover = new Rover(new Position(x, y), orientation); string commands = Console.ReadLine(); System.Console.WriteLine(rover.Explore(commands)); }
static void Main(string[] args) { IRoverService roverService = new RoverService(); Plateau plateau = new Plateau(5, 5); Coordinates coordinates = new Coordinates(2, 0); Rover rover = new Rover(plateau, Domain.Enum.Direction.South, coordinates); roverService.ApplyCommand(rover, "MLLM"); Console.WriteLine(rover.coordinates.xCoordinate + " " + rover.coordinates.yCoordinate + " " + rover.direction); coordinates = new Coordinates(3, 3); rover = new Rover(plateau, Domain.Enum.Direction.East, coordinates); roverService.ApplyCommand(rover, "MMRMMRMRRM"); Console.WriteLine(rover.coordinates.xCoordinate + " " + rover.coordinates.yCoordinate + " " + rover.direction); }
static void Main(string[] args) { Console.WriteLine("Test Input:"); var upperRight = "5 5"; //rover1 var position1 = "1 2 N"; var command1 = "LMLMLMLMM"; //rover2 var position2 = "3 3 E"; // var command2 = "MMRMMRMRRM"; var command2 = "LLLLMR"; Console.WriteLine(upperRight + "\n" + position1 + "\n" + command1 + "\n" + position2 + "\n" + command2); new CoordinateValidation(upperRight).IsValid(); var upperRightValues = upperRight.Split(" "); var plateau = new Plateau { Width = int.Parse(upperRightValues[0]), Height = int.Parse(upperRightValues[1]), Rovers = new List <Rover>() }; //rover1 new PositionValidation(position1, plateau.Width, plateau.Height).IsValid(); var positionValues1 = position1.Split(" "); var rover1 = new Rover(int.Parse(positionValues1[0]), int.Parse(positionValues1[1]), (Direction)Enum.Parse(typeof(Direction), positionValues1[2])); new CommandValidation(command1).IsValid(); rover1.Execute(command1, plateau); plateau.Rovers.Add(rover1); //rover2 new PositionValidation(position2, plateau.Width, plateau.Height).IsValid(); var positionValues2 = position2.Split(" "); var rover2 = new Rover(int.Parse(positionValues2[0]), int.Parse(positionValues2[1]), (Direction)Enum.Parse(typeof(Direction), positionValues2[2])); new CommandValidation(command2).IsValid(); rover2.Execute(command2, plateau); plateau.Rovers.Add(rover2); Console.WriteLine("Output:"); foreach (var item in plateau.Rovers) { Console.WriteLine(item.PointX + " " + item.PointY + " " + item.Direction); } }
public static async Task ReadFileAndMoveRoversAsync(string path, string planetName) { if (File.Exists(path)) { TextReader input = File.OpenText(path); int lineCounter = 0; Plateau PlateauOnMars = new Plateau(); for (string line; (line = input.ReadLine()) != null; lineCounter++) { string[] variables = line.Split(' '); if (lineCounter == 0) { // If it is first line // Create Plateau int XMax = int.Parse(variables[0]); int YMax = int.Parse(variables[1]); PlateauOnMars = new Plateau(XMax, YMax, planetName); continue; } if (IsEven(lineCounter)) { // If the line count is even // It is movement instruction for rover int RoverID = PlateauOnMars.RoverCount - 1; PlateauOnMars.MoveRoverWithIDAndSequence(RoverID, line); } else { // If the line count is odd // It is a new rover to create int XPos = int.Parse(variables[0]); int YPos = int.Parse(variables[1]); string Direction = variables[2]; PlateauOnMars.AddRoverWithInformation(XPos, YPos, Direction); } } await File.WriteAllLinesAsync(Path.Combine(Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\")), "Output.txt"), PlateauOnMars.GetInformationOfRovers()); } else { throw new FileNotFoundException(); } }
static void Main(string[] args) { Plateau plateau = new Plateau("Mars", new Coordinate(5, 5)); Rover rover1 = new Rover(plateau, new Coordinate(1, 2), Direction.N); rover1.Start("LMLMLMLMM"); Rover rover2 = new Rover(plateau, new Coordinate(3, 3), Direction.E); rover2.Start("MMRMMRMRRM"); Console.WriteLine("Test Input:\n" + $"{plateau.Coordinate.X} {plateau.Coordinate.Y}" + " \n1 2 N\nLMLMLMLMM\n3 3 E\nMMRMMRMRRM\n\nExpected Output :"); Console.WriteLine($"{rover1.Coordinate.X} {rover1.Coordinate.Y} {rover1.Direction.ToString()}"); Console.WriteLine($"{rover2.Coordinate.X} {rover2.Coordinate.Y} {rover2.Direction.ToString()}"); Console.ReadLine(); }
static void Main(string[] args) { var message = string.Empty; Plateau plateau = new Plateau(5, 5); var rover1 = new Rover(0, 0, Orientations.N); var rover2 = new Rover(3, 3, Orientations.E); plateau.AddRovel(rover1); message = plateau.Process(rover1, "LMLMLMLMM"); Console.WriteLine(message); plateau.AddRovel(rover2); message = plateau.Process(rover2, "MMRMMRMRRM"); Console.WriteLine(message); }
public void ProcessLine(string line, ProcessorState state) { string[] vals = line.Split(" "); Plateau plateau; try{ int xmax = Int32.Parse(vals[0]); int ymax = Int32.Parse(vals[1]); plateau = new Plateau(xmax, ymax); LogManager.LogDebug("Set up plateau max values x = " + xmax + ", y = " + ymax); state.Plateau = plateau; } catch (Exception) { throw new Exception("Invalid plateau size format: " + line); } }
static void Main(string[] args) { string boundry; string roverPos; Orientation roverO; string roverInstruction; // assuming all data entered are valid Console.WriteLine("Please enter upper right coordinates"); boundry = Console.ReadLine(); Plateau plateau = new Plateau(new Position(boundry)); Console.WriteLine("Please enter first Rover's position"); roverPos = Console.ReadLine(); roverO = (Orientation)Enum.Parse(typeof(Orientation), roverPos.Split(' ')[2]); Rover roverA = new Rover(new Position(roverPos), roverO, plateau.MaxPosition); plateau.PlaceRover(roverA); Console.WriteLine("Please enter first Rover's instructions"); roverInstruction = Console.ReadLine(); roverA.SetInstruction(roverInstruction); Console.WriteLine("Please enter second Rover's position"); roverPos = Console.ReadLine(); roverO = (Orientation)Enum.Parse(typeof(Orientation), roverPos.Split(' ')[2]); Rover roverB = new Rover(new Position(roverPos), roverO, plateau.MaxPosition); plateau.PlaceRover(roverB); Console.WriteLine("Please enter second Rover's instructions"); roverInstruction = Console.ReadLine(); roverB.SetInstruction(roverInstruction); plateau.ExecuteInstructions(); // start exploring Console.WriteLine("Final positions of rovers are:"); plateau.DisplayPositions(); Console.ReadLine(); }
public void Execute(string command, Plateau plateau) { foreach (var c in command) { switch (c) { case 'L': Left(); break; case 'R': Right(); break; case 'M': Move(plateau.Width, plateau.Height); break; } } }
static void Main(string[] args) { try { var plateau = new Plateau(); CommandInvoker commandInvoker = new CommandInvoker(); foreach (var rover in plateau.Rovers) { commandInvoker.AddCommand(rover.Commands.ToArray()); commandInvoker.RunCommands(); Console.WriteLine(rover); } } catch (Exception) { Console.WriteLine("Error has occured."); } }
static void Main() { SetGlobalExceptionHandler(); //First Rover var firstPlateau = new Plateau(new Position(5, 5)); var firstRover = new RoverService(firstPlateau, new Position(1, 2), Directions.N); firstRover.Process("LMLMLMLMM"); //Second Rover var secondPlateau = new Plateau(new Position(5, 5)); var secondRover = new RoverService(secondPlateau, new Position(3, 3), Directions.E); secondRover.Process("MMRMMRMRRM"); Print(firstRover, secondRover); Console.ReadKey(); }
static void Main(string[] args) { string commands1 = "LMLMLMLMM"; Plateau plateauOne = new Plateau(new Position(5, 5)); Rover firstRover = new Rover(plateauOne, new Position(1, 2), Directions.N); firstRover.ApplyCommands(commands1); Console.WriteLine($"Input {commands1}"); Console.WriteLine($"Output {firstRover.ToString()}"); string commands2 = "MMRMMRMRRM"; Plateau plateauTwo = new Plateau(new Position(5, 5)); Rover secondRover = new Rover(plateauTwo, new Position(3, 3), Directions.E); secondRover.ApplyCommands(commands2); Console.WriteLine($"Input {commands2}"); Console.WriteLine($"Output {secondRover.ToString()}"); Console.ReadLine(); }
static void Main() { #region Definations IBase _SBase = new SBase(); ICommand _SCommand = new SCommand(_SBase); ILocation _SLocation = new SLocation(_SCommand); IRover _SRover = new SRover(_SCommand, _SBase, _SLocation); IPlateau _SPlateau = new SPlateau(); #endregion #region Test Input One Plateau plateau = _SPlateau.createPlateau(5, 5); Dictionary <Rover, bool> firstRover = _SRover.setRoverLocation(plateau, 1, 2, enumMainDirections.N); if (firstRover.FirstOrDefault().Value) { Dictionary <Rover, bool> firstRoverResponse = _SRover.updateRoverLocation(plateau, firstRover.FirstOrDefault().Key, "LMLMLMLMM"); _SLocation.roverResultLocation(firstRoverResponse); } else { _SCommand.printInvalidLocationOrDirection(); } #endregion #region Test Input Two Dictionary <Rover, bool> secondRover = _SRover.setRoverLocation(plateau, 3, 3, enumMainDirections.E); if (firstRover.FirstOrDefault().Value) { Dictionary <Rover, bool> secondRoverResponse = _SRover.updateRoverLocation(plateau, secondRover.FirstOrDefault().Key, "MMRMMRMRRM"); _SLocation.roverResultLocation(secondRoverResponse); } else { _SCommand.printInvalidLocationOrDirection(); } #endregion Console.ReadLine(); }
public Rover(int x, int y, String direction, Plateau plateau) { if (x >= 0 && y >= 0 && x <= plateau.X && y <= plateau.Y) { this.plateauRoverPositionX = x; this.plateauRoverPositionY = y; } else { throw new OutOfBoundsException("Valores negativos não permitidos"); } if (direction.Equals("N") || direction.Equals("S") || direction.Equals("E") || direction.Equals("W")) { this.direction = direction; } else { throw new InvalidStringValueException("String vazia ou inválida."); } this.plateau = plateau; }
private static void Main(string[] args) { Console.Write("Plateau Grid (x, y):\t"); var input = Console.ReadLine(); try { plateau = Plateau.Define(input); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } while (true) { DeployRover(); var rover = ExplorePlateau(); Console.WriteLine($"#{plateau.TotalRovers} Final Position:\t{rover.Position}"); } }
static void Main(string[] args) { Console.WriteLine("Mars Rover Challenge"); var reader = new InputReader(); var plateauInput = Console.ReadLine(); Plateau plateauArea = null; try { plateauArea = reader.ReadPlateauBoundary(plateauInput); } catch (UserInputException ex) { Console.WriteLine(ex.Message); return; } var rovers = new List <Rover>(); var newRoverPositionInput = string.Empty; do { try { DeployRover(newRoverPositionInput, reader, plateauArea, rovers); } catch (UserInputException ex) { Console.WriteLine(ex.Message); return; } newRoverPositionInput = Console.ReadLine().Trim(); } while (newRoverPositionInput.Length > 0); MoveRovers(rovers); }
/// <summary> /// Taking upper-right co-ordinates of the plateau /// </summary> /// <returns></returns> private static Plateau getUpperRightCoordinates() { //creating a new Plateau instance Plateau plateau = new Plateau(); while (true) { Console.Write("Write the upper-right co-ordinates in a format like '{x point} {y point}' (e.g. '5 6' ): "); string _val = Console.ReadLine(); //displaying an error message if coordinates that is entered, has invalid format if (!plateau.IsPointHasValidFormat(_val)) { Console.WriteLine("Write in the correct format!"); continue; } //Getting rid of space string[] upperRightCoordinates = _val.Split(" "); //Assigning plateau's coordinates plateau.UpperRightX = Convert.ToInt32(upperRightCoordinates[0]); plateau.UpperRightY = Convert.ToInt32(upperRightCoordinates[1]); return(plateau); } }
static void Main(string[] args) { Console.WriteLine("Size of Plateau :"); var plateauSizeCommand = Console.ReadLine(); var inputCommandPlateauSize = Helper.InputCommandPlateauSize(plateauSizeCommand); Plateau.SetPlateau(inputCommandPlateauSize.Width, inputCommandPlateauSize.Height); Console.WriteLine("Rover Position :"); var roverPositionCommand = Console.ReadLine(); var inputCommandRoverPosition = Helper.InputCommandRoverPosition(roverPositionCommand); var rover = new Rover(inputCommandRoverPosition.PositionX, inputCommandRoverPosition.PositionY, inputCommandRoverPosition.Direction); Console.WriteLine("Command :"); var command = Console.ReadLine(); rover.Drive(command); rover.GetPosition(); Console.ReadLine(); }
static void Main(string[] args) { Plateau plateau = new Plateau(5, 5); MarsRover rover = new MarsRover(1, 2, "N", plateau); string commands = "LMLMLMLMM"; foreach (var command in commands) { if (command == 'M') { rover.move(); } else { rover.turn(command.ToString()); } Console.WriteLine(rover); } Console.ReadLine(); }
/// <summary> /// Advance method to change the co-ordinates based on controller input. /// Skips the action of controller if it finds another rover for the action, /// or crosses the boundary limits. /// </summary> public void advance() { char currentDirection = getDirection(); switch (currentDirection) { case 'N': if ((_ycoord + 1 <= Plateau.getMaxy()) && (_ycoord + 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord, _ycoord + 1, _direction)))) { _ycoord = _ycoord + 1; } break; case 'W': if ((_xcoord - 1 <= Plateau.getMaxx()) && (_xcoord - 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord - 1, _ycoord, _direction)))) { _xcoord = _xcoord - 1; } break; case 'E': if ((_xcoord + 1 <= Plateau.getMaxx()) && (_xcoord + 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord + 1, _ycoord, _direction)))) { _xcoord = _xcoord + 1; } break; case 'S': if ((_ycoord - 1 <= Plateau.getMaxy()) && (_ycoord - 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord, _ycoord - 1, _direction)))) { _ycoord = _ycoord - 1; } break; } }
public Rover(int x, int y, string direction, Plateau plateau) { direction = direction.ToUpper(); if (x >= 0 && y >= 0 && x <= plateau.X && y <= plateau.Y) { this.xCoordinate = x; this.yCoordinate = y; } else { Console.WriteLine("Girilen değerler uygun değildir"); } if (direction == "N" || direction == "S" || direction == "E" || direction == "W") { this.direction = direction; } else { Console.WriteLine("Girilen Doğrultu Yanlış"); } this.plateau = plateau; }
public Rover() { _placesOfDeath = new List <Position>(); this.Plateau = new Plateau(5, 5, 0, 0); }
public Rover(Plateau plateau) { _placesOfDeath = new List <Position>(); this.Plateau = plateau; }
public void TestIfThrowExceptionWhenInstructionIsInvalid() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(5, 5, "Z", plateau); }
public Rover(Position initialPosition, Plateau plateau, IInstructionHandler instructionHandler) { Position = initialPosition; _plateau = plateau; _instructionHandler = instructionHandler; }
public void TestIFCreateANewPlateauCorrectly() { Plateau plateau = new Plateau(5, 5); int expected = 5; Assert.AreEqual(expected, plateau.X); }
public void TestIfThrowExceptionWhenRoverYPlateauPositionGoesOutOfPlateauLimits() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(4, 8, "N", plateau); }
public void TestIfThrowExceptionWhenXValueIsZero() { Plateau plateau = new Plateau(0, 5); }
public void TestIfThrowExceptionWhenXValueIsNegative() { Plateau plateau = new Plateau(-1, 5); }
public void TestToString() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(1, 2, "N", plateau); Assert.IsNotNull(rover.toString()); }
static void Main(string[] args) { var container = ContainerConfig.Configure(); #region Input Sequence var plateauRegex = new Regex("\\d\\s\\d$"); string plateauInfo = ""; Console.WriteLine("Enter plateau size. ex: 5 5"); do { plateauInfo = Console.ReadLine(); }while(!plateauRegex.IsMatch(plateauInfo)); var roverRegex = new Regex("^\\d\\s\\d\\s\\b[N,S,W,E]$"); string roverOneInfo = ""; Console.WriteLine("Enter RoverOne start point and compass sign. ex: 1 2 N"); do { roverOneInfo = Console.ReadLine(); }while(!roverRegex.IsMatch(roverOneInfo)); var roverOneInstructions = ""; Console.WriteLine("Enter RoverOne orders. ex:LMLMLMLMM"); do { roverOneInstructions = Console.ReadLine(); } while (roverOneInstructions.Any(x => x != 'L' && x != 'M' && x != 'R')); var roverTwoInfo = ""; Console.WriteLine("Enter RoverTwo start point and compass sign. ex: 3 3 E"); do { roverTwoInfo = Console.ReadLine(); }while(!roverRegex.IsMatch(roverTwoInfo)); Console.WriteLine("Enter RoverTwo instructions. ex:MMRMMRMRRM"); var roverTwoInstructions = ""; do { roverTwoInstructions = Console.ReadLine(); } while (roverTwoInstructions.Any(x => x != 'L' && x != 'M' && x != 'R')); #endregion input sequence #region Parsing Inputs var x = Convert.ToInt32(plateauInfo.Split(" ")[0]); var y = Convert.ToInt32(plateauInfo.Split(" ")[1]); var RoverOneX = Convert.ToInt32(roverOneInfo.Split(" ")[0]); var RoverOneY = Convert.ToInt32(roverOneInfo.Split(" ")[1]); var RoverOneOrientation = roverOneInfo.Split(" ")[2]; var RoverTwoX = Convert.ToInt32(roverTwoInfo.Split(" ")[0]); var RoverTwoY = Convert.ToInt32(roverTwoInfo.Split(" ")[1]); var RoverTwoOrientation = roverTwoInfo.Split(" ")[2]; #endregion Parsing imputs //create items by inputs IPlateau plateau = new Plateau(x, y); IRover roverOne = new Rover(RoverOneX, RoverOneY, plateau); IRover roverTwo = new Rover(RoverTwoX, RoverTwoY, plateau); //create roverInstructions List <IInstruction> _tempRoverOneInstructions = new List <IInstruction>(); List <IInstruction> _tempRoverTwoInstructions = new List <IInstruction>(); //Resolving container configs and filling roverInstructions using (var scope = container.BeginLifetimeScope()) { foreach (var instruction in roverOneInstructions) { var roverInstruction = container.Resolve <IInstruction>(new NamedParameter("instruction", instruction)); _tempRoverOneInstructions.Add(roverInstruction); } roverOne.UpdateInstructions(_tempRoverOneInstructions); foreach (var instruction in roverTwoInstructions) { var roverCommand = container.Resolve <IInstruction>(new NamedParameter("instruction", instruction)); _tempRoverTwoInstructions.Add(roverCommand); } roverTwo.UpdateInstructions(_tempRoverTwoInstructions); var rover1Orientation = container.Resolve <IOrientation>(new NamedParameter("orientation", RoverOneOrientation)); roverOne.UpdateOrientation(rover1Orientation); var rover2Orientation = container.Resolve <IOrientation>(new NamedParameter("orientation", RoverTwoOrientation)); roverTwo.UpdateOrientation(rover2Orientation); } //Move one by one roverOne.MoveRover(); roverTwo.MoveRover(); }
public void TestMoveMethodException() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(1,2,"N",plateau); rover.ReadCommands("MMMMM"); }
public void TestIfTrhowExceptionWhenYValueIsZero() { Plateau plateau = new Plateau(5, 0); }
public void TestIfThrowExceptionWhenXRoverPlateauPositionIsNegative() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(-2, 2, "N", plateau); }
public void TestIfThrowExceptionWhenYValueIsNegative() { Plateau plateau = new Plateau(5, -1); }
public void TestTurnRight90DegreesMethod() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(2, 2, "N", plateau); rover.turn90DegreesToRight(); String expectedState = "W"; NUnit.Framework.Assert.That(rover.Direction, NUnit.Framework.Is.EqualTo(expectedState)); }
/// <summary> /// Default constructor to instantiate an object of rover. /// </summary> /// <param name="plateau">Instance of plateau</param> /// <param name="baseLocation">Base Location</param> /// <param name="name">Name of the rover</param> public Rover(Plateau plateau, string baseLocation, string name) : base(plateau, baseLocation, name) { }
public void TestMoveMethod() { Plateau plateau = new Plateau(5, 5); Rover rover = new Rover(2,2,"N",plateau); rover.moveRover(); int expectedState = 3; NUnit.Framework.Assert.That(rover.PlateauY, NUnit.Framework.Is.EqualTo(expectedState)); }