コード例 #1
0
    def turn_control(self):
        # TODO: Give this a good cleaning
        self.phase = utterances.UTT_GREET
        turns = 1
        talking = True
        either = [self.ai, self.pl]
        while talking:
            # For now we'll just time conversations
            if turns > 1:
                self.phase = utterances.UTT_Q
            elif turns > 5:
                self.phase = utterances.UTT_PART
            elif turns > 6:
                talking = False

            # Choose a random person to go first
            random.shuffle(either)
            self.first, self.second = either

            # Do a set of turns.
            if self.first == self.ai:
                self.ai_turn()
                self.pl_turn()
                if utterances.coherent(self.phase, self.ai_said, self.pl_said):
                    words = []
                    if isinstance(self.ai_said, utterances.Verbal):
                        words.extend(self.ai_said.word_array)
                    if isinstance(self.pl_said, utterances.Verbal):
                        words.extend(self.pl_said.word_array)
                    self.pl.learn_words(words)
                self.pl.encounter_utterance(self.ai_said)
            else:
                self.pl_turn()
                self.ai_turn()
                if utterances.coherent(self.phase, self.pl_said, self.ai_said):
                    words = []
                    if isinstance(self.ai_said, utterances.Verbal):
                        words.extend(self.ai_said.word_array)
                    if isinstance(self.pl_said, utterances.Verbal):
                        words.extend(self.pl_said.word_array)
                    self.pl.learn_words(words)
                self.pl.encounter_utterance(self.ai_said)

            turns += 1

        self._destruct()
コード例 #2
0
ファイル: characters.py プロジェクト: nichdel/Strangerland
 def choose_utterance(self, phase, prompt=None):
     # TODO: This works, but it's messy, clean it up.
     if prompt is not None:
         if not utterances.coherent(phase, prompt):
             options = utterances.filter_utts(utype=utterances.UTT_CONF)
             return random.choice(options)
     if phase == utterances.UTT_GREET:
         options = utterances.filter_utts(utype=utterances.UTT_GREET)
     elif phase == utterances.UTT_PART:
         options = utterances.filter_utts(utype=utterances.UTT_PART)
     else:
         if prompt is None:
             options = utterances.filter_utts(utterances.UTT_Q)
         else:
             for key in self.traits:
                 if isinstance(self.traits[key], prompt.prompts_for):
                     options = utterances.filter_utts(responds_with=self.traits[key])
     return random.choice(options)