def test_calculate_score_2(self):
     actual = pf.calculate_score(10, 3, CONSONANT)
     self.assertEqual(actual, 13)
 def test_calculate_score_3(self):
     actual = pf.calculate_score(10, 3, VOWEL)
     self.assertEqual(actual, 9)
 def test_calculate_score_1(self):
     actual = pf.calculate_score(0, 0, CONSONANT)
     self.assertEqual(actual, 0)
def play_game(puzzle: str, view: str, game_type: str) -> None:
    """Prompt the player(s) to try to guess the puzzle. game_type is one of
    HUMAN, HUMAN_HUMAN, or HUMAN_COMPUTER.
    Return whether there was a winner and the final score.
    """

    player_one_score = 0
    player_two_score = 0
    current_player = PLAYER_ONE

    # The player move choice; will be one of CONSONANT, VOWEL,
    # SOLVE and QUIT.
    move_type = ''

    # The letters that have not yet been guessed.
    unguessed_consonants = CONSONANTS
    unguessed_vowels = VOWELS

    # This is None if there is no computer player.
    difficulty = select_computer_difficulty(game_type)

    # Note: you may find it helpful to display the solution while you
    # are testing. To do this, uncomment the following line:
    #print('Solution: {0}'.format(puzzle))

    while not pf.game_over(puzzle, view, move_type):
        quantity = 0
        if current_player == PLAYER_ONE:
            score = player_one_score
        else:
            score = player_two_score

        # Set up function aliases based on whether it's a human's turn or a
        # computer's turn.
        if is_human(current_player, game_type):
            get_move = get_player_move
            get_guess = get_player_guess
            get_letter = get_player_letter
        else:
            get_move = get_computer_move
            get_guess = get_computer_guess
            get_letter = get_computer_letter

        move_type = get_move(current_player, view, difficulty, \
            score, unguessed_consonants, unguessed_vowels)

        if move_type == SOLVE:

            if get_guess(view) == puzzle:
                #newview = puzzle
                score = finalize_score(puzzle, view, \
                    unguessed_consonants, score)
                #view = newview
                view = puzzle
            else:
                print("The guess '{0}' is Incorrect :-(".format(
                    get_guess(view)))

        elif move_type == CONSONANT or move_type == VOWEL:

            letter = get_letter(unguessed_consonants, unguessed_vowels,
                                move_type, difficulty)

            quantity = puzzle.count(letter)
            view = update_view(puzzle, view, letter)
            score = pf.calculate_score(score, quantity, move_type)
            unguessed_consonants, unguessed_vowels = make_guessed(
                unguessed_consonants, unguessed_vowels, letter)

            print('The guess was {0}, which occurs {1} time(s).  '\
                  .format(letter, quantity), end='')
            print('Your score is {0}.'.format(score))


            player_one_score, player_two_score = update_score(player_one_score,\
             player_two_score, score, current_player)

        if game_type != HUMAN:
            current_player = pf.next_player(current_player, quantity)

    # The game is over.
    display_outcome(pf.is_win(view, puzzle), score)
Esempio n. 5
0
assert isinstance(result, bool), \
       """puzzler_functions.bonus_letter should return a bool, but returned {0}.""" \
       .format(type(result))
print('  check complete')

# Type check puzzler_functions.update_letter_view
print('Checking update_letter_view...')
result = pf.update_letter_view('apple', 'a^^l^', 2, 'x')
assert isinstance(result, str), \
       """puzzler_functions.update_letter_view should return a str, but returned {0}.""" \
       .format(type(result))
print('  check complete')

# Type check pf.calculate_score
print('Checking calculate_score...')
result = pf.calculate_score(4, 2, pf.CONSONANT)
assert isinstance(result, int), \
       """pf.calculate_score should return an int, but returned {0}.""" \
       .format(type(result))
print('  check complete')

# Type check pf.next_player
print('Checking next_player...')
result = pf.next_player(pf.PLAYER_ONE, 2)
assert isinstance(result, str), \
       """pf.next_player should return a str, but returned {0}.""" \
       .format(type(result))
print('  check complete')
print(
    "================= End: checking parameter and return types =================\n"
)
Esempio n. 6
0
def play_game(puzzle, view, game_type):
    """(str, str, str) -> (bool, int)

    Prompt the player(s) to try to guess the puzzle. game_type is one of
    pf.HUMAN, pf.HUMAN_HUMAN, or pf.HUMAN_COMPUTER.
    Return whether there was a winner and the final score.
    """

    player_one_score = 0
    player_two_score = 0
    current_player = pf.PLAYER_ONE

    # The player move choice; will be one of pf.CONSONANT, pf.VOWEL,
    # pf.SOLVE and pf.QUIT.
    move_type = ''

    # The letters that have not yet been guessed.
    unguessed_consonants = pf.CONSONANTS
    unguessed_vowels = pf.VOWELS

    # This is None if there is no computer player.
    difficulty = select_computer_difficulty(game_type)

    # Note: you may find it helpful to display the solution while you
    # are testing. To do this, uncomment the following line:
    #print('Solution: {0}'.format(puzzle))

    while not pf.game_over(puzzle, view, move_type):
        quantity = 0
        if current_player == pf.PLAYER_ONE:
            score = player_one_score
        else:
            score = player_two_score

        # Set up function aliases based on whether it's a human's turn or a
        # computer's turn.
        if is_human(current_player, game_type):
            get_move = get_player_move
            get_guess = get_player_guess
            get_letter = get_player_letter
        else:
            get_move = get_computer_move
            get_guess = get_computer_guess
            get_letter = get_computer_letter

        move_type = get_move(current_player, view, difficulty,
            score, unguessed_consonants, unguessed_vowels)

        if move_type == pf.SOLVE:
            guess = get_guess(view)

            if guess == puzzle:
                newview = puzzle
                score = pf.finalize_score(puzzle, view,
                    unguessed_consonants, score)
                view = newview
            else:
                print("The guess '{0}' is Incorrect :-(".format(guess))

        elif move_type == pf.CONSONANT or move_type == pf.VOWEL:

            letter = get_letter(
                unguessed_consonants, unguessed_vowels, move_type, difficulty)

            quantity = puzzle.count(letter)
            view = pf.update_view(puzzle, view, letter)
            score = pf.calculate_score(score, quantity, move_type)
            unguessed_consonants, unguessed_vowels = pf.make_guessed(
                unguessed_consonants, unguessed_vowels, letter)

            print('The guess was {0}, which occurs {1} time(s).  '\
                  .format(letter,quantity), end='')
            print('Your score is {0}.'.format(score))
            

            player_one_score, player_two_score = pf.update_score(
                              player_one_score, player_two_score,
                              score, current_player)

        if game_type != pf.HUMAN:
            current_player = pf.next_player(current_player, quantity)

    # The game is over.
    display_outcome(pf.is_win(view, puzzle), score)
Esempio n. 7
0
       """pf.update_view should return a str, but returned {0}.""" \
       .format(type(result))


# Type check pf.make_guessed
result = pf.make_guessed('jklmn', 'aeo', 'm')
assert isinstance(result, tuple) \
       and isinstance(result[0], str) \
       and isinstance(result[1], str), \
       """pf.make_guessed should return a tuple of (str, str),
but returned {0}.""" \
       .format(type(result))


# Type check pf.calculate_score
result = pf.calculate_score(4, 2, pf.CONSONANT)
assert isinstance(result, int), \
       """pf.calculate_score should return an int, but returned {0}.""" \
       .format(type(result))

# Type check pf.finalize_score
result = pf.finalize_score('apple', 'a^^l^', 'ghjklpq', 4)
assert isinstance(result, int), \
       """pf.finalize_score should return an int, but returned {0}.""" \
       .format(type(result))

# Type check pf.update_score
result = pf.update_score(2, 3, 4, pf.PLAYER_ONE)
assert isinstance(result, tuple)  \
       and isinstance(result[0], int) \
       and isinstance(result[1], int), \