コード例 #1
0
        private CommandResult BatchCommand(BatchInstructions command)
        {
            StringBuilder res = new StringBuilder();
            IGrid <CoordinateBase, DirectionBase> grid = null;
            IRobot robot = null;

            //TODO check for consistency robot initialization with next command for it
            //should not be a problem if overall command format is right even if there are local errors in single command
            foreach (var myString in command.Batch.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (Regex.IsMatch(myString, @"^[a-zA-Z]+$"))
                {
                    //skip or cut? for consistency skip was choosen
                    if (myString.Length <= _settingsOption.MaxRobotCommandLength && robot != null)
                    {
                        //TODO Refactor for incapsulated choosing command type
                        for (int i = 0; i < myString.Length; ++i)
                        {
                            if (myString[i] == 'L' || myString[i] == 'R')
                            {
                                if (!RobotTurn(myString[i].ToString(), robot))
                                {
                                    break;
                                }
                                else
                                if (!RobotMove(myString[i].ToString(), robot))
                                {
                                    break;
                                }
                            }
                        }

                        res.AppendLine(robot.ToString());
                    }
                }
                else
                {
                    if (myString.Length == 2)
                    {
                        grid = GridInitialize(myString);
                    }

                    if (myString.Length == 3 && grid != null)
                    {
                        robot = RobotActivate(myString, grid);
                    }
                }
            }

            return(new CommandResult {
                Result = res.ToString()
            });
        }
コード例 #2
0
 //GRPC message size limit setting is 4Mb by default, we should remember that in case of huge batch
 public override Task <CommandResult> BatchCommand(BatchInstructions command, ServerCallContext context)
 {
     return(Task.FromResult(BatchCommand(command)));
 }