示例#1
0
def do_sprint(robot_name, steps):
    """
    Sprints the robot, i.e. let it go forward steps + (steps-1) + (steps-2) + .. + 1 number of steps, in iterations
    :param robot_name:
    :param steps:
    :return: (True, forward output)
    """
    if steps == 1:
        return world.do_forward(robot_name, 1)
    else:
        (do_next, command_output) = world.do_forward(robot_name, steps)
        print(command_output)
        return do_sprint(robot_name, steps - 1)
示例#2
0
def maze_move(path, robot_name):
    '''
    This function prints out the various movements the robot makes on 
    its way to the boundary of the maze. Keeping track of the direction index
    the function knows which direction function to execute.
    Param path: Is the list of the shortest routes coordinates.
    '''
    index = 0
    end = path[-1]
    while index < len(path) - 1:
        Fsteps = 0
        direction = getnextnodesdirection(path[index], path[index + 1])
        if direction == 1:
            print(world.do_right_turn(robot_name)[1])
        elif direction == 2:
            print(world.do_right_turn(robot_name)[1])
            print(world.do_right_turn(robot_name)[1])
        elif direction == 3:
            print(world.do_left_turn(robot_name)[1])
        while direction == 0:
            Fsteps += 1
            index += 1
            if path[index] == end:
                break
            direction = getnextnodesdirection(path[index], path[index + 1])
        if Fsteps > 0:
            print(world.do_forward(robot_name, Fsteps)[1])
示例#3
0
def call_command(command_name, command_arg, robot_name):
    if command_name == 'help':
        return do_help()
    elif command_name == 'forward':
        return world.do_forward(robot_name, int(command_arg))
    elif command_name == 'back':
        return world.do_back(robot_name, int(command_arg))
    elif command_name == 'right':
        return world.do_right_turn(robot_name)
    elif command_name == 'left':
        return world.do_left_turn(robot_name)
    elif command_name == 'sprint':
        return world.do_sprint(robot_name, int(command_arg))
    elif command_name == 'replay':
        return do_replay(robot_name, command_arg)
    return False, None
示例#4
0
def call_command(command_name, command_arg, robot_name):
    if command_name == 'help':
        return do_help()
    elif command_name == 'forward':
        if command_arg == '':
            return True, f"{robot_name}: Sorry, I did not understand '{command_name}''."
        return world.do_forward(robot_name, int(command_arg))
    elif command_name == 'back':
        if command_arg == '':
            return True, f"{robot_name}: Sorry, I did not understand '{command_name}''."
        return world.do_back(robot_name, int(command_arg))
    elif command_name == 'right':
        return world.do_right_turn(robot_name)
    elif command_name == 'left':
        return world.do_left_turn(robot_name)
    elif command_name == 'sprint':
        return world.do_sprint(robot_name, int(command_arg))
    elif command_name == 'replay':
        return do_replay(robot_name, command_arg)
    return False, None
示例#5
0
def call_command(command_name, command_arg, robot_name):
    """
    This determines what kind of command the user is giving to the robot
    """
    if command_name == 'help':
        return do_help()
    elif command_name == 'forward':
        return text_world.do_forward(robot_name, int(command_arg))
    elif command_name == 'back':
        return text_world.do_back(robot_name, int(command_arg))
    elif command_name == 'right':
        return text_world.do_right_turn(robot_name)
    elif command_name == 'left':
        return text_world.do_left_turn(robot_name)
    elif command_name == 'sprint':
        return text_world.do_sprint(robot_name, int(command_arg))
    elif command_name == 'replay':
        return do_replay(robot_name, command_arg)
    elif command_name == 'mazerun':
        return mazerun.start_mazerun(robot_name, command_arg)
    return False, None
示例#6
0
def call_command(command_name, command_arg, robot_name):
    '''
    Call command handles the robots commands and executes the various functions related
    with each paticular command.
    Param: command_name is the first part of the command i.e. forward
    Param: command_arg is the 2nd part of the command i.e. 5
    '''
    if command_name == 'help':
        return do_help()
    elif command_name == 'forward':
        return world.do_forward(robot_name, int(command_arg))
    elif command_name == 'back':
        return world.do_back(robot_name, int(command_arg))
    elif command_name == 'right':
        return world.do_right_turn(robot_name)
    elif command_name == 'left':
        return world.do_left_turn(robot_name)
    elif command_name == 'sprint':
        return do_sprint(robot_name, int(command_arg))
    elif command_name == 'replay':
        return do_replay(robot_name, command_arg)
    elif command_name == 'mazerun':
        return do_mazerun(robot_name, command_arg)
    return False, None