Exemple #1
0
        public ParsedRoverCommand(string initializer, string mission)
        {
            var commands = initializer.Split(' ')
                           .Select(z => z.Trim())
                           .ToArray();

            if (commands.Length != 3)
            {
                Error = ErrorCode.Command_Parse;
                return;
            }

            if (mission.Any(c => !MISSION_PARSABLE_CHARS.Contains(c)))
            {
                Error = ErrorCode.Command_Parse;
                return;
            }

            Start   = new Coordinant($"{commands[0]} {commands[1]}");
            Mission = mission;

            var heading = Heading;

            if (commands[2].Length != 1 || !Enum.TryParse(commands[2], out heading))
            {
                Error = ErrorCode.Command_Parse;
            }
            Heading = heading;
        }
Exemple #2
0
        public ParsedMissionCommand(string[] commands)
        {
            var commandLines = commands.Select(z => z.Trim()).ToArray();

            //One line header and 2 lines per drone command
            if (commandLines.Length < 3 || commandLines.Length % 2 == 0)
            {
                Error = ErrorCode.Command_Parse;
                return;
            }

            try
            {
                Bounds = new Coordinant(commandLines[0]);
                var missions = new List <IRoverCommand>();
                for (var i = 1; i < commandLines.Length; i += 2)
                {
                    var newRoverMission = new ParsedRoverCommand(commandLines[i], commandLines[i + 1]);
                    if (newRoverMission.Error.HasValue)
                    {
                        this.Error = newRoverMission.Error;
                        return;
                    }

                    missions.Add(newRoverMission);
                }

                RoverMissions = missions;
            }
            catch (Exception)
            {
                Error = ErrorCode.Command_Parse;
            }
        }
Exemple #3
0
 public MissionResponse(Coordinant end, Directionality heading)
 {
     _end     = end;
     _heading = heading;
 }
Exemple #4
0
 public DebugResponse(Coordinant end, Directionality heading, ErrorCode errorCode)
     : base(end, heading)
 {
     _errorCode = errorCode;
 }