Changeset 247374662bf2…
Parent 169848b05f89…
by Benjamin Pollack
Changes to one file · Browse files at 247374662bf2 Showing diff from parent 169848b05f89 Diff from another changeset...
|
@@ -45,6 +45,9 @@ else:
self.questioner.advance_no()
+ def is_possible_answer(self):
+ False
+
class Thing(object):
"""represents a concrete thing that might be the right answer
@@ -68,15 +71,17 @@ """asks the user on the command line
You can use Determiner.question() to grab the question text,
- and manually call Questioner.mark_failed() or
- Questioner.mark_succeeded(), if you want to ask users
+ and manually call Questioner.advance_yes() or
+ Questioner.advance_no(), if you want to ask users
questions in other ways. This is here just for convenience.
"""
if ask(self.question()):
- self.questioner.mark_succeeded()
+ self.questioner.advance_yes()
else:
- self.questioner.mark_failed()
+ self.questioner.advance_no()
+ def is_possible_answer(self):
+ return True
class Questioner(object):
"""holds all knowledge in the universe as a form of yes/no questions
@@ -96,30 +101,28 @@ """returns the next question that you should ask
This will actually keep returning the same question until you
- tell the questioner to continue by calling advance_yes,
- advance_no, mark_succeeded, or mark_failed, as appropriate.
+ tell the questioner to continue by calling advance_yes or
+ advance_no, as appropriate.
"""
return self.current_question
def advance_yes(self):
- """tell the Questioner that his last Determiner was answered yes
-
- If the last question asked was actually a Thing, use
- mark_succeeded instead
- """
- self.last_branch = True
- self.last_question = self.current_question
- self.current_question = self.current_question.true_question
+ """tell the Questioner that his last Determiner was answered yes"""
+ if self.current_question.is_possible_answer():
+ self._solved = True
+ else:
+ self.last_branch = True
+ self.last_question = self.current_question
+ self.current_question = self.current_question.true_question
def advance_no(self):
- """tell the Questioner that his last Determiner was answered no
-
- If the last question asked was actually a Thing, use
- mark_failed instead
- """
- self.last_branch = False
- self.last_question = self.current_question
- self.current_question = self.current_question.false_question
+ """tell the Questioner that his last Determiner was answered no"""
+ if self.current_question.is_possible_answer():
+ self._failed = True
+ else:
+ self.last_branch = False
+ self.last_question = self.current_question
+ self.current_question = self.current_question.false_question
def out_of_ideas(self):
"""tell the user if we don't have any idea what they were thinking of"""
@@ -169,31 +172,13 @@ """
return self.current_question is not None
- def mark_succeeded(self):
- """tell the Questioner they succeeded
-
- Once you call this, the Questioner assumes they got it, even
- if they didn't, so don't call this unless the user's really
- gotten the right answer.
- """
- self._solved = True
-
- def mark_failed(self):
- """tell the Questioner they failed
-
- Once you call this, the Questioner assumes they messed up,
- even if they secretly actually really got it. Don't lie.
- It's not nice.
- """
- self._failed = True
-
def best_guess(self):
"""return our best guess, if we had one
This will only return something if we tried to guess a Thing.
Otherwise, it returns None.
"""
- if isinstance(self.current_question, Thing):
+ if self.current_question.is_possible_answer():
return self.current_question.what
def dump(self):
|
Loading...