def test_is_win_2(self): actual = pf.is_win("banana", "banana") self.assertTrue(actual)
def test_is_win_1(self): actual = pf.is_win("apple", "app^e") self.assertFalse(actual)
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)
print( "================= Start: checking parameter and return types =================" ) import puzzler_functions as pf # Get the initial values of the constants constants_before = [ pf.DATA_FILE, pf.VOWEL_PRICE, pf.CONSONANT_BONUS, pf.CONSONANT_POINTS, pf.PLAYER_ONE, pf.PLAYER_TWO, pf.CONSONANT, pf.VOWEL, pf.SOLVE, pf.QUIT ] # Type check puzzler_functions.is_win print('Checking is_win...') result = pf.is_win('apple', 'about') assert isinstance(result, bool), \ """puzzler_functions.is_win should return a bool, but returned {0} .""".format(type(result)) print(' check complete') # Type check puzzler_functions.game_over print('Checking game_over...') result = pf.game_over('water', '^^te^', pf.CONSONANT) assert isinstance(result, bool), \ """puzzler_functions.game_over should return a bool, but returned {0}.""" \ .format(type(result)) print(' check complete') # Type check puzzler_functions.bonus_letter print('Checking bonus_letter...')
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)
When this module runs, if nothing is displayed and no errors occur, then the type checks passed. This means that the function parameters and return types match the assignment specification, but it does not mean that your code works correctly in all situations. Be sure to test your code before submitting.""" import puzzler_functions as pf # Get the initial values of the constants constants_before = [pf.DATA_FILE, pf.HIDDEN, pf.VOWEL_PRICE, pf.CONSONANT_BONUS, pf.HUMAN, pf.HUMAN_HUMAN, pf.HUMAN_COMPUTER, pf.EASY, pf.HARD, pf.PLAYER_ONE, pf.PLAYER_TWO, pf.CONSONANTS, pf.VOWELS, pf.CONSONANT, pf.VOWEL, pf.SOLVE, pf.QUIT, pf.PRIORITY_CONSONANTS] # Type check pf.is_win result = pf.is_win('apple', 'about') assert isinstance(result, bool), \ """pf.is_win should return a bool, but returned {0} .""".format(type(result)) # Type check pf.game_over result = pf.game_over('water', '^^te^', pf.CONSONANT) assert isinstance(result, bool), \ """pf.game_over should return a bool, but returned {0}.""" \ .format(type(result)) # Type check pf.get_view result = pf.get_view('happy') assert isinstance(result, str), \