示例#1
0
        public void ObstacleDectectionMoveBackwardDirectionWest()
        {
            rover.currentPosition = new RoverLocation(1, 0, Direction.W);
            RoverLocation location = rover.MoveRover("B", out ObstacleCoOrdinates);

            Assert.AreEqual(ObstacleCoOrdinates.XCoOrdinate, 1);
            Assert.AreEqual(ObstacleCoOrdinates.YCoOrdinate, 1);
            Assert.AreEqual(location, rover.currentPosition);
        }
示例#2
0
        public void ObstacleDectectionMoveForwardDirectionSouth()
        {
            rover.currentPosition = new RoverLocation(2, 1, Direction.S);
            RoverLocation location = rover.MoveRover("F", out ObstacleCoOrdinates);

            Assert.AreEqual(ObstacleCoOrdinates.XCoOrdinate, 1);
            Assert.AreEqual(ObstacleCoOrdinates.YCoOrdinate, 1);
            Assert.AreEqual(location, rover.currentPosition);
        }
示例#3
0
        public void MoveLeft(RoverLocation location)
        {
            LinkedListNode <Direction> node = directionsList.Find(location.CurrentDirection);

            // If first node go to last node
            if (directionsList.First() == node.Value)
            {
                location.CurrentDirection = directionsList.Last.Value;
            }
            else
            {
                location.CurrentDirection = node.Previous.Value;
            }
        }
示例#4
0
        public void MoveRight(RoverLocation location)
        {
            LinkedListNode <Direction> node = directionsList.Find(location.CurrentDirection);

            // If last node go to first node
            if (directionsList.Last() == node.Value)
            {
                location.CurrentDirection = directionsList.First.Value;
            }
            else
            {
                location.CurrentDirection = node.Next.Value;
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            List <ObstacleCoOrdinates> obstacles = new List <ObstacleCoOrdinates> {
                new ObstacleCoOrdinates(1, 1)
            };

            Console.WriteLine("Get ready to maneuver the rover on Pluto!");
            InsertBlankLine();

            // XX TODO Get input from user for the grid
            Rover rover = new Rover(new Grid(100, 100, obstacles));

            rover.currentPosition = new RoverLocation(0, 0, Direction.N);

            bool confirmed = false;

            do
            {
                Console.WriteLine("Input maneuver instructions");
                string instruction = Console.ReadLine();

                ObstacleCoOrdinates obstacleCo;
                RoverLocation       location = rover.MoveRover(instruction, out obstacleCo);

                if (obstacleCo.XCoOrdinate != 0 && obstacleCo.YCoOrdinate != 0)
                {
                    Console.WriteLine($"Obstacle at '{obstacleCo.XCoOrdinate}, {obstacleCo.YCoOrdinate}'. Rover's current location : {location.CurrentX},{location.CurrentY},{location.CurrentDirection}");
                }
                else
                {
                    Console.WriteLine($"Rover's current location : {location.CurrentX},{location.CurrentY},{location.CurrentDirection}");
                }

                Console.WriteLine("Do you want to continue to move the rover [y/n]");

                string option = Console.ReadLine();
                confirmed = option == "y" ? true : false;
            } while (confirmed);

            Console.WriteLine("Press Any Key To exit.");

            Console.ReadKey();
        }
示例#6
0
        public bool MoveForward(RoverLocation location, out ObstacleCoOrdinates obstacle)
        {
            RoverLocation newLocation = new RoverLocation(location.CurrentX, location.CurrentY, location.CurrentDirection);

            obstacle = new ObstacleCoOrdinates();

            switch (location.CurrentDirection)
            {
            case Direction.N:
                newLocation.CurrentX = IncrementX(location.CurrentX);
                break;

            case Direction.S:
                newLocation.CurrentX = DecrementX(location.CurrentX);
                break;

            case Direction.E:
                newLocation.CurrentY = IncrementY(location.CurrentY);
                break;

            case Direction.W:
                newLocation.CurrentY = DecrementY(location.CurrentY);
                break;
            }

            bool obstacleAtNewLocation = CheckIfObstacleAtLocation(newLocation.CurrentX, newLocation.CurrentY);

            if (obstacleAtNewLocation)
            {
                obstacle.XCoOrdinate = newLocation.CurrentX;
                obstacle.YCoOrdinate = newLocation.CurrentY;
                return(true);
            }
            else
            {
                location.CurrentX         = newLocation.CurrentX;
                location.CurrentY         = newLocation.CurrentY;
                location.CurrentDirection = newLocation.CurrentDirection;

                return(false);
            }
        }