Commit ac59ffd9 authored by Constantin Berhard's avatar Constantin Berhard

euclid => euclid+questionman

parent 80d2bd44
from npc import Npc
from questionman import Questionman
import random
def testQuestion(qpair):
q,ac = qpair
print(q)
a = input("> ")
print("Is correct: ",ac(a))
class Euclid (Npc):
class Euclid(Questionman):
questions = [
("Imagine there is a circle. The origin and the point (4,0) are on the circle. The circle is symmetric with respect to the line x=y. Where is its center? ", lambda x: "2,2" in ("".join(x.split())).strip("()[]{}")),
("In a rectangular triangle, if the two shortest sides have lengths 3 meters and 4 meters, how long is the longest side?", lambda x: "5m" in ("".join(x.split())).replace("meters","m").replace("meter","m")),
......@@ -18,42 +10,11 @@ class Euclid (Npc):
("What does a mine turtle have on its back?",lambda x: "button" in x.lower() or "trigger" in x.lower()),
]
class DLevel(Npc.DialogLevel):
def __init__ (self,euclid):
super().__init__(euclid)
self.question, self.answerChecker = random.choice(Euclid.questions)
self.questionAsked = False
def checkStandardRequests(self, teller, verb, message):
resp = super().checkStandardRequests(teller, verb, message)
if resp is not None:
assert len(resp) == 3
return resp
if not self.questionAsked:
self.questionAsked = True
return ("ask", self.question, None)
else:
if self.answerChecker(message):
# correct answer
self.npc.correctAnswerGiven = True
newq, newac = random.choice(Euclid.questions)
return ("say", "That answer is correct. I will go annoy people somewhere else. Good Bye.", Euclid.DLevel(self.npc))
else: # wrong answer
return ("shout", "WRONG! "+self.question, None)
def __init__(self,game):
super().__init__(game, Euclid.DLevel(self))
self.correctAnswerGiven = False
super().__init__(game)
def __str__ (self):
return "Euclid"
def __repr__ (self):
return "E"
def blocksMove(self):
return True
def afterAnswering(self):
if self.correctAnswerGiven:
self.correctAnswerGiven = False
self.relocate()
\ No newline at end of file
return "E"
\ No newline at end of file
from npc import Npc
import random
def testQuestion(qpair):
q,ac = qpair
print(q)
a = input("> ")
print("Is correct: ",ac(a))
class Questionman (Npc):
class DLevel(Npc.DialogLevel):
def __init__ (self,npc):
super().__init__(npc)
self.question, self.answerChecker = random.choice(self.npc.questions)
self.questionAsked = False
def checkStandardRequests(self, teller, verb, message):
resp = super().checkStandardRequests(teller, verb, message)
if resp is not None:
assert len(resp) == 3
return resp
if not self.questionAsked:
self.questionAsked = True
return ("ask", self.question, None)
else:
if self.answerChecker(message):
# correct answer
self.npc.correctAnswerGiven = True
newq, newac = random.choice(self.npc.questions)
return ("say", "That answer is correct. I will go annoy people somewhere else. Good Bye.", Questionman.DLevel(self.npc))
else: # wrong answer
return ("shout", "WRONG! "+self.question, None)
def __init__(self,game):
super().__init__(game, Questionman.DLevel(self))
self.correctAnswerGiven = False
def __str__ (self):
return "QuestionMan"
def __repr__ (self):
return "Q"
def blocksMove(self):
return True
def afterAnswering(self):
if self.correctAnswerGiven:
self.correctAnswerGiven = False
self.relocate()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment