Example #1
0
        /// <summary>
        /// Rover action to Move for Forward, extend here for backword
        /// </summary>
        /// <param name="roverMove"></param>
        public void Move(RoverMove roverMove)
        {
            if (roverMove == RoverMove.Forward)
            {
                switch (RoverCurrentFaceDirection)
                {
                case RoverFaceDirection.North:
                {
                    roverCurrentPosition.Y += 1;
                    break;
                }

                case RoverFaceDirection.East:
                {
                    roverCurrentPosition.X += 1;
                    break;
                }

                case RoverFaceDirection.South:
                {
                    roverCurrentPosition.Y -= 1;
                    break;
                }

                case RoverFaceDirection.West:
                {
                    roverCurrentPosition.X -= 1;
                    break;
                }
                }
            }
        }
Example #2
0
        public static bool Validate(RoverInfo info, RoverMove move)
        {
            if (info == null || move == null || !info.IsSuccess || !move.IsSuccess)
            {
                return(false);
            }

            return(true);
        }
 public void setup()
 {
     coordinates = new Coordinates {
         point_x = 1, point_y = 1
     };
     rover = new Rover {
         Coordinates = coordinates, Heading = Compass.north
     };
     rover_move = new RoverMove();
 }
Example #4
0
        public static RoverMove SetupMove(string input)
        {
            var move = new RoverMove
            {
                Moves     = input,
                IsSuccess = true
            };

            return(move);
        }
Example #5
0
        public Rover AddRover(RoverInfo info, RoverMove move)
        {
            if (!RoverManager.Validate(info, move))
            {
                throw new ArgumentException("Error occurred while creating Rover, try again.");
            }

            var result = RoverManager.Insert(info, move);

            return(result);
        }
Example #6
0
        public static Rover Insert(RoverInfo info, RoverMove move)
        {
            var rover = new Rover
            {
                Info      = info,
                Moves     = move,
                IsSuccess = true
            };

            return(rover);
        }
Example #7
0
            public void AddRover_Valid()
            {
                RoverInfo roverInfo = new RoverInfo()
                {
                    X         = 1,
                    Y         = 2,
                    Direction = Compass.N,
                    IsSuccess = true
                };

                RoverMove roverMove = new RoverMove()
                {
                    Moves     = "LMLMLMLMM",
                    IsSuccess = true
                };

                var result = service.AddRover(roverInfo, roverMove);

                Assert.IsTrue(result.IsSuccess);
            }
Example #8
0
            public void AddRover_InValid()
            {
                //invalid test case, because RoverMove is not success

                RoverInfo roverInfo = new RoverInfo()
                {
                    X         = 1,
                    Y         = 2,
                    Direction = Compass.N,
                    IsSuccess = true
                };

                RoverMove roverMove = new RoverMove()
                {
                    Moves     = "LMLMLMLMM",
                    IsSuccess = false
                };

                var result = service.AddRover(roverInfo, roverMove);

                Assert.IsTrue(result.IsSuccess);
            }
Example #9
0
        public static List <RoverInfo> MissionStart(MarsRoverService service, Mission mission)
        {
            Console.BackgroundColor = ConsoleColor.Black;

            foreach (PropertyInfo propertyInfo in mission.GetType().GetProperties())
            {
                switch (propertyInfo.Name)
                {
                case nameof(mission.Plateau):
                    if (mission.Plateau.IsSuccess)
                    {
                        break;
                    }
                    Console.Write("Plateau Info :");
                    Plateau plateau = service.AddPlateu(Console.ReadLine());
                    mission.Plateau = plateau;
                    break;

                case nameof(mission.RoverCount):
                    if (mission.RoverCount.IsSuccess)
                    {
                        break;
                    }
                    Console.Write("Rover Count:");
                    RoverCount roverCount = service.AddRoverCount(Console.ReadLine());
                    mission.RoverCount = roverCount;
                    var rovers = new List <Rover>();
                    for (int i = 0; i < roverCount.Count; i++)
                    {
                        rovers.Add(new Rover());
                    }
                    mission.Rovers = rovers;
                    break;

                case nameof(mission.Rovers):
                    for (int i = 0; i < mission.RoverCount.Count; i++)
                    {
                        if (mission.Rovers[i].IsSuccess)
                        {
                            break;
                        }

                        Console.WriteLine($"{i} - Rover Setup ");
                        RoverInfo roverInfo = service.SetupRoverInfo(Console.ReadLine());
                        RoverMove roverMove = service.SetupRoverMove(Console.ReadLine());
                        mission.Rovers[i] = service.AddRover(roverInfo, roverMove);
                    }
                    Console.WriteLine($" Rover Setup End ");
                    break;

                default:
                    break;
                }
            }

            var result = new List <RoverInfo>();

            for (int i = 0; i < mission.RoverCount.Count; i++)
            {
                var rover         = mission.Rovers[i];
                var serviceResult = service.StartDiscovering(mission.Plateau, rover);
                result.Add(serviceResult);

                Console.WriteLine($"Info Mission > {i} - Rover : {serviceResult.X} {serviceResult.Y} {serviceResult.Direction}, IsSuccess:{serviceResult.IsSuccess} ");

                if (!serviceResult.IsSuccess)
                {
                    Console.WriteLine($" \t Failed Detail: { serviceResult.ErrorMessage }");
                }
            }
            ;

            return(result);
        }