Esempio n. 1
0
 public void MoveTest()
 {
     Surface MySurface = new Surface(new Size(5, 5));
     Rover Rover1 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.North);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
 }
Esempio n. 2
0
        public void PlexisChallenge()
        {
            Surface MySurface = new Surface(new Size(5, 5));

            Rover Spirit = new Rover(MySurface, new Point(1, 2), PhysicalObject.Heading.North);
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Move();
            Assert.AreEqual(new Point(1, 3), MySurface.GetPosition(Spirit));
            Assert.AreEqual(PhysicalObject.Heading.North, Spirit.Direction);

            Rover Opportunity = new Rover(MySurface, new Point(3, 3), PhysicalObject.Heading.East);
            Opportunity.Move();
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Assert.AreEqual(new Point(5, 1), MySurface.GetPosition(Opportunity));
            Assert.AreEqual(PhysicalObject.Heading.East, Opportunity.Direction);
        }
Esempio n. 3
0
        public void CrashLandedTest()
        {
            Surface MySurface = new Surface(new Size(5, 5));
            Rover Rover1 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.North);
            Rover Rover2 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.East);

            Assert.AreEqual(true, Rover2.CrashLanded);
        }
Esempio n. 4
0
 public void LocationAvailableTest()
 {
     Surface MySurface = new Surface(new Size(5, 5));
     Assert.AreEqual(true, MySurface.LocationAvailable(new Point(0, 0)));
     Assert.AreEqual(true, MySurface.LocationAvailable(new Point(5, 5)));
     Assert.AreEqual(false, MySurface.LocationAvailable(new Point(-1, 0)));
     Assert.AreEqual(false, MySurface.LocationAvailable(new Point(0, -1)));
     Assert.AreEqual(false, MySurface.LocationAvailable(new Point(6, 0)));
     Assert.AreEqual(false, MySurface.LocationAvailable(new Point(0, 6)));
 }
Esempio n. 5
0
 /// <summary>Create a new rover</summary>
 /// <param name="mySurface">What (Surface) should the rover land on?</param>
 /// <param name="startingPosition">What (Point) does the rover originate at?</param>
 /// <param name="directionFacing">What (Heading) is our rover point in?</param>
 public Rover(Surface mySurface, Point startingPosition, Heading directionFacing)
 {
     this.parent = mySurface;
     this.Direction = directionFacing;
     this.crashLanded = !this.parent.AddObject(this, startingPosition);
 }
Esempio n. 6
0
        public void RoverConstructorTest()
        {
            // Test a "crash landing"
            Surface MySurface = new Surface(new Size(5, 5));
            Rover Rover1 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.North);

            Assert.AreEqual(new Point(0, 0), MySurface.GetPosition(Rover1));
        }
Esempio n. 7
0
 public void RotateTest()
 {
     Surface MySurface = new Surface(new Size(5, 5));
     Rover Rover1 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.North);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 0), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 0), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 2), MySurface.GetPosition(Rover1));
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            HashSet<Rover> Rovers = new HashSet<Rover>();
            String[] Input;

            Console.WriteLine("Please specify the size of the Mars Plateu:");
            Console.WriteLine("The first number is the width, and the second number is the height.");

            Input = Console.ReadLine().Split(' ');
            Surface MySurface = new Surface(new Size(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])));

            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Please specify the starting position and direction of the rover:");
                Console.WriteLine("The first number is the horizontal coordinate, the second number is the vertical coordinate");
                Console.WriteLine("The third value is a single character representing a Cardinal Point (N, S, E, or W)");
                Console.WriteLine("Please enter a blank line to indicate you have no more rovers to enter.");

                Input = Console.ReadLine().Split(' ');

                try
                {
                    PhysicalObject.Heading Direction = PhysicalObject.Heading.North;
                    switch (Input[2].ToUpper())
                    {
                        case "N":
                            Direction = PhysicalObject.Heading.North;
                            break;
                        case "E":
                            Direction = PhysicalObject.Heading.East;
                            break;
                        case "S":
                            Direction = PhysicalObject.Heading.South;
                            break;
                        case "W":
                            Direction = PhysicalObject.Heading.West;
                            break;
                    }
                    Rover CurrentRover = new Rover(MySurface, new Point(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])), Direction);

                    Console.WriteLine("Please provide a string of directions for the rover to follow.  No spaces are requred.");
                    Console.WriteLine("{ L = Turn Left; R = Turn Right; M = Move 1 unit forward }");

                    String UserInput = Console.ReadLine().Replace(" ", "");

                    foreach (Char character in UserInput.ToUpper())
                    {
                        switch (character)
                        {
                            case 'L':
                                CurrentRover.Rotate(PhysicalObject.Rotation.Left);
                                break;
                            case 'R':
                                CurrentRover.Rotate(PhysicalObject.Rotation.Right);
                                break;
                            case 'M':
                                CurrentRover.Move();
                                break;
                        }
                    }

                    Rovers.Add(CurrentRover);
                }
                catch
                {
                    break;
                }
            }

            Console.WriteLine("These are the resulting location(s) for your rover(s):");

            foreach (Rover TestRover in Rovers)
            {
                String Output = "";
                Output += MySurface.GetPosition(TestRover).X;
                Output += " ";
                Output += MySurface.GetPosition(TestRover).Y;
                Output += " ";

                switch (TestRover.Direction)
                {
                    case PhysicalObject.Heading.North:
                        Output += "N";
                        break;
                    case PhysicalObject.Heading.East:
                        Output += "E";
                        break;
                    case PhysicalObject.Heading.South:
                        Output += "S";
                        break;
                    case PhysicalObject.Heading.West:
                        Output += "W";
                        break;
                }

                Console.WriteLine(Output);
            }

            Console.Read();
        }
        static void Main(string[] args)
        {
            HashSet <Rover> Rovers = new HashSet <Rover>();

            String[] Input;

            Console.WriteLine("Please specify the size of the Mars Plateu:");
            Console.WriteLine("The first number is the width, and the second number is the height.");

            Input = Console.ReadLine().Split(' ');
            Surface MySurface = new Surface(new Size(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])));

            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Please specify the starting position and direction of the rover:");
                Console.WriteLine("The first number is the horizontal coordinate, the second number is the vertical coordinate");
                Console.WriteLine("The third value is a single character representing a Cardinal Point (N, S, E, or W)");
                Console.WriteLine("Please enter a blank line to indicate you have no more rovers to enter.");

                Input = Console.ReadLine().Split(' ');

                try
                {
                    PhysicalObject.Heading Direction = PhysicalObject.Heading.North;
                    switch (Input[2].ToUpper())
                    {
                    case "N":
                        Direction = PhysicalObject.Heading.North;
                        break;

                    case "E":
                        Direction = PhysicalObject.Heading.East;
                        break;

                    case "S":
                        Direction = PhysicalObject.Heading.South;
                        break;

                    case "W":
                        Direction = PhysicalObject.Heading.West;
                        break;
                    }
                    Rover CurrentRover = new Rover(MySurface, new Point(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])), Direction);

                    Console.WriteLine("Please provide a string of directions for the rover to follow.  No spaces are requred.");
                    Console.WriteLine("{ L = Turn Left; R = Turn Right; M = Move 1 unit forward }");

                    String UserInput = Console.ReadLine().Replace(" ", "");

                    foreach (Char character in UserInput.ToUpper())
                    {
                        switch (character)
                        {
                        case 'L':
                            CurrentRover.Rotate(PhysicalObject.Rotation.Left);
                            break;

                        case 'R':
                            CurrentRover.Rotate(PhysicalObject.Rotation.Right);
                            break;

                        case 'M':
                            CurrentRover.Move();
                            break;
                        }
                    }

                    Rovers.Add(CurrentRover);
                }
                catch
                {
                    break;
                }
            }

            Console.WriteLine("These are the resulting location(s) for your rover(s):");

            foreach (Rover TestRover in Rovers)
            {
                String Output = "";
                Output += MySurface.GetPosition(TestRover).X;
                Output += " ";
                Output += MySurface.GetPosition(TestRover).Y;
                Output += " ";

                switch (TestRover.Direction)
                {
                case PhysicalObject.Heading.North:
                    Output += "N";
                    break;

                case PhysicalObject.Heading.East:
                    Output += "E";
                    break;

                case PhysicalObject.Heading.South:
                    Output += "S";
                    break;

                case PhysicalObject.Heading.West:
                    Output += "W";
                    break;
                }

                Console.WriteLine(Output);
            }

            Console.Read();
        }
Esempio n. 10
0
 public void DimensionsTest()
 {
     Surface MySurface = new Surface(new Size(5, 5));
     Assert.AreEqual(new Size(5, 5), MySurface.Dimensions);
 }