Ejemplo n.º 1
0
    def initialize(self, length_count, length_to_word):
        self.guessed_letters = set()
        # initialize game state
        for letter in range(self.word_length):
            self.game_state.append('_')

        if self.multiplayer.lower() == 'y':
            # list of the word of such length to choose (print about 50 of them)
            print("Here are possible words of such length: ")
            if length_count[self.word_length] >= 50:
                print(length_to_word[self.word_length][:50])
            else:
                print(length_to_word[self.word_length])
            word = str(
                input("Please choose a word of length " +
                      str(self.word_length) + ": "))
            while len(word) != self.word_length or word not in length_to_word[
                    self.word_length]:
                word = str(
                    input("Invalid choice. Please choose a word of length " +
                          str(self.word_length) + ":"))
        else:
            ## create an AI to get a word of length based on level.
            self.level = str(
                input(
                    "Please choose a level (easy,intermediate,medium,hard): "))
            while self.level not in self.set_levels:
                self.level = str(
                    input(
                        "Please choose a proper level (easy,intermediate,medium,hard): "
                    ))
            # create an instant of AI_computer based on level
            self.computer = AI.AI_Computer(
                self.level,
                dictionary.Dictionary(length_to_word[self.word_length]))
            # choose a word using the level
            word = self.computer.choose_word()
            # print ("word:",word)
        self.word = word  # initial our word, it could be a bag of word from hard/ insane level
        if self.level != "hard":
            self.solver = AI.AI_solver()
        else:
            self.solver = AI.AI_hard_solver()
        self.solver.dic = dictionary.Dictionary(
            length_to_word[self.word_length]
        )  #  object initial our solver data as a dictionary