public void AddRoversToPlateauAndTestForCollissions()
        {
            Plateau.SetPlateauBounds(10, 10);

            var positionA = new Position(5, 5);
            var headingA = new Heading('N');
            var pathA = new List<char> {'M', 'M'};
            var roverA = new Rover(positionA, headingA, new Guid(), pathA);

            var positionB = new Position(4, 4);
            var headingB = new Heading('N');
            var pathB = new List<char> {'M', 'M'};
            var roverB = new Rover(positionB, headingB, new Guid(), pathB);

            var positionC = new Position(3, 3);
            var headingC = new Heading('N');
            var pathC = new List<char> {'M', 'M'};
            var roverC = new Rover(positionC, headingC, new Guid(), pathC);

            var positionD = new Position(2, 2);

            Plateau.AddRoverToPosition(positionA, roverA);
            Plateau.AddRoverToPosition(positionB, roverB);
            Plateau.AddRoverToPosition(positionC, roverC);

            Plateau.RoverAtPosition(positionA).Should().BeTrue();
            Plateau.RoverAtPosition(positionB).Should().BeTrue();
            Plateau.RoverAtPosition(positionC).Should().BeTrue();
            Plateau.RoverAtPosition(positionD).Should().BeFalse();
        }
        public static IEnumerable<RoverPath> Parse(List<string> instructions)
        {
            var bounds = instructions[0].Split(' ');
            int boundsX;
            int boundsY;

            int.TryParse(bounds[0], out boundsX);
            int.TryParse(bounds[1], out boundsY);
            Plateau.SetPlateauBounds(boundsX, boundsY);

            for (var i = 1; i < instructions.Count; i += 2)
            {
                var currentInstruction = instructions[i].Split(' ');
                var x = int.Parse(currentInstruction[0]);
                var y = int.Parse(currentInstruction[1]);
                var heading = char.Parse(currentInstruction[2]);

                var startPosition = new Position(x, y);
                var startHeading = new Heading(heading);
                var path = instructions[i + 1];

                var roverPath = new RoverPath(startPosition, startHeading, path);
                RoverPathList.Add(roverPath);
            }
            return RoverPathList;
        }
Esempio n. 3
0
        // path shouldn't be part of the constructor, the rover can exist without it

        // convert _path to an enum to reduce the possible valid ideas
        // extension methods 

        public Rover(Position position, Heading heading, Guid id, List<char> path)
        {
            // generate id within this class
            _id = id;
            Position = position;
            _heading = heading;
            _path = path;
        }
Esempio n. 4
0
        public RoverPath(Position startPosition, Heading startHeading, string movementInstructions)
        {
            _startHeading = startHeading;
            _startPosition = startPosition;

            foreach (var move in movementInstructions)
            {
                _movementInstructions.Add(move);
            }
        }
Esempio n. 5
0
 public static bool RoverAtPosition(Position newRoverPosition)
 {
     var roverCrashed = false;
     foreach (var existingRoverPosition in RoverPositions)
     {
         if (!newRoverPosition.PositionIsDisctinct(existingRoverPosition.Key))
         {
             roverCrashed = true;
         }
     }
     return roverCrashed;
 }
Esempio n. 6
0
        public void CreateRoversAndGetPositionsAndHeadings()
        {
            var positionA = new Position(5, 5);
            var headingA = new Heading('N');
            var pathA = new List<char> { 'M', 'M' };
            var roverA = new Rover(positionA, headingA, new Guid(), pathA);

            var positionB = new Position(4, 4);
            var headingB = new Heading('S');
            var pathB = new List<char> { 'M', 'M' };
            var roverB = new Rover(positionB, headingB, new Guid(), pathB);

            roverA.GetHeading().Should().Be('N');
            roverB.Position.ShouldBeEquivalentTo(new Position(4, 4));
        }
        public void CreateRoverPaths()
        {
            var positionA = new Position(5, 5);
            var headingA = new Heading('N');
            var pathA = "MMRLMM";
            var roverPathA = new RoverPath(positionA, headingA, pathA);

            var positionB = new Position(4, 4);
            var headingB = new Heading('S');
            var pathB = "MMMMMMM";
            var roverPathB = new RoverPath(positionB, headingB, pathB);

            roverPathA.GetStartHeading().GetHeading().ShouldBeEquivalentTo('N');
            roverPathA.GetStartPosition().ShouldBeEquivalentTo(new Position(5, 5));

            roverPathB.GetStartHeading().GetHeading().ShouldBeEquivalentTo('S');
            roverPathB.GetStartPosition().ShouldBeEquivalentTo(new Position(4, 4));

        }
Esempio n. 8
0
        public void MoveRover()
        {
            Plateau.SetPlateauBounds(10, 10);

            var positionA = new Position(5, 5);
            var headingA = new Heading('N');
            var pathA = new List<char> { 'M', 'M', 'L' };
            var roverA = new Rover(positionA, headingA, new Guid(), pathA);

            var successA = roverA.FollowPath();
            successA.Should().BeTrue();
            roverA.GetHeading().Should().Be('W');
            roverA.Position.ShouldBeEquivalentTo(new Position(5, 7));

            var positionB = new Position(4, 4);
            var headingB = new Heading('S');
            var pathB = new List<char> { 'M', 'M', 'M', 'M', 'M' };
            var roverB = new Rover(positionB, headingB, new Guid(), pathB);
            var successB = roverB.FollowPath();
            successB.Should().BeFalse();
            roverB.GetHeading().Should().Be('S');
            roverB.Position.ShouldBeEquivalentTo(new Position(4, -1));
        }
Esempio n. 9
0
 public static bool IsValidPosition(Position position)
 {
     return position.X <= _xSize && position.Y <= _ySize && position.X >= 0 && position.Y >= 0;
 }
Esempio n. 10
0
 public static void AddRoverToPosition(Position position, Rover rover)
 {
     RoverPositions.Add(position, rover);
 }