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);
        }
        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;
        }
Пример #3
0
        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));

        }