-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maple: Tiffany and Rhyannon #39
base: master
Are you sure you want to change the base?
Changes from 16 commits
10c5347
04fc8b6
3261c94
942154a
a3e1e7e
418e234
9422350
5fcbf47
3150567
8473081
97a13b3
7d028f4
b37d81e
aa4597e
a7cf957
80e45d3
8b8300f
9e566b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,107 @@ | ||
import random | ||
|
||
LETTER_POOL = {'A': 9, 'B': 2, 'C': 2, 'D': 4, 'E': 12, 'F': 2, | ||
'G': 3, 'H': 2, 'I': 9, 'J': 1, 'K': 1, 'L': 4, 'M': 2, | ||
'N': 6, 'O': 8, 'P': 2, 'Q': 1, 'R': 6, 'S': 4, 'T': 6, | ||
'U': 4, 'V': 2, 'W': 2, 'X': 1, 'Y': 2, 'Z': 1} | ||
|
||
SCORE_CHART = { | ||
("A", "E", "I", "O", "U", "L", "N", "R", "S", "T"): 1, | ||
("D", "G") : 2, | ||
("B", "C", "M", "P") : 3, | ||
("F", "H", "V", "W", "Y") : 4, | ||
("K") : 5, | ||
("J", "X") : 8, | ||
("Q", "Z") : 10, | ||
} | ||
|
||
# Wave 1 | ||
def draw_letters(): | ||
pass | ||
""" | ||
Takes in no parameters, | ||
returns an array of random 10 strings from LETTER_POOL | ||
""" | ||
letters = [] | ||
letter_count = LETTER_POOL.copy() # could also be letter_bank, but not sure yet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 good job reducing side effects |
||
i = 0 | ||
while len(letters) < 10: | ||
random_letter = random.choice(list(LETTER_POOL)) | ||
if letter_count[random_letter] > 0: | ||
letter_count[random_letter] -= 1 | ||
letters.append(random_letter) | ||
if letter_count[random_letter] < 0: | ||
letters.remove(random_letter) | ||
i += 1 | ||
Comment on lines
+26
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't actually need let's get rid of line 26 and line 34! |
||
return letters | ||
|
||
# Wave 2 | ||
def uses_available_letters(word, letter_bank): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
pass | ||
""" | ||
Takes in two parameters: word, letter_bank, | ||
returns True if every letter in word is available, | ||
otherwise returns False. | ||
""" | ||
#this method copies the letter bank list | ||
letter_bank_duplicate = letter_bank[:] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 keeps side effects away |
||
|
||
for letter in word: | ||
if letter in letter_bank_duplicate: | ||
letter_bank_duplicate.remove(letter) | ||
else: | ||
return False | ||
|
||
return True | ||
|
||
# Wave 3 | ||
def score_word(word): | ||
pass | ||
""" | ||
Takes one parameter word, | ||
returns integer score of string word, | ||
returns extra points if word is seven letters or more | ||
""" | ||
total_score = 0 | ||
word_case_check = word.upper() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 good idea |
||
|
||
for key, value in SCORE_CHART.items(): | ||
for letter in word_case_check: | ||
if letter in key: | ||
total_score += value | ||
|
||
if len(word) >= 7: | ||
total_score += 8 | ||
|
||
return total_score | ||
|
||
|
||
# Wave 4 | ||
def get_score_dict(word_list): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 love a good helper function! |
||
""" | ||
Takes one parameter word_list, | ||
returns dictionary score_dict | ||
""" | ||
score_dict = {} | ||
for word in word_list: | ||
word_score = score_word(word) | ||
score_dict[word] = word_score | ||
return score_dict | ||
|
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
""" | ||
Takes one parameter word_list to find the highest scoring word, | ||
returns winning word tuple: (winning_word, top_score) | ||
""" | ||
score_dictionary = get_score_dict(word_list) | ||
top_word = max(score_dictionary, key=score_dictionary.get) | ||
all_scores = get_score_dict(word_list).values() | ||
top_word_score = max(all_scores) | ||
Comment on lines
+94
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. look at all these helper functions helping!!! |
||
|
||
|
||
for word, score in score_dictionary.items(): | ||
if top_word_score == score and len(top_word) != 10: | ||
if len(word) < len(top_word): | ||
top_word = word | ||
elif len(word) == 10: | ||
top_word = word | ||
|
||
return top_word, top_word_score | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice tuple return! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice idea!