static void Main(string[] args) { IHelper helper = new Helper(); helper.InitializeInputs(); Plateau plateau = helper.GetPlateau(); List <Rover> roverList = helper.GetRovers(); IRoverNavigation objRN = new RoverNavigation(); objRN.CalculateRoverPosition(plateau, roverList); helper.DisplayOutput(); Console.ReadKey(); }
static void Main(string[] args) { ILandingSurface landingSurface = new Plateau("5 5"); RoverSquad roverSquad = new RoverSquad(landingSurface); roverSquad.DeployNewRover("1 2 N", "LMLMLMLMM"); roverSquad.DeployNewRover("3 3 E", "MMRMMRMRRM"); foreach (var rover in roverSquad) { Console.WriteLine("{0} {1} {2}", rover.XCoordinate, rover.YCoordinate, rover.Direction); } Console.ReadLine(); }
public void InitializeInputs() { plateau = new Plateau(5, 5); rovers = new List <Rover>(); string ins1 = "LMLMLMLMM"; Rover r1 = new Rover() { X = 1, Y = 2, Direction = Direction.N, Instructions = ins1.Select(c => (Instruction)Enum.Parse(typeof(Instruction), c.ToString(), true)).ToList() }; rovers.Add(r1); string ins2 = "MMRMMRMRRM"; Rover r2 = new Rover() { X = 3, Y = 3, Direction = Direction.E, Instructions = ins2.Select(c => (Instruction)Enum.Parse(typeof(Instruction), c.ToString(), true)).ToList() }; rovers.Add(r2); inputRovers = new List <Rover>(); inputRovers = rovers; }
public bool IsValidLandingPosition(Plateau p, Rover r) { int currentX = r.X; int currentY = r.Y; bool result = false; try { switch (r.Direction) { case Direction.N: currentY++; result = currentY <= p.RightY; break; case Direction.S: currentY--; result = currentY >= 0; break; case Direction.E: currentX++; result = currentX <= p.RightX; break; case Direction.W: currentX--; result = currentX >= 0; break; default: break; } return(result); } catch (Exception ex) { throw ex; } }
public void CalculateRoverPosition(Plateau p, List <Rover> roverList) { try { foreach (Rover r in roverList) { foreach (Instruction i in r.Instructions) { switch (i) { case Instruction.L: NavigateLeft(r); break; case Instruction.R: NavigateRight(r); break; case Instruction.M: if (helper.IsValidLandingPosition(p, r)) { MoveForward(r); } break; default: break; } } } } catch (Exception ex) { throw ex; } }