static void Main(string[] args) { Console.WriteLine("__Test Input:__"); Console.WriteLine(); Console.WriteLine("5 5"); Console.WriteLine("1 2 N"); Console.WriteLine("LMLMLMLMM"); Console.WriteLine(); Console.WriteLine("3 3 E"); Console.WriteLine("MMRMMRMRRM"); Console.WriteLine(); //First rover Plateau plateauOne = new Plateau(new Position(5, 5)); Rover firstRover = new Rover(plateauOne, new Position(1, 2), Directions.N); firstRover.Process("LMLMLMLMM"); //Second rover Plateau plateauTwo = new Plateau(new Position(5, 5)); Rover secondRover = new Rover(plateauTwo, new Position(3, 3), Directions.E); secondRover.Process("MMRMMRMRRM"); Console.WriteLine("__Expected Output:__"); Console.WriteLine(); Console.WriteLine(firstRover.ToString()); Console.WriteLine(secondRover.ToString()); Console.WriteLine(); Console.ReadLine(); }
private void GetRoverCoords() { Console.Write("Roverın koordinatlarını ve yönünü giriniz. [ X Y N,W,S,E ] = "); if (InputValidator.CheckRoverCoordsAndDirection(Console.ReadLine(), out int x, out int y, out Direction _direction)) { Rover rover = new Rover(map) { PosX = x, PosY = y, RoverDirection = _direction }; Console.WriteLine(rover.ToString()); GetRoverCommand(rover); rovers.Add(rover); Console.WriteLine("Başka bir rover eklemek istiyorsanız E'ye basınız."); Console.WriteLine("Devam etmek için herhangi bir tuşa basabilirsiniz."); if (Console.ReadLine() != "E") { return; } } GetRoverCoords(); }
static void Main(string[] args) { // notes // if try to move outside bounds of perimiter, it will move to the edge in that direction and not throw an error // default plateau size is 0,0 to infinity unless set var plateau = new Plateau(); plateau.SetGridSize(40, 30); // this needed to handle multiple rovers var RoverController = new RoverController(plateau); var rover = new Rover(RoverController); rover.SetPosition(10, 10, "N"); rover.Move("R1R3L2L1"); Console.WriteLine(rover.ToString()); // if uncommented this will throw excepton as robots crash // var rover2 = new Rover(RoverController); // rover2.SetPosition(10, 10, "N"); // rover2.Move("R1R3L2L3"); // Console.WriteLine(rover2.ToString()); Console.ReadLine(); }
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(); }
private static void ReportLocation(Rover activeRover) { Console.WriteLine(activeRover.ToString()); }
private string ParseRoverInstructions(string[] instructions) { StringBuilder output = new StringBuilder(); for (int i = 1; i < instructions.Length; i += 2) { var startPosLine = instructions[i]; if (!IsValidPosition(startPosLine)) // verify the start position is in the valid format { output.AppendLine($"Warning: Invalid start position for Rover #{i / 2}. Sipping rover commands."); continue; } var startPos = instructions[i].Split(' '); Rover rover = new Rover(int.Parse(startPos[0]), int.Parse(startPos[1]), startPos[2]); if (!IsInBounds(rover.Position)) // verify that the given start position is in bounds of the plateau { output.AppendLine($"Warning: Invalid start position for Rover #{i / 2}. Sipping rover commands."); continue; } var commands = instructions[i + 1]; if (!IsValidCommands(commands)) // verify that the commands are in the valid format { output.AppendLine($"Warning: Invalid commands for Rover #{i / 2}. Sipping rover commands."); continue; } foreach (var command in commands) { switch (command) { case 'L': case 'l': rover.RotateLeft(); break; case 'R': case 'r': rover.RotateRight(); break; case 'M': case 'm': if (IsInBounds(rover.GetNextPosition())) { rover.Position = rover.GetNextPosition(); } else { output.AppendLine($"Warning: Cannot move Rover #{i / 2} out of bounds. Move command ignored."); } break; } } // send updated position back to NASA output.AppendLine(rover.ToString()); } return(output.ToString()); }
//Adds current rover coordinates and heading to RoverEndValues public void UpdateRoverEndValues() { RoverEndValues += Rover.ToString(); RoverEndValues += "\n"; }