public RobotCommandMessage(int robotID, RobotCommandType type, List <Vector2> waypoints, double angleWhenDone)
 {
     this.robotID  = robotID;
     Type          = type;
     Waypoints     = waypoints;
     AngleWhenDone = angleWhenDone;
 }
 public RobotCommandMessage(int robotID, RobotCommandType type, List<Vector2> waypoints, double angleWhenDone)
 {
     this.robotID = robotID;
     Type = type;
     Waypoints = waypoints;
     AngleWhenDone = angleWhenDone;
 }
Beispiel #3
0
        public List <DecodedInput> DecodeInput(string textToDecode)
        {
            List <string> splittedInputListByInt = Regex.Matches(textToDecode, @"\d+|\D+")
                                                   .Cast <Match>()
                                                   .Select(m => m.Value)
                                                   .ToList();

            if (splittedInputListByInt == null)
            {
                return(null);
            }

            bool             nextShouldBeNumber     = false;
            string           currentRotationPointer = "";
            var              decodedCommands        = new List <DecodedInput>();
            RobotCommandType robotCommandType       = RobotCommandType.Unknown;

            foreach (var item in splittedInputListByInt)
            {
                if (item == "L")
                {
                    nextShouldBeNumber     = true;
                    currentRotationPointer = "L";
                    robotCommandType       = RobotCommandType.Move;
                }
                else if (item == "R")
                {
                    nextShouldBeNumber     = true;
                    currentRotationPointer = "R";
                    robotCommandType       = RobotCommandType.Move;
                }
                else
                {
                    if (nextShouldBeNumber == true)
                    {
                        int number;

                        bool success = int.TryParse(item, out number);

                        if (success)
                        {
                            Console.WriteLine($"CMD:{currentRotationPointer}{number}");
                            decodedCommands.Add(new DecodedInput
                            {
                                OriginalCmd      = $"CMD:{currentRotationPointer}{number}",
                                MovementDistance = number,
                                RotationType     = currentRotationPointer == "L" ? RotationType.Left : RotationType.Right,
                                CommandType      = robotCommandType
                            });
                        }

                        nextShouldBeNumber = false;
                    }
                    currentRotationPointer = "";
                }
            }

            return(decodedCommands);
        }
 public RobotCommandMessage(int robotID, RobotCommandType type, List <Vector2> waypoints, RobotTwoWheelCommand directCmd,
                            double angleWhenDone, RobotState.RobotMode mode)
 {
     this.robotID  = robotID;
     Type          = type;
     Waypoints     = waypoints;
     DirectCmd     = directCmd;
     AngleWhenDone = angleWhenDone;
     Mode          = mode;
 }
        public RobotCommandMessage(int robotID, RobotCommandType type, List<Vector2> waypoints, RobotTwoWheelCommand directCmd,
			double angleWhenDone, RobotState.RobotMode mode)
        {
            this.robotID = robotID;
            Type = type;
            Waypoints = waypoints;
            DirectCmd = directCmd;
            AngleWhenDone = angleWhenDone;
            Mode = mode;
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ICommandRecorder    commandRecorder     = new CommandRecorder();
            RobotCommandHandler robotCammandHandler = new RobotCommandHandler(commandRecorder);
            RobotCommandType    drawingCommand      = RobotCommandType.None;

            Console.WriteLine("Welcome to the Mock Robot Interface:");
            Console.WriteLine("'Move' command will move Robot A. Syntax: M <Distance in Decimal number> Example: M 10.3");
            Console.WriteLine("'Turn' command will Turn Robot A. Syntax: T <Angle in Decimal number> Eg: T 45.8");
            Console.WriteLine("'Beep' command will Beep Robot A. Syntax: B");
            Console.WriteLine("'Replay' command will replay all the past commands sent to Robot A on Robot B. Syntax: R");
            Console.WriteLine("'Quit' command syntax not matched. Syntax: Q");
            do
            {
                IRobot robotA = new MockRobotA();
                IRobot robotB = new MockRobotB();
                IRobot robot;
                try
                {
                    Console.Write("Enter Command: ");
                    var commandStr = Console.ReadLine();
                    if (commandStr != null && commandStr.Trim().ToUpper() == "R")
                    {
                        robot = robotB;
                    }
                    else
                    {
                        robot = robotA;
                    }

                    drawingCommand = RobotCommandType.None;
                    try
                    {
                        drawingCommand = robotCammandHandler.Run(robot, commandStr);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            } while (drawingCommand != RobotCommandType.Quit);
            Console.WriteLine("Press a key to Quit");
            Console.ReadKey();
        }
        public IState Build(RobotCommandType commandType)
        {
            if (!Enum.IsDefined(typeof(RobotCommandType), commandType))
            {
                throw new NotImplementedException();
            }

            switch (commandType)
            {
            case RobotCommandType.Initialization:
                return(new InitializationState(_locationService));

            case RobotCommandType.Move:
                return(new MoveState(_locationService));

            case RobotCommandType.Unknown:
                break;
            }

            throw new NotImplementedException();
        }
 public RobotCommandMessage(int robotID, RobotCommandType type, RobotState.RobotMode mode)
 {
     this.robotID = robotID;
     Type         = type;
     Mode         = mode;
 }
 public RobotCommandMessage(int robotID, RobotCommandType type, RobotTwoWheelCommand cmd)
 {
     this.robotID = robotID;
     Type         = type;
     DirectCmd    = cmd;
 }
Beispiel #10
0
 public bool Supports(RobotCommandType commandType) => commandType == RobotCommandType.Report;
 public RobotCommandMessage(int robotID, RobotCommandType type, RobotState.RobotMode mode)
 {
     this.robotID = robotID;
     Type = type;
     Mode = mode;
 }
 public RobotCommandMessage(int robotID, RobotCommandType type, RobotTwoWheelCommand cmd)
 {
     this.robotID = robotID;
     Type = type;
     DirectCmd = cmd;
 }
 public void GivenSupports_WhenGivenCommandType_ThenOnlySupportsRight(RobotCommandType commandType, bool result)
 {
     _handler.Supports(commandType).Should().Be(result);
 }
Beispiel #14
0
        public void GivenTryParse_WhenInputIsEnum_ThenTrueAndCommandSet(string input, RobotCommandType commandType, string secondaryArgs)
        {
            var isParsed = _parser.TryParse(input, out var command);

            isParsed.Should().BeTrue();
            command.Should().NotBeNull();
            command.CommandType.Should().Be(commandType);
            command.SecondaryArguments.Should().Be(secondaryArgs);
        }
Beispiel #15
0
        /// <summary>
        /// This method is doing the actual logic of moving a Robot inside of Arena. It takes the ID of the robot and the movement type.
        /// </summary>
        /// <param name="id">Id of the robot</param>
        /// <param name="commandType">Command type that specify the movement</param>
        /// <returns></returns>
        public void Move(int id, RobotCommandType commandType)
        {
            if (_width == 0 || _height == 0)
            {
                throw new Exception("Arena is not initialized");
            }

            if (!_robots.ContainsKey(id))
            {
                throw new Exception($"Robot with id {id} doesn't exists");
            }

            Robot robot = _robots[id];

            switch (commandType)
            {
            case RobotCommandType.L:
                switch (robot.Orientation)
                {
                case RobotOrientation.N:
                    robot.Orientation = RobotOrientation.W;
                    break;

                case RobotOrientation.W:
                    robot.Orientation = RobotOrientation.S;
                    break;

                case RobotOrientation.E:
                    robot.Orientation = RobotOrientation.N;
                    break;

                case RobotOrientation.S:
                    robot.Orientation = RobotOrientation.E;
                    break;

                default:
                    break;
                }
                break;

            case RobotCommandType.R:
                switch (robot.Orientation)
                {
                case RobotOrientation.N:
                    robot.Orientation = RobotOrientation.E;
                    break;

                case RobotOrientation.W:
                    robot.Orientation = RobotOrientation.N;
                    break;

                case RobotOrientation.E:
                    robot.Orientation = RobotOrientation.S;
                    break;

                case RobotOrientation.S:
                    robot.Orientation = RobotOrientation.W;
                    break;

                default:
                    break;
                }
                break;

            case RobotCommandType.M:
                switch (robot.Orientation)
                {
                case RobotOrientation.N:
                    if (robot.Y + 1 >= _height)
                    {
                        throw new Exception("Robot cannot move to North, it is already at the limit");
                    }

                    robot.Y++;
                    break;

                case RobotOrientation.W:
                    if (robot.X == 0)
                    {
                        throw new Exception("Robot cannot move to West, it is already at the limit");
                    }

                    robot.X--;
                    break;

                case RobotOrientation.E:
                    if (robot.X + 1 >= _width)
                    {
                        throw new Exception("Robot cannot move to East, it is already at the limit");
                    }

                    robot.X++;
                    break;

                case RobotOrientation.S:
                    if (robot.Y == 0)
                    {
                        throw new Exception("Robot cannot move to South, it is already at the limit");
                    }

                    robot.Y--;
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }

            _robots[id] = robot; //setting here value since robot is struct
        }