public void MyTest_GoRandom2()
        {
            MarsMap  marsMap           = new MarsMap(10, 10);
            Rover    rover             = new Rover(5, 5, "S");
            string   roverInstructions = "LMMLMMLMMLMM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "5 5 S");
        }
        public void MyTest_FallOffCliff()
        {
            MarsMap  marsMap           = new MarsMap(10, 10);
            Rover    rover             = new Rover(0, 1, "S");
            string   roverInstructions = "MM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "0 -1 S");
        }
        public void GivenTest_GoRandom1()
        {
            MarsMap  marsMap           = new MarsMap(5, 5);
            Rover    rover             = new Rover(1, 2, "N");
            string   roverInstructions = "LMLMLMLMM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "1 3 N");
        }
        public void MyTest_GoingCircle()
        {
            MarsMap  marsMap           = new MarsMap(10, 10);
            Rover    rover             = new Rover(5, 7, "E");
            string   roverInstructions = "RRRRLLLL";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "5 7 E");
        }
        public void MyTest_GoRandom1()
        {
            MarsMap  marsMap           = new MarsMap(10, 10);
            Rover    rover             = new Rover(0, 0, "N");
            string   roverInstructions = "MMMRMMMLMM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "3 5 N");
        }
        public void MyTest_MoveStraight()
        {
            MarsMap  marsMap           = new MarsMap(10, 10);
            Rover    rover             = new Rover(5, 5, "W");
            string   roverInstructions = "MMMMM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            Assert.AreEqual(scenario.Run(), "10 5 W");
        }
        public void GivenTest_GoRandom2()
        {
            MarsMap  marsMap           = new MarsMap(5, 5);
            Rover    rover             = new Rover(3, 3, "E");
            string   roverInstructions = "MMRMMRMRRM";
            Scenario scenario          = new Scenario(marsMap, rover, roverInstructions);

            // This output in pdf is incorrect
            //Assert.AreEqual(scenario.Run(), "5 1 E");
            Assert.AreEqual(scenario.Run(), "1 5 E");
        }
Exemple #8
0
        public static void Main(string[] args)
        {
            IConsoleReader        consoleReader        = new SystemConsoleReader();
            ICardinalPointFactory cardinalPointFactory = new CardinalPointFactory();
            InputReader           InputReader          = new InputReader(consoleReader, cardinalPointFactory);
            MarsMap           marsMap = InputReader.GetMarsMap();
            IList <RoverBase> rovers  = InputReader.GetRovers(roverCount);

            marsMap.Rovers = rovers;
            marsMap.Discover();
            var roversPositions = marsMap.ToString();

            System.Console.WriteLine(roversPositions);
        }
        private static MarsMap GetMap(int roverX, int roverY, ICardinalPoint cardinalPoint, List <DirectionType> directionTypes)
        {
            RoboticRover rover      = new RoboticRover(new MarsPoint(roverX, roverY), cardinalPoint);
            var          directions = directionTypes;

            rover.MovePattern = new MovePattern(directions);
            MarsMap map = new MarsMap(new MarsPoint(5, 5));

            map.Rovers = new List <RoverBase>()
            {
                rover
            };
            return(map);
        }
        public void Discover_WhenRoverIsOn1_2NPatternIsLMLMLMLMM_ShouldLastPositionIs1_3_N()
        {
            //arrange
            var directions = new List <DirectionType>()
            {
                DirectionType.Left,
                DirectionType.Move,
                DirectionType.Left,
                DirectionType.Move,
                DirectionType.Left,
                DirectionType.Move,
                DirectionType.Left,
                DirectionType.Move,
                DirectionType.Move
            };
            MarsMap map = GetMap(1, 2, new NorthCardinalPoint(), directions);

            //act
            map.Discover();

            //assert
            Assert.AreEqual("1 3 N", map.ToString().Replace("\n", string.Empty));
        }
        public void Discover_WhenRoverIs3n3_2EPatternIsMMRMMRMRRM_ShouldLastPositionIs5_1_E()
        {
            //arrange
            var directions = new List <DirectionType>()
            {
                DirectionType.Move,
                DirectionType.Move,
                DirectionType.Right,
                DirectionType.Move,
                DirectionType.Move,
                DirectionType.Right,
                DirectionType.Move,
                DirectionType.Right,
                DirectionType.Right,
                DirectionType.Move
            };
            MarsMap map = GetMap(3, 3, new EastCardinalPoint(), directions);

            //act
            map.Discover();

            //assert
            Assert.AreEqual("5 1 E", map.ToString().Replace("\n", string.Empty));
        }
    static void Main(string[] args)
    {
        MarsMap marsMap = new MarsMap();

        string[] inputs;
        int      surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars.

        for (int i = 0; i < surfaceN; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999)
            int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.

            marsMap.AddPoint(landX, landY);
        }

        // desired horizontal speed
        int horizontalMaxSpeed     = 60;
        int horizontalCruiseSpeed  = 40; // for getting above landing zone
        int horizontalLandingSpeed = 19; // for landing

        // desired vertical speed
        int verticalMaxSpeed     = 10;   // for getting above landing zone
        int verticalLandingSpeed = 38;   // for landing

        int safeHeightAboveGround = 200; // we shouldn't go lower unless touching down

        int horizontalMoveDefaultAngle    = 20;
        int horizontalEmergencyBrakeAngle = 45;

        // game loop
        while (true)
        {
            int newAngle = 0;
            int newPower = 0;

            inputs = Console.ReadLine().Split(' ');
            int X      = int.Parse(inputs[0]);
            int Y      = int.Parse(inputs[1]);
            int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative.
            int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative.
            int fuel   = int.Parse(inputs[4]); // the quantity of remaining fuel in liters.
            int rotate = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90).
            int power  = int.Parse(inputs[6]); // the thrust power (0 to 4).

            Position  currentPosition = new Position(X, Y);
            Direction cruiseDirection = marsMap.GetDirectionToLandingZone(currentPosition);
            Position  nextPeak        = marsMap.GetNextPeak(currentPosition, cruiseDirection);

            int directionalSpeed = hSpeed * (int)cruiseDirection;
            int directionalAngle = rotate * -(int)cruiseDirection;

            bool aboveLandingZone = marsMap.AboveLandingZone(currentPosition);

            int currentHorizLimit = aboveLandingZone ? horizontalLandingSpeed : horizontalMaxSpeed;
            int currentVertLimit  = aboveLandingZone ? verticalLandingSpeed : verticalMaxSpeed;

            bool touchMode       = aboveLandingZone && marsMap.HeightAboveLanding(currentPosition) < safeHeightAboveGround && directionalSpeed <= currentHorizLimit;
            bool dungerousHeight = (currentPosition.Height - nextPeak.Height < safeHeightAboveGround);

            Console.Error.WriteLine("directionalSpeed: " + directionalSpeed);
            Console.Error.WriteLine("cruiseDirection: " + cruiseDirection);
            Console.Error.WriteLine("directionalAngle: " + directionalAngle);
            Console.Error.WriteLine("dungerousHeight: " + dungerousHeight);

            if (touchMode)
            {
                newAngle = 0;
                newPower = (-vSpeed > currentVertLimit) ? 4: 3;
                Console.Error.WriteLine("Current mode: TOUCH");
            }
            else if (dungerousHeight) // need to get UP
            {
                newAngle = 0;
                newPower = 4;
                Console.Error.WriteLine("Current mode: UP - Height");
            }
            else if (directionalSpeed < 0 || directionalSpeed > currentHorizLimit) // emergency brake
            {
                bool highPriorityBrake = directionalSpeed <0 || directionalSpeed> horizontalMaxSpeed;
                newAngle = horizontalEmergencyBrakeAngle * (int)cruiseDirection * (directionalSpeed < 0 ? -1 : 1) / (highPriorityBrake ? 1 : 2);

                if (directionalAngle > 60)
                {
                    newPower = 0; // we really don't need more speed
                }
                else
                {
                    newPower = 4;
                }

                Console.Error.WriteLine("Current mode: BRAKE");
            }
            else if (-vSpeed > currentVertLimit) // need to get UP
            {
                newAngle = 0;
                newPower = 4;
                Console.Error.WriteLine("Current mode: UP - vert speed");
            }
            else if (!aboveLandingZone && directionalSpeed < horizontalCruiseSpeed) // cruising to landing zone
            {
                newAngle = horizontalMoveDefaultAngle * -(int)cruiseDirection / (dungerousHeight ? 2 : 1);
                newPower = 4;
                Console.Error.WriteLine("Current mode: CRUISE");
            }
            else // above landing with a height to spare or in cruise
            {
                newAngle = 0;
                if (Math.Abs(rotate) < 45)
                {
                    newPower = 2;
                }
                else
                {
                    newPower = 0;
                }

                Console.Error.WriteLine("Current mode: DESCENT");
            }

            // rotate power. rotate is the desired rotation angle. power is the desired thrust power.
            // To debug: Console.Error.WriteLine("Debug messages...");
            Console.WriteLine(newAngle + " " + newPower);
        }
    }
Exemple #13
0
 public Navigate(Compass direction, int positionY, int positionX)
 {
     _axis      = new Axis(positionY, positionX);
     _direction = new Direction(direction);
     _marsMap   = new MarsMap();
 }
        public void SetUp()
        {
            Point point = new MarsPoint(5, 5);

            _map = new MarsMap(point);
        }