Пример #1
0
        public void RobotMovesOffGrid()
        {
            _grid = new Grid(30, 30);
            _coord = new Coordinate(0, 0);
            _robot = new Robot(_coord, Orientation.S, _grid);

            _robot.Move(Instruction.M, _grid);
        }
Пример #2
0
        public void FirstRobotMovementTest()
        {
            //1 2 N
            //LMLMLMLMM

            _grid = new Grid(5, 5);
            _robot = new Robot(new Coordinate(1, 2), Orientation.N, _grid);

            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.L, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.M, _grid);

            Assert.AreEqual(1, _robot.Pos.X);
            Assert.AreEqual(3, _robot.Pos.Y);
            Assert.AreEqual(Orientation.N, _robot.Or);
        }
Пример #3
0
        /**
         * Parse a moves line and apply the moves to the specified robot.
         */
        public void ParseMovesLine(string line, Robot r)
        {
            if (echo)
            {
                Console.WriteLine("Got a robot moves line of: " + line);
            }

            char[] chars = line.ToCharArray();

            for (int i = 0; i < chars.Length; i++)
            {
                r.Move(chars[i]);
            }

            Console.WriteLine("");
            Console.WriteLine("-----> Robot Final Position: " + r + " <-----");
            Console.WriteLine("");
        }
Пример #4
0
        static void Main(string[] args)
        {
            try
            {
                BattleArenaCreateCommand createArenaCommand = WaitForArenaCreation();
                BattleArena arena = new BattleArena(createArenaCommand.MaximumPositionX, createArenaCommand.MaximumPositionY);

                while (true)
                {
                    try
                    {
                        IRobotCreateCommand createRobotCommand = WaitForRobotCreationCommand();
                        IRobot currentlyControlledRobot        = new Robot(createRobotCommand.PositionX, createRobotCommand.PositionY, createRobotCommand.Orientation);
                        arena.AddRobot(currentlyControlledRobot);

                        IList <ICommand> robotCommands = WaitForRobotCommands(currentlyControlledRobot);
                        foreach (ICommand command in robotCommands)
                        {
                            if (command is IRobotTurnCommand)
                            {
                                IRobotTurnCommand turnCommand = command as IRobotTurnCommand;
                                currentlyControlledRobot = currentlyControlledRobot.Turn(turnCommand);
                            }
                            else if (command is IRobotMoveCommand)
                            {
                                currentlyControlledRobot = currentlyControlledRobot.Move();
                            }
                        }

                        Console.WriteLine(currentlyControlledRobot.ToString());
                    }
                    catch (Exception ex) when(ex is CollisionException)
                    {
                        WriteError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(ex);
            }
        }
Пример #5
0
 private static void IssueCommand(Robot robot, string commandInput)
 {
     foreach (var command in commandInput)
     {
         switch (command)
         {
             case 'L':
                 robot.TurnLeft();
                 break;
             case 'R':
                 robot.TurnRight();
                 break;
             case 'M':
                 robot.Move();
                 break;
             default:
                 throw new UnknownCommandException(command);
         }
     }
 }
Пример #6
0
        public void SecondRobotMovementTest()
        {
            //3 3 E
            //MMRMMRMRRM

            _robot = new Robot(new Coordinate(3, 3), Orientation.E, _grid);

            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.R, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.R, _grid);
            _robot.Move(Instruction.M, _grid);
            _robot.Move(Instruction.R, _grid);
            _robot.Move(Instruction.R, _grid);
            _robot.Move(Instruction.M, _grid);

            Assert.AreEqual(5, _robot.Pos.X);
            Assert.AreEqual(1, _robot.Pos.Y);
            Assert.AreEqual(Orientation.E, _robot.Or);
        }