another big diff. tested some things

This commit is contained in:
Ben Harris committed 2018-10-09 02:53:23 -04:00
1 parent 99cf1c5822
commit 649a56f6c2
17 files changed
+180 -553

No files matched your search

+12 -15
View File
@@ -7,8 +7,9 @@ dictionary = "/usr/share/dict/american-english-small"
BAD_WORDS_FILE = "badwords.txt"
def get_wordlist():
def gen_wordlist():
# I feel weird calling this "get_wordlist" when it's a generator without calling out that I do in fact realise it's weird - ~deltawitch
# how about gen_wordlist
with open(BAD_WORDS_FILE, "r") as fp:
bad_words = set(fp)
@@ -18,14 +19,11 @@ def get_wordlist():
def get_puzzle():
dict_words = list(get_wordlist())
dict_words = list(gen_wordlist())
words = random.sample(dict_words, 3)
key = random.randrange(0, 3) # get values 1-3
puzzle = (
"When alphebetized, what is the "
+ p.ordinal(p.number_to_words(key + 1))
+ " in "
+ ", ".join(words)
puzzle = "When alphebetized, what is the {} in {}?".format(
p.ordinal(p.number_to_words(key + 1)), ", ".join(words)
)
words.sort()
answer = words[key]
@@ -34,14 +32,12 @@ def get_puzzle():
def get_anagram(maxlen=6):
dict_words = [
word for word in get_wordlist() if len(word) > 2 and len(word) <= maxlen + 1
word for word in gen_wordlist() if len(word) > 2 and len(word) < maxlen + 1
]
word = random.choice(dict_words)
while True:
anagram = "".join(random.sample(word, len(word)))
if anagram != word:
break
puzzle = "Unscramble the following word: '" + anagram + "'"
anagram = list(word)
random.shuffle(anagram)
anagram = "".join(anagram)
# Anagrams can have multiple answers, so we provide a check function that accepts all possibilities
def answer_checker(guess):
@@ -52,6 +48,7 @@ def get_anagram(maxlen=6):
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 any(guess == item for item in gen_wordlist())
return [answer_checker, puzzle]
challenge_text = "Unscramble the following word: '{}'".format(anagram)
return [answer_checker, challenge_text]