def test_next_player_3(self): actual = pf.next_player(PLAYER_TWO, 3) self.assertEqual(actual, PLAYER_TWO)
def test_next_player_4(self): actual = pf.next_player(PLAYER_TWO, 0) self.assertEqual(actual, PLAYER_ONE)
def test_next_player_1(self): actual = pf.next_player(PLAYER_ONE, 3) self.assertEqual(actual, PLAYER_ONE)
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)
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" ) print( "================= Start: checking whether constants are unchanged =================" ) # Get the final values of the constants constants_after = [ pf.DATA_FILE, pf.VOWEL_PRICE, pf.CONSONANT_BONUS, pf.CONSONANT_POINTS,
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)
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), \ """pf.update_score should return a tuple of (int, int), but returned {0}.""" \ .format(type(result)) # Type check pf.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)) # Type check pf.guess_letter result = pf.guess_letter('bcd', pf.HARD) assert isinstance(result, str), \ """pf.guess_letter should return a str, but returned {0}.""" \ .format(type(result)) # Type check pf.half_revealed result = pf.half_revealed('a^^l^') assert isinstance(result, bool), \ """pf.half_revealed should return a bool, but returned {0}.""" \ .format(type(result))