public bool Do(string input) { var command = parser.ParseCommand(input); if (IsRobotInUnknownState(command)) { return(false); } switch (command.Command) { case Command.Place: var parameter = (PlaceParameter)command.CommandParameter; if (tabletop.IsValidPosition(parameter.X, parameter.Y)) { robot.Place(parameter.X, parameter.Y, parameter.Direction); } else { return(false); } break; case Command.Move: var newPosition = robot.CalculateNextPosition(); if (tabletop.IsValidPosition(newPosition.X, newPosition.Y)) { robot.Place(newPosition.X, newPosition.Y, robot.CurrentDirection); } else { return(false); } break; case Command.Left: robot.Rotate(Rotation.Left); break; case Command.Right: robot.Rotate(Rotation.Right); break; case Command.Report: PrintReport(); break; } return(true); }