Ejemplo n.º 1
0
def get_direction_calculate_score(puzzle, guess, current_player_name, words):
    """ (str, str, str, str, list of str) -> int

    Prompt for the direction and the row or column number.  Based on these
    answers and the number of words left to be found, calculate and return the
    appropriate score.
    """

    # Prompt for the direction.
    direction = None
    while direction not in ['up', 'down', 'forward', 'backward']:
        direction = input(
            current_player_name +
            ', enter the direction (up, down, forward, or backward): ')

    # Prompt for the row or column number, check whether the word occurs in
    # that row or column in the direction specified, and calculate the score.
    if direction == 'up' or direction == 'down':
        row_or_col_num = int(
            input('Enter the column number where ' + guess + ' occurs: '))
    elif direction == 'forward' or direction == 'backward':
        row_or_col_num = int(
            input('Enter the row number where ' + guess + ' occurs: '))

    words_left = len(words)

    return puzzle_functions.calculate_score(
        puzzle, direction, guess, row_or_col_num, words_left)
Ejemplo n.º 2
0
def get_direction_calculate_score(puzzle, guess, current_player_name, words):
    """ (str, str, str, str, list of str) -> int

    Prompt for the direction and the row or column number.  Based on these
    answers and the number of words left to be found, calculate and return the
    appropriate score.
    """

    # Prompt for the direction.
    direction = None
    while direction not in ['up', 'down', 'forward', 'backward']:
        direction = input(
            current_player_name +
            ', enter the direction (up, down, forward, or backward): ')

    # Prompt for the row or column number, check whether the word occurs in
    # that row or column in the direction specified, and calculate the score.
    if direction == 'up' or direction == 'down':
        row_or_col_num = int(
            input('Enter the column number where ' + guess + ' occurs: '))
    elif direction == 'forward' or direction == 'backward':
        row_or_col_num = int(
            input('Enter the row number where ' + guess + ' occurs: '))

    words_left = len(words)

    return puzzle_functions.calculate_score(
        puzzle, direction, guess, row_or_col_num, words_left)
Ejemplo n.º 3
0
       .format(type(result))

# Type check pf.get_factor
result = pf.get_factor('forward')
assert isinstance(result, int), \
       '''pf.get_factor should return an int, but returned {0}.''' \
       .format(type(result))


# Type check pf.get_points
result = pf.get_points('up', 7)
assert isinstance(result, int), \
       '''pf.get_points should return an int, but returned {0}.''' \
       .format(type(result))


# Type check pf.calculate_score
result = pf.calculate_score('abcd\nefgh\nijkl\n', 'forward', 'bcd', 2, 4)
assert isinstance(result, int), \
       '''pf.calculate_score should return an int, but returned {0}.''' \
       .format(type(result))

# Get the final values of the constants
constants_after = [pf.FORWARD_FACTOR, pf.DOWN_FACTOR, pf.BACKWARD_FACTOR,
                    pf.UP_FACTOR]
# Check whether the constants are unchanged.
assert constants_before == constants_after, \
       '''Your function(s) modified the value of a constant(s).
Edit your code so that the values of constants are unchanged by your functions.'''