Exemplo n.º 1
0
def results_of_guess(codewords, game):
    """
    This method shows the human player keywords based on how the computer player has evaluated
    their guess. It also shows how many guesses the human player has used so far.
    """

    # Before giving feedback on the latest guess, the computer checks to see if the human won.

    lowercase_codewords = []
    for word in codewords:
        lowercase_codewords.append(word.lower())

    if bagels.did_player_win(lowercase_codewords, new_game.digits):
        you_win()
        sys.exit()
    else:

        # Rather than display codewords in the order they're originally added to the list,
        # we want to list any "Pico" responses first and then any "Fermi" responses. This is
        # the traditional Bagels order and it makes it harder for the human player to guess.

        codewords.sort(reverse=True)
        print " ".join(codewords)

        if new_game.number_of_guesses == 1:
            print "So far, you've made 1 guess."
        else:
            print "So far, you've made {} guesses.".format(
                new_game.number_of_guesses)
Exemplo n.º 2
0
def results_of_guess(codewords, game):
    """
    This method shows the human player keywords based on how the computer player has evaluated
    their guess. It also shows how many guesses the human player has used so far.
    """

    # Before giving feedback on the latest guess, the computer checks to see if the human won.

    lowercase_codewords = []
    for word in codewords:
        lowercase_codewords.append(word.lower())

    if bagels.did_player_win(lowercase_codewords, new_game.digits):
        you_win()
        sys.exit()
    else:

        # Rather than display codewords in the order they're originally added to the list,
        # we want to list any "Pico" responses first and then any "Fermi" responses. This is
        # the traditional Bagels order and it makes it harder for the human player to guess.

        codewords.sort(reverse=True)
        print " ".join(codewords)

        if new_game.number_of_guesses == 1:
            print "So far, you've made 1 guess."
        else:
            print "So far, you've made {} guesses.".format(new_game.number_of_guesses)
Exemplo n.º 3
0
def computer_guessing_game():
    """
    The whole process of a computer player guessing a number is contained in this method.
    """
    try:
        number_of_digits = int(
            raw_input("""Do you want me to guess a 3 digit number? 4? 5?
                Less than 3 isn't fun. And you can't pick more than 9 digits. You just can't, okay? >> """
                      ))
        new_game = bagels.Game("computer", number_of_digits)
        computer_player = bagels.ComputerPlayer(number_of_digits)
    except ValueError:
        print "Okay, whatever, 3 digits is good."
        new_game = bagels.Game("computer", 3)
        computer_player = bagels.ComputerPlayer(3)
    computer_player.computer_guess()
    codewords = []

    while bagels.did_player_win(codewords, new_game.digits) is False:
        computer_player.number_of_guesses += 1
        codewords = compare_computer_guess(computer_player)

        # Making sure the computer can read user codewords if they use commas.

        codewords_sans_commas = []
        for word in codewords:
            if "," in word:
                word = word.replace(',', '')
                codewords_sans_commas.append(word)
            else:
                codewords_sans_commas.append(word)
        codewords = codewords_sans_commas
        try:
            computer_player.computer_guess(codewords)
        except IndexError:
            raw_input(
                "Hey, you either forgot your number or you're cheating. That's impossible! >> "
            )
            print "Come back when you're ready to play for real."
            sys.exit()
    print "Yay! I won! And it only took me {} guesses.".format(
        computer_player.number_of_guesses)
Exemplo n.º 4
0
def computer_guessing_game():
    """
    The whole process of a computer player guessing a number is contained in this method.
    """
    try:
        number_of_digits = int(raw_input("""Do you want me to guess a 3 digit number? 4? 5?
                Less than 3 isn't fun. And you can't pick more than 9 digits. You just can't, okay? >> """))
        new_game = bagels.Game("computer", number_of_digits)
        computer_player = bagels.ComputerPlayer(number_of_digits)
    except ValueError:
        print "Okay, whatever, 3 digits is good."
        new_game = bagels.Game("computer", 3)
        computer_player = bagels.ComputerPlayer(3)
    computer_player.computer_guess()
    codewords = []

    while bagels.did_player_win(codewords, new_game.digits) is False:
        computer_player.number_of_guesses += 1
        codewords = compare_computer_guess(computer_player)

        # Making sure the computer can read user codewords if they use commas.

        codewords_sans_commas = []
        for word in codewords:
            if "," in word:
                word = word.replace(',', '')
                codewords_sans_commas.append(word)
            else:
                codewords_sans_commas.append(word)
        codewords = codewords_sans_commas
        try:
            computer_player.computer_guess(codewords)
        except IndexError:
            raw_input("Hey, you either forgot your number or you're cheating. That's impossible! >> ")
            print "Come back when you're ready to play for real."
            sys.exit()
    print "Yay! I won! And it only took me {} guesses.".format(computer_player.number_of_guesses)
Exemplo n.º 5
0
def did_player_win_test():
    assert bagels.did_player_win(["fermi", "fermi", "fermi"], 3) is True
Exemplo n.º 6
0
def did_player_win_test():
    assert bagels.did_player_win(["fermi", "fermi", "fermi"], 3) is True