示例#1
0
文件: puzzler.py 项目: z0k/CSC108
def get_computer_move(current_player, view, difficulty, score,
        unguessed_consonants, unguessed_vowels):
    """(int, int, str, str, int, str, str) -> str

    Return the computer's next move, which will be either to guess a
    pf.CONSONANT or to pf.SOLVE. The computer chooses to solve when difficulty
    is pf.HARD, at least half of the letters in the puzzle have been revealed
    and there is a valid guess (according to guess_puzzle), otherwise the
    computer opts to guess a pf.CONSONANT.

    This function and get_player_move must have the same type contract.
    current_player and unguessed_vowels are unused.
    """

    print('=' * 50)
    print('Computer, it\'s your turn. You have {0} points.'.format(
        score))
    print('\n' + view + '\n')
    print('[C]onsonant, [V]owel, [S]olve, [Q]uit: ')
    guess = get_computer_guess(view) 
    if (difficulty == pf.HARD and pf.half_revealed(view)
       and guess != '') or unguessed_consonants == '':
        print('The Computer chooses to try to solve.')
        print('The computer guesses "{0}"'.format(guess))
        return pf.SOLVE

    return pf.CONSONANT
示例#2
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))

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

# Get the final values of the constants
constants_after = [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,