tildebot | Accept alternative correct anagrams
Since this means there's multiple possible answers, I made it so that the answer can now be a function, and that gets run with the guess. This may open the door to other puzzle ideas that have been ignored due to having more than one correct answer.
This commit is contained in:
parent
f883cda857
commit
888b3e871a
|
@ -32,4 +32,15 @@ def get_anagram(maxlen = 6):
|
|||
if anagram != word:
|
||||
break
|
||||
puzzle = "Unscramble the following word: '" + anagram + "'"
|
||||
return [word, puzzle]
|
||||
|
||||
# Anagrams can have multiple answers, so we provide a check function that accepts all possibilities
|
||||
def answer_checker(guess):
|
||||
# Check for exact match
|
||||
if guess == word:
|
||||
return True
|
||||
# Bail out early if they didn't even use all the same letters
|
||||
if sorted(guess) != sorted(word):
|
||||
return False
|
||||
# Ok, gotta actually check if it's a word now
|
||||
return any(guess == item for item in get_wordlist())
|
||||
return [answer_checker, puzzle]
|
||||
|
|
|
@ -146,7 +146,7 @@ def challenge_response(channel, user, name, time, msg):
|
|||
print(msg);
|
||||
if(challenges.has_key(user)):
|
||||
answer, bonus = challenges[user]
|
||||
if(msg.lower() == str(answer).lower() or msg == p.number_to_words(answer)):
|
||||
if((callable(answer) and answer(msg.lower())) or (msg.lower() == str(answer).lower() or msg == p.number_to_words(answer))):
|
||||
give_tilde(channel, user, name, time, True, bonus);
|
||||
else:
|
||||
give_tilde(channel, user, name, time, False, 0);
|
||||
|
|
Loading…
Reference in New Issue