Exemple #1
0
        public void GivenASetOfRobot_And_Movements_ShowOutput()
        {
            var movements = new List <PositionMove>();

            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 1, PositionY = 1, Orientation = Orientation.E
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotOne()
            });
            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 3, PositionY = 2, Orientation = Orientation.N
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotTwo()
            });
            movements.Add(new PositionMove
            {
                InitialPosition = new Position {
                    PositionX = 0, PositionY = 3, Orientation = Orientation.W
                },
                Movements = MoveCommand_Extensions.ExampleCommandsRobotThree()
            });


            var sut = new MarsBoardService();

            var result = sut.GetOutput(_marsGrid, movements);

            Assert.True(result.ToList().Count == 3);
            Assert.Collection(result,
                              item => Assert.True(item.Position.PositionX == 1 && item.Position.PositionY == 1 && item.Position.Orientation == Orientation.E),
                              item => Assert.True(item.IsLost && item.Scent.PositionX == 3 && item.Scent.PositionY == 3),
                              item => Assert.True(item.Position.PositionX == 2 && item.Position.PositionY == 3 && item.Position.Orientation == Orientation.S));
        }
        private static void TypeRobotMoves()
        {
            string maxCoordinateX, maxCoordinateY;
            var    marsGrid = BuildMarsGrid(out maxCoordinateX, out maxCoordinateY);

            var    positionMoves      = new List <PositionMove>();
            int    robotNumber        = 1;
            string defaultOrientation = "N";

            while (true)
            {
                var robotPosition = new Position();
                do
                {
                    Console.WriteLine($"Type position X of the Robot {robotNumber} and press enter");
                    string positionX = Console.ReadLine();
                    Console.WriteLine($"Type position Y of the Robot {robotNumber} and press enter");
                    string positionY = Console.ReadLine();
                    Console.WriteLine($"Type Orientation N, S, E, W of the Robot {robotNumber} press enter");
                    string orientation = Console.ReadLine();

                    robotPosition.PositionX = int.Parse(positionX);
                    robotPosition.PositionY = int.Parse(positionY);

                    if (!Enum.IsDefined(typeof(Orientation), orientation))
                    {
                        orientation = defaultOrientation;
                    }
                    robotPosition.Orientation = (Orientation)Enum.Parse(typeof(Orientation), orientation, true);
                } while (!robotPosition.IsValid(marsGrid));

                Console.WriteLine($"Type set of robot moves R L or F (for example FFRLFFL) of the Robot {robotNumber} and press enter");
                string moves = Console.ReadLine();

                var moveCommands = new MoveConverter().Convert(moves);
                positionMoves.Add(new PositionMove {
                    InitialPosition = robotPosition, Movements = moveCommands
                });

                Console.WriteLine($"Moves: {moves}");

                robotNumber++;

                Console.WriteLine($"More robots?? Press any key. If you want to finish press ESC");

                ConsoleKeyInfo info = Console.ReadKey();
                if (info.Key == ConsoleKey.Escape)
                {
                    break;
                }
                Console.WriteLine("--------------------------------------------");
            }

            var finalPositions = new MarsBoardService().GetOutput(marsGrid, positionMoves);

            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("FINAL OUTPUT:");
            Console.WriteLine("--------------------------------------------");
            foreach (var finalPosition in finalPositions)
            {
                Console.WriteLine(finalPosition.ToString());
            }
        }